Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a14bec79f8 | ||
|
|
c0de5ac3c8 | ||
|
|
8d7f810556 | ||
|
|
5c6526a6bd | ||
|
|
e9635ab75b | ||
|
|
e946243b6f | ||
|
|
ca6a4177b5 | ||
|
|
7817311f84 | ||
|
|
77659aae2a | ||
|
|
7cc619fbb0 | ||
|
|
887654049e | ||
|
|
d07b79f578 | ||
|
|
cefeb0bb51 | ||
|
|
1d675ec803 | ||
|
|
7596dfa65c | ||
|
|
508e997c64 | ||
|
|
89563ee05c | ||
|
|
8b72584d53 | ||
|
|
4ae62c114b | ||
|
|
823fb51d18 | ||
|
|
a840b815bd | ||
|
|
fbf973dc2a | ||
|
|
2698f6779f | ||
|
|
3b5de80c54 | ||
|
|
041f5a7c2b | ||
|
|
cb8f1130af | ||
|
|
f480df7504 | ||
|
|
51763d3bf9 | ||
|
|
d2b7e88060 | ||
|
|
b20df563ce | ||
|
|
5ada180d66 | ||
|
|
a4256de444 | ||
|
|
bce5553a4b | ||
|
|
670743cbcf | ||
|
|
ffed9ceb6d | ||
|
|
bbacb1b80a | ||
|
|
5ea38c9898 | ||
|
|
7177722a49 | ||
|
|
6083923604 | ||
|
|
7a3e1c23aa | ||
|
|
cab50dbf7a | ||
|
|
9964b308ce | ||
|
|
247a0e7227 | ||
|
|
f2dba8aff8 | ||
|
|
2ef18335e3 | ||
|
|
fa0818d088 | ||
|
|
2106626f22 | ||
|
|
fceab0becc | ||
|
|
bdf42368f7 | ||
|
|
36ab5ea5e2 | ||
|
|
c5c8469038 | ||
|
|
83d0121a28 | ||
|
|
aff74ebde3 | ||
|
|
be4619ba3d | ||
|
|
17bc2e9fa0 | ||
|
|
66e2382f26 | ||
|
|
6c299f81c6 | ||
|
|
a4fcba6ff6 | ||
|
|
1a3507366e | ||
|
|
65939dbe9d | ||
|
|
6914411232 | ||
|
|
c79f46aaa2 | ||
|
|
cea09b2c8b | ||
|
|
bc23ed9fc9 | ||
|
|
a4f286e89a | ||
|
|
f112f9eb5e | ||
|
|
010552ca44 | ||
|
|
9ae4b1066e | ||
|
|
1a57abde6e | ||
|
|
cf4b44940e | ||
|
|
81e19aace4 | ||
|
|
7341c32df5 | ||
|
|
bb1ed6cfcd | ||
|
|
55dcfb5e18 | ||
|
|
2fe9e5a125 | ||
|
|
e24385213d | ||
|
|
9cd81a23e7 | ||
|
|
64348860cb | ||
|
|
ecfceb5d0a | ||
|
|
cc840c37a2 | ||
|
|
527af12b0f | ||
|
|
9f2b98d5a8 | ||
|
|
4bd767fb62 | ||
|
|
cff29dfd2d | ||
|
|
d26b80905c | ||
|
|
4249679882 | ||
|
|
ff27055808 | ||
|
|
54f8acb27f | ||
|
|
017bebe8bb | ||
|
|
89f5670d8b | ||
|
|
b9e2293bee | ||
|
|
3b45418e47 | ||
|
|
6af7f6ef24 | ||
|
|
a0b85ee7f8 | ||
|
|
2e0c6c3368 | ||
|
|
1d36284369 | ||
|
|
94788692bb | ||
|
|
1f3f5d5980 | ||
|
|
90c2638221 | ||
|
|
98e02a0baa | ||
|
|
e96a204bb5 | ||
|
|
0dc4ec48da | ||
|
|
5d5c7e4c0a | ||
|
|
76c973f5c5 | ||
|
|
7608f2eed9 | ||
|
|
e585aa1899 | ||
|
|
82152352ea | ||
|
|
515e1d62af | ||
|
|
2d2e6bc1bf | ||
|
|
5bb89db279 | ||
|
|
36d8f6c922 | ||
|
|
8224beb85d | ||
|
|
ae6856f124 | ||
|
|
6953e22168 | ||
|
|
8c815ac601 | ||
|
|
9f1f5c9f5f | ||
|
|
b4acb2afa8 | ||
|
|
7287e746e3 | ||
|
|
ea4d5ab2e9 | ||
|
|
0dbc359f07 | ||
|
|
1e380ca1eb | ||
|
|
6bbe961a0f | ||
|
|
0fa8484208 | ||
|
|
30d5f5c118 | ||
|
|
3bcd1d17f6 | ||
|
|
befdfca6b2 | ||
|
|
c9b9f80987 | ||
|
|
0eae8fb0f7 | ||
|
|
903c3b120f | ||
|
|
6f8ffcbb99 | ||
|
|
2563a0ac3d | ||
|
|
d73ca5805a | ||
|
|
1e20b7725b | ||
|
|
97ec9e6626 | ||
|
|
120d5304f1 | ||
|
|
7c59232204 | ||
|
|
0df0bf094e | ||
|
|
5b16f0cf36 | ||
|
|
c1b7cd5885 | ||
|
|
ec7bae841e | ||
|
|
06fba7bdca | ||
|
|
b3f19247d5 | ||
|
|
5e562d7a59 | ||
|
|
b4479f3747 | ||
|
|
6dc79a0b7c | ||
|
|
e2aa034843 | ||
|
|
e99bc1163b | ||
|
|
a29dae61c5 | ||
|
|
777a04cc64 | ||
|
|
1f22566934 | ||
|
|
0011e5219a | ||
|
|
ce331bf6bd | ||
|
|
60d795f480 | ||
|
|
75a5f2fe48 | ||
|
|
dfda191c8b | ||
|
|
de09a2aa90 | ||
|
|
5e7cb9db9e | ||
|
|
61eca6100b | ||
|
|
4ef36d51ad | ||
|
|
880f560613 | ||
|
|
3f21278634 | ||
|
|
3c1e3573c9 | ||
|
|
6f8b14759d | ||
|
|
057e233cbf | ||
|
|
5dcc12e94d | ||
|
|
17886d60c0 | ||
|
|
b40fca79cb | ||
|
|
c04a228100 | ||
|
|
b3b1c7622c | ||
|
|
06f0813f2f | ||
|
|
5e086d6579 | ||
|
|
6fef3e0b2e | ||
|
|
7a7ee378c8 | ||
|
|
6fd2edcd76 | ||
|
|
73d17faaaa | ||
|
|
47bed3a2ba | ||
|
|
280a8f89bd | ||
|
|
8140d44d8a | ||
|
|
8b7717961f | ||
|
|
e462046c82 | ||
|
|
d261b2e464 | ||
|
|
73898ada43 | ||
|
|
bb0831a023 | ||
|
|
012719b0bf | ||
|
|
c8dc222435 | ||
|
|
7e0588b690 | ||
|
|
3dc6e8a128 | ||
|
|
eb5cebfb7c | ||
|
|
1f6417a9a8 | ||
|
|
306592f6b1 | ||
|
|
673945c8cb | ||
|
|
8a30f168c3 | ||
|
|
35708e8414 | ||
|
|
fb55db7797 | ||
|
|
2aca02ecd4 | ||
|
|
bba72e7191 | ||
|
|
a3ea860144 | ||
|
|
6e20baf317 | ||
|
|
f8742c8523 | ||
|
|
c6b84b8c7e | ||
|
|
815c1f5eeb | ||
|
|
e7d454787d | ||
|
|
d5c541db67 | ||
|
|
2cf12616ed | ||
|
|
2dee1c86e6 | ||
|
|
023b1e8610 | ||
|
|
e9f3efa0ec | ||
|
|
529119d9c3 | ||
|
|
3748d578e0 | ||
|
|
6af09d344d | ||
|
|
951ee2be17 | ||
|
|
7d902d1b6e | ||
|
|
cba373ab8a | ||
|
|
ab1c1bf311 | ||
|
|
749afff2e6 | ||
|
|
c2fc0328b8 | ||
|
|
b41fc87737 | ||
|
|
65c1cbf973 | ||
|
|
1a362a7f66 | ||
|
|
a86c26d0d7 | ||
|
|
37df8b1f0e | ||
|
|
0d963bbb46 | ||
|
|
1aa791eeb2 | ||
|
|
a051a84187 | ||
|
|
43476b9c5d | ||
|
|
d2bdac70d5 | ||
|
|
b5036c6fd7 | ||
|
|
0db7738bd1 | ||
|
|
31cec49247 | ||
|
|
d259174901 | ||
|
|
98932406b9 | ||
|
|
5994784bf5 | ||
|
|
488ab9e543 | ||
|
|
8af1b0556e | ||
|
|
ab27e68c3b | ||
|
|
5fe3528672 | ||
|
|
c065ecc45f | ||
|
|
9356c52f28 | ||
|
|
d015a96773 | ||
|
|
d3b7e50d06 |
+3
-1
@@ -25,4 +25,6 @@
|
||||
8.0.4
|
||||
8.0.5
|
||||
8.1.2
|
||||
8.2.2
|
||||
8.2.2
|
||||
8.3.2
|
||||
8.3.3
|
||||
@@ -1,10 +0,0 @@
|
||||
---
|
||||
title: SS58 registry is outdated
|
||||
labels: ['ci', '@networks']
|
||||
---
|
||||
|
||||
cc @polkadot-js/notifications
|
||||
|
||||
Discrepancies detected between https://github.com/paritytech/substrate/blob/master/ss58-registry.json and https://github.com/polkadot-js/common/blob/master/packages/networks/src/substrate.ts
|
||||
|
||||
Check the nightly cron output (or via `yarn networks:crosscheck` locally) and run `yarn networks:sync` to update. The output as found from the test includes:
|
||||
@@ -0,0 +1,16 @@
|
||||
name: bot
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
|
||||
jobs:
|
||||
approve:
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: jacogr/action-approve@master
|
||||
with:
|
||||
authors: jacogr
|
||||
labels: -auto
|
||||
token: ${{ secrets.GH_PAT_BOT }}
|
||||
@@ -0,0 +1,16 @@
|
||||
name: bot
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
|
||||
jobs:
|
||||
merge:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: jacogr/action-merge@master
|
||||
with:
|
||||
checks: build,lint,test
|
||||
labels: -auto
|
||||
strategy: squash
|
||||
token: ${{ secrets.GH_PAT_BOT }}
|
||||
@@ -7,6 +7,8 @@ on:
|
||||
jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v2
|
||||
with:
|
||||
|
||||
@@ -8,11 +8,12 @@ jobs:
|
||||
step: ['lint', 'test', 'build']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: ${{ matrix.step }}
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
@@ -12,17 +12,18 @@ jobs:
|
||||
step: ['build:release']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
- name: ${{ matrix.step }}
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
@@ -9,6 +9,8 @@ jobs:
|
||||
check:
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && (!github.event.pull_request || github.event.pull_request.head.repo.full_name == github.repository)"
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: returntocorp/semgrep-action@v1
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
name: SS58
|
||||
on:
|
||||
schedule:
|
||||
- cron: '15 4/6 * * *'
|
||||
|
||||
jobs:
|
||||
ss58:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: check
|
||||
env:
|
||||
CI_LOG: 123
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn build
|
||||
yarn networks:crosscheck
|
||||
|
||||
- name: issue
|
||||
if: ${{ failure() }}
|
||||
uses: JasonEtco/create-an-issue@v2
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GH_PAT_BOT }}
|
||||
with:
|
||||
filename: .github/ss58-check.md
|
||||
update_existing: true
|
||||
@@ -6,6 +6,8 @@ on:
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
YARN_ENABLE_SCRIPTS: false
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
--test-*
|
||||
_book/
|
||||
build/
|
||||
build-cjs/
|
||||
build-esm/
|
||||
build-docs/
|
||||
coverage/
|
||||
docs/.vuepress/dist/
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
Jaco <jacogr@gmail.com>
|
||||
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> <action@github.com>
|
||||
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Github Actions <action@github.com>
|
||||
|
||||
Vendored
-768
File diff suppressed because one or more lines are too long
+785
File diff suppressed because one or more lines are too long
+1
-1
@@ -10,4 +10,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.1.1.cjs
|
||||
yarnPath: .yarn/releases/yarn-3.2.0.cjs
|
||||
|
||||
+130
@@ -1,5 +1,135 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 9.4.1 Jun 4, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `nextTick` to `@polkadot/util` to defer execution to the queue
|
||||
- Upgrade dependencies to latest stable versions
|
||||
|
||||
|
||||
## 9.3.1 May 29, 2022
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add Ledger support for Parallel (Thanks to https://github.com/carlosala)
|
||||
- Add Ledger support for Astar & Polkadex (Thanks to https://github.com/carlosala)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust `u8aToU8a` checks with better `isU8a` shortcut
|
||||
- Adjust compact conversion with unrolled loops
|
||||
- Adjust `string{Camel, Pascal}Case` with loop (no map)
|
||||
- Add `compactFromU8aLim` variant with Uint8Array-only inputs
|
||||
- Add `u8aConcatStrict` variant with Uint8Array-only inputs
|
||||
- Internal code maintainability enhancements
|
||||
- Upgrade dependencies to latest stable versions
|
||||
|
||||
|
||||
## 9.2.1 May 13, 2022
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add Ledger support for Acala (Thanks to https://github.com/ntduan)
|
||||
|
||||
Changes:
|
||||
|
||||
- Optimize `u8aToHex` with direct (non-hex) conversion
|
||||
- Change all occurences of `.substr(...)` to `.substring(...)`
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
- Mark deprecated function signatures (no removals)
|
||||
- Re-enable auto init of `cryptoWaitReady()`
|
||||
- Upgrade to `@polkadot/wasm-crypto` 6.1.1
|
||||
|
||||
|
||||
## 9.1.1 Apr 30, 2022
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add Ledger support for Statemint (Thanks to https://github.com/carlosala)
|
||||
- Add Ledger support for xxnetwork (Thanks to https://github.com/xx-labs)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust/dedupe output from `detectPackage`
|
||||
- Adjust `isHex` performance test
|
||||
- Add field-level comments to some `*Options` structures
|
||||
- Add new Rococo genesisHash (reset)
|
||||
|
||||
|
||||
## 9.0.1 Apr 9, 2022
|
||||
|
||||
- **Breaking change** In this major version the commonjs outputs are moved to a sub-folder. Since the export map and main field in package.json does reflect this change, there should be no usage changes. However the packages here will all need to be on the same version for internal linkage.
|
||||
|
||||
Changes:
|
||||
|
||||
- Be explicit in `@polkadot/util-crypto` re-exports from `@polkadot/networks`
|
||||
- Output commonjs files under the `cjs/**` root
|
||||
- Upgrade to `@polkadot/wasm-crypto` 6.0.1
|
||||
|
||||
|
||||
## 8.7.1 Mar 27, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix race-condition with wasm overrides, make `cryptoWaitReady` lazy
|
||||
- Additional tests for `BN` & `BigInt` negative conversions
|
||||
- Upgrade to `@polkadot/wasm-crypto` 5.1.1
|
||||
|
||||
|
||||
## 8.6.1 Mar 19, 2022
|
||||
|
||||
**Important** This contains an upgraded version of `@polkadot/wasm-crypto`. For users of asm.js, e.g. React Native, there are some additional upgrade instructions in the release notes for this version https://github.com/polkadot-js/wasm/releases/tag/v5.0.1
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add aditional Dock mainnet genesis (Thanks to https://github.com/lovesh)
|
||||
- Add Westend genesis (Thanks to https://github.com/Nick-1979)
|
||||
- Update README with ss58 links (Thanks to https://github.com/Nick-197)
|
||||
|
||||
Changes:
|
||||
|
||||
- Ensure invalid secp256k1 publicKeys are not returned
|
||||
- Cater for Expo v41+ in RN random value generation
|
||||
- Fixed for RN environment imports
|
||||
- Internal split of details in `@polkadot/networks`
|
||||
- Additional workaround for Vite bundling
|
||||
- Upgrade to `@polkadot/wasm-crypto` 5.0.1
|
||||
|
||||
|
||||
## 8.5.1 Mar 12, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust for bundlers where `import.meta.url` is undefined
|
||||
- Upgrade dependencies to latest stable versions
|
||||
|
||||
|
||||
## 8.4.1 Feb 14, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Use upstream `@substrate/ss58-registry` (instead of duplicating here)
|
||||
- Swap `micro-base` to `@scure/base` (same package, audited)
|
||||
- Bump `bn.js` library to latest 5.2.0 (has impact on e.g. API)
|
||||
- Upgrade dependencies to latest stable versions
|
||||
|
||||
|
||||
## 8.3.3 Jan 23, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
|
||||
|
||||
## 8.3.2 Jan 15, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Correct network sorting (primary by prefix, secondary by name)
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
|
||||
|
||||
## 8.3.1 Jan 9, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
+50
-45
@@ -1,45 +1,50 @@
|
||||
1228 Jaco
|
||||
9 Antoine Estienne
|
||||
6 Amaury Martiny
|
||||
5 kwingram25
|
||||
4 Adam Dossa
|
||||
3 Jakub Pánik
|
||||
3 Luke Schoen
|
||||
2 AndreasGassmann
|
||||
2 Gav Wood
|
||||
2 Hyungsuk Kang
|
||||
2 Jared Norris
|
||||
2 Nantian
|
||||
2 pan
|
||||
2 Stefanie Doll
|
||||
1 Agustinus Theodorus
|
||||
1 Alexander Krupenkin
|
||||
1 alexdniep
|
||||
1 amphineko
|
||||
1 Axel Chalon
|
||||
1 Brad Larson
|
||||
1 Eliott Teissonniere
|
||||
1 h4x3rotab
|
||||
1 Harry Liu
|
||||
1 Hussein Ait-Lahcen
|
||||
1 Igor
|
||||
1 Jake Naviasky
|
||||
1 JesseAbram
|
||||
1 joe petrowski
|
||||
1 Lezek123
|
||||
1 Lovesh Harchandani
|
||||
1 Mario Neises
|
||||
1 Miguel Hervas
|
||||
1 nahuseyoum
|
||||
1 qwer951123
|
||||
1 Raoul Millais
|
||||
1 Raymond Zhong
|
||||
1 Reto Trinkler
|
||||
1 Rocco Musolino
|
||||
1 Song Zhou
|
||||
1 Thibaut Sardan
|
||||
1 Tomokazu Kozuma
|
||||
1 Tore19
|
||||
1 Wei Tang
|
||||
1 WoeOm
|
||||
1 Yuri
|
||||
1338 Jaco 9.4.1 (#1514)
|
||||
9 Antoine Estienne Add eth uri keyring test (#1291)
|
||||
6 Amaury Martiny Add tests from Rust (#283)
|
||||
5 kwingram25 Add BN consts and timeToString (#610)
|
||||
4 Adam Dossa Update Polymesh Genesis Hash (#1193)
|
||||
4 Jakub Pánik Add basilisk 🐍 (#1396)
|
||||
3 Carlo Sala some changes to KnownLedger (#1497)
|
||||
3 Luke Schoen docs: Fix example in readme since we use default imports (#243)
|
||||
2 AndreasGassmann feat(dependencies): remove moment.js (#530)
|
||||
2 Gav Wood Fix stake:unstake (#182)
|
||||
2 Hyungsuk Kang Add cross client Encryption/Decryption (#496)
|
||||
2 Jared Norris Add Sora network (#1306)
|
||||
2 Kami Adding Westend genesis. (#1429)
|
||||
2 Lovesh Harchandani Update genesis hash of Dock mainnet (#1436)
|
||||
2 Nantian fix bigint type (#1079)
|
||||
2 pan add bifrost (#1296)
|
||||
2 Stefanie Doll Add missing dependencies to util-crypto (#424)
|
||||
1 Agustinus Theodorus docs: fix typo in naclSeal docs. (#1005)
|
||||
1 Alexander Krupenkin Added ECDSA keypair support (#589)
|
||||
1 alexdniep added equilibrium slip44; added equilibrium genesis hash (#984)
|
||||
1 amphineko chore: fix typo in versionDetect messages (#941)
|
||||
1 Axel Chalon Simplify @polkadot/keyring KeyringPair (#419)
|
||||
1 Brad Larson [FIX] Adjust error message (#646)
|
||||
1 Eliott Teissonniere add nodle ledger specs (#1089)
|
||||
1 h4x3rotab Throws an error when signing with a locked keypair (#578)
|
||||
1 Harry Liu Update README.md (#446)
|
||||
1 Hoon Kim replace plasm genesis with astar (#1397)
|
||||
1 Hussein Ait-Lahcen Add Picasso Genesis Hash (#1261)
|
||||
1 Igor Support genshiro network (#1148)
|
||||
1 Jake Naviasky Add evmToAddress and addressToEvm crypto utils. (#705)
|
||||
1 JesseAbram added check if valid address to docs (#440)
|
||||
1 joe petrowski Add example for multisig address creation (#590)
|
||||
1 Lezek123 logger - wildcard include/exclude with DEBUG env (#932)
|
||||
1 Mario Neises remove redudant export (#257)
|
||||
1 Miguel Hervas Add CFG Ledger Support (#1057)
|
||||
1 nahuseyoum Reserving 65 for Aventus based on the new extended range (#871)
|
||||
1 Nantian add acala ledger config (#1485)
|
||||
1 qwer951123 Add acala genesis (#1161)
|
||||
1 Raoul Millais Fix yarn add instructions in x-global README (#873)
|
||||
1 Raymond Zhong Add Edgeware ledger app (#1006)
|
||||
1 Reto Trinkler Adding 4 as address type of ss58 for Katal Chain (#639)
|
||||
1 Rocco Musolino remove doc broken link (#697)
|
||||
1 Song Zhou Add in ability to encrypt/decrypt msg with keyring (#1070)
|
||||
1 Thibaut Sardan add hasLedgerSupport prop to networks (#835)
|
||||
1 Tomokazu Kozuma fix comment (#1119)
|
||||
1 Tore19 Add stafi genesis hash (#1096)
|
||||
1 Wei Tang ss58: add Kulupu prefix to the list (#595)
|
||||
1 WoeOm Handing high precision scenes (#450)
|
||||
1 xx network Add xxnetwork genesis hash and ledger app (#1463)
|
||||
1 Yuri Extra check for process for browser bundles (#923)
|
||||
+7
-8
@@ -2,15 +2,15 @@
|
||||
"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",
|
||||
"license": "Apache-2.0",
|
||||
"packageManager": "yarn@3.2.0",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
@@ -21,18 +21,17 @@
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"networks:crosscheck": "polkadot-dev-run-test packages/networks/src/crosscheck",
|
||||
"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.16.7",
|
||||
"@polkadot/dev": "^0.65.23",
|
||||
"@types/jest": "^27.4.0"
|
||||
"@babel/core": "^7.18.2",
|
||||
"@polkadot/dev": "^0.66.34",
|
||||
"@types/jest": "^28.1.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"typescript": "^4.5.3"
|
||||
"typescript": "^4.7.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.7",
|
||||
"@ledgerhq/hw-transport": "^6.20.0",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.20.0",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.20.0",
|
||||
"@polkadot/util": "8.3.1"
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.27.1",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.27.1",
|
||||
"@polkadot/util": "9.4.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.20.0"
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.27.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: 'auto', type: 'auto', version: '8.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: 'auto', type: 'auto', version: '9.4.1' };
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../util" }
|
||||
{ "path": "../util/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -19,13 +19,13 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.7",
|
||||
"@ledgerhq/hw-transport": "^6.20.0",
|
||||
"@polkadot/hw-ledger-transports": "8.3.1",
|
||||
"@polkadot/util": "8.3.1",
|
||||
"@zondax/ledger-substrate": "^0.24.0"
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@polkadot/hw-ledger-transports": "9.4.1",
|
||||
"@polkadot/util": "9.4.1",
|
||||
"@zondax/ledger-substrate": "^0.30.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,27 @@
|
||||
import type Transport from '@ledgerhq/hw-transport';
|
||||
import type { SubstrateApp } from '@zondax/ledger-substrate';
|
||||
|
||||
import { newBifrostApp, newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newSoraApp, newStatemineApp } from '@zondax/ledger-substrate';
|
||||
import { newAcalaApp, newAstarApp, newBifrostApp, newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKaruraApp, newKusamaApp, newNodleApp, newParallelApp, newPolkadexApp, newPolkadotApp, newPolymeshApp, newSoraApp, newStatemineApp, newStatemintApp, newXXNetworkApp } from '@zondax/ledger-substrate';
|
||||
|
||||
// These match up with the keys of the knownLedger object in the @polkadot/networks/defaults.ts
|
||||
// These match up with the keys of the knownLedger object in the @polkadot/networks/defaults/ledger.ts
|
||||
export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp> = {
|
||||
acala: newAcalaApp,
|
||||
astar: newAstarApp,
|
||||
bifrost: newBifrostApp,
|
||||
centrifuge: newCentrifugeApp,
|
||||
'dock-mainnet': newDockApp,
|
||||
edgeware: newEdgewareApp,
|
||||
equilibrium: newEquilibriumApp,
|
||||
genshiro: newGenshiroApp,
|
||||
karura: newKaruraApp,
|
||||
kusama: newKusamaApp,
|
||||
'nodle-chain': newNodleApp,
|
||||
'nodle-para': newNodleApp,
|
||||
parallel: newParallelApp,
|
||||
polkadex: newPolkadexApp,
|
||||
polkadot: newPolkadotApp,
|
||||
polymesh: newPolymeshApp,
|
||||
sora: newSoraApp,
|
||||
statemine: newStatemineApp
|
||||
statemine: newStatemineApp,
|
||||
statemint: newStatemintApp,
|
||||
xxnetwork: newXXNetworkApp
|
||||
};
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '8.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '9.4.1' };
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface AccountOptions {
|
||||
|
||||
export interface LedgerAddress {
|
||||
address: string;
|
||||
publicKey: string;
|
||||
publicKey: HexString;
|
||||
}
|
||||
|
||||
export interface LedgerSignature {
|
||||
@@ -23,5 +23,8 @@ export interface LedgerSignature {
|
||||
export interface LedgerVersion {
|
||||
isLocked: boolean;
|
||||
isTestMode: boolean;
|
||||
/**
|
||||
* @description Tuple with major, minor, patch
|
||||
*/
|
||||
version: [number, number, number];
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../util" },
|
||||
{ "path": "../util-crypto" }
|
||||
{ "path": "../hw-ledger-transports/tsconfig.build.json" },
|
||||
{ "path": "../util/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.7",
|
||||
"@polkadot/util": "8.3.1",
|
||||
"@polkadot/util-crypto": "8.3.1"
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/util": "9.4.1",
|
||||
"@polkadot/util-crypto": "9.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "8.3.1",
|
||||
"@polkadot/util-crypto": "8.3.1"
|
||||
"@polkadot/util": "9.4.1",
|
||||
"@polkadot/util-crypto": "9.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '8.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '9.4.1' };
|
||||
|
||||
@@ -65,7 +65,9 @@ describe('testingPairs', (): void => {
|
||||
delete ring.nobody;
|
||||
|
||||
Object.keys(ring).forEach((testKeyring, i) => {
|
||||
if (i < 6) { expect(u8aToHex(ring[testKeyring].publicKey)).toEqual(u8aToHex(keyring.createFromUri(privKeys[i]).publicKey)); }
|
||||
if (i < 6) {
|
||||
expect(u8aToHex(ring[testKeyring].publicKey)).toEqual(u8aToHex(keyring.createFromUri(privKeys[i]).publicKey));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,13 @@ import type { HexString } from '@polkadot/util/types';
|
||||
import type { EncryptedJson, Keypair, KeypairType, Prefix } from '@polkadot/util-crypto/types';
|
||||
|
||||
export interface KeyringOptions {
|
||||
/**
|
||||
* @description The ss58Format to use for address encoding (defaults to 42)
|
||||
*/
|
||||
ss58Format?: Prefix;
|
||||
/**
|
||||
* @description The type of keyring to create (defaults to ed25519)
|
||||
*/
|
||||
type?: KeypairType;
|
||||
}
|
||||
|
||||
@@ -17,6 +23,9 @@ export interface KeyringPair$Json extends EncryptedJson {
|
||||
}
|
||||
|
||||
export interface SignOptions {
|
||||
/**
|
||||
* @description Create a MultiSignature-compatible output with an indicator type
|
||||
**/
|
||||
withType?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../hw-ledger-transports" },
|
||||
{ "path": "../util" }
|
||||
{ "path": "../util/tsconfig.build.json" },
|
||||
{ "path": "../util-crypto/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
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
|
||||
This list is periodically checked against the master list available at https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json
|
||||
|
||||
@@ -17,14 +17,15 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.7",
|
||||
"@polkadot/util": "8.3.1"
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/util": "9.4.1",
|
||||
"@substrate/ss58-registry": "^1.22.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/hw-ledger": "8.3.1",
|
||||
"@polkadot/x-fetch": "8.3.1"
|
||||
"@polkadot/hw-ledger": "9.4.1",
|
||||
"@polkadot/x-fetch": "9.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import fs from 'fs';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
import { substrateRegistry } from '../build/defaults.js';
|
||||
|
||||
const substrateRegistryRepo = substrateRegistry
|
||||
.replace('raw.githubusercontent.com', 'github.com')
|
||||
.split('main')[0];
|
||||
|
||||
function outputField (k, v) {
|
||||
if (typeof v === 'string') {
|
||||
return `'${v}'`;
|
||||
} else if (Array.isArray(v)) {
|
||||
// new format is [] to indicate optionality
|
||||
return (['decimals', 'symbols'].includes(k) && !v.length)
|
||||
? null
|
||||
: `[${v.map((v) => outputField(k, v)).join(', ')}]`;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
async function getSubstrateRegistry () {
|
||||
const original = await fetch(substrateRegistry);
|
||||
const json = await original.json();
|
||||
|
||||
return json.registry
|
||||
.map((e) =>
|
||||
` {\n${Object
|
||||
.entries(e)
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([k, v]) => ` ${k}: ${outputField(k, v)}`)
|
||||
.join(',\n')}\n }`
|
||||
)
|
||||
.join(',\n');
|
||||
}
|
||||
|
||||
getSubstrateRegistry()
|
||||
.then((entries) => {
|
||||
fs.writeFileSync('packages/networks/src/substrate.ts', `// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//
|
||||
// Auto-generated by yarn networks:sync (via scripts/fromSubstrate.mjs)
|
||||
//
|
||||
// This file should never be edited manually. Rather the process is as follow -
|
||||
//
|
||||
// - make a PR to the upstream registry found at ${substrateRegistryRepo}
|
||||
// - ensure the PR gets merged
|
||||
// - yarn networks:sync in this repo to sync
|
||||
//
|
||||
// Any manual changes to this file will make CI cron checks fail and will be
|
||||
// lost when the registry is updated alongside the above sync.
|
||||
//
|
||||
|
||||
import type { KnownSubstrate } from './types';
|
||||
|
||||
export const knownSubstrate: KnownSubstrate[] = [\n${entries}\n];
|
||||
`);
|
||||
|
||||
console.log('Completed.');
|
||||
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error.message);
|
||||
|
||||
process.exit(-1);
|
||||
});
|
||||
@@ -8,9 +8,9 @@ import fs from 'fs';
|
||||
import { objectKeys, stringify } from '@polkadot/util';
|
||||
import { fetch } from '@polkadot/x-fetch';
|
||||
|
||||
import { substrateRegistry } from './defaults';
|
||||
import { allNetworks } from './';
|
||||
|
||||
const REGISTRY = 'https://raw.githubusercontent.com/paritytech/ss58-registry/main/ss58-registry.json';
|
||||
const OUTPUT = './.github/ss58-check.md';
|
||||
|
||||
function assertAndLog (check: boolean, error: string): void {
|
||||
@@ -28,7 +28,7 @@ describe('check latest Substrate ss58 registry', (): void => {
|
||||
let original: Ss58Registry;
|
||||
|
||||
beforeAll(async (): Promise<void> => {
|
||||
original = (await (await fetch(substrateRegistry)).json()) as Ss58Registry;
|
||||
original = (await (await fetch(REGISTRY)).json()) as Ss58Registry;
|
||||
});
|
||||
|
||||
it('has the same number as the original', (): void => {
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KnownIcon, KnownLedger, KnownTestnet } from './types';
|
||||
|
||||
export { knownGenesis } from './genesis';
|
||||
|
||||
export const substrateRegistry = 'https://raw.githubusercontent.com/paritytech/ss58-registry/main/ss58-registry.json';
|
||||
|
||||
// these are icon overrides
|
||||
export const knownIcon: KnownIcon = {
|
||||
centrifuge: 'polkadot',
|
||||
kusama: 'polkadot',
|
||||
polkadot: 'polkadot',
|
||||
sora: 'polkadot',
|
||||
statemine: 'polkadot',
|
||||
statemint: 'polkadot',
|
||||
westmint: 'polkadot'
|
||||
};
|
||||
|
||||
// These match up with the keys of the ledgerApps object in the @polkadot/hw-ledger/defaults.ts
|
||||
// and maps to the known slip44 (minus the `0x8` hard derivation flag)
|
||||
// NOTE: Any network here needs to have a genesisHash attached in the config above
|
||||
export const knownLedger: KnownLedger = {
|
||||
bifrost: 0x00000314,
|
||||
centrifuge: 0x000002eb,
|
||||
'dock-mainnet': 0x00000252,
|
||||
edgeware: 0x0000020b,
|
||||
equilibrium: 0x05f5e0fd,
|
||||
genshiro: 0x05f5e0fc,
|
||||
kusama: 0x000001b2,
|
||||
'nodle-chain': 0x000003eb,
|
||||
polkadot: 0x00000162,
|
||||
polymesh: 0x00000253,
|
||||
sora: 0x00000269,
|
||||
statemine: 0x000001b2 // common-good on Kusama, shares derivation
|
||||
};
|
||||
|
||||
// testnets should not allow selection
|
||||
export const knownTestnet: KnownTestnet = {
|
||||
'': true, // this is the default non-network entry
|
||||
'cess-testnet': true,
|
||||
'dock-testnet': true,
|
||||
jupiter: true,
|
||||
'mathchain-testnet': true,
|
||||
subspace_testnet: true,
|
||||
'zero-alphaville': true
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KnownGenesis } from './types';
|
||||
import type { KnownGenesis } from '../types';
|
||||
|
||||
// NOTE: In the case where the network was hard-spooned and multiple genesisHashes
|
||||
// are provided, it needs to be in reverse order, i.e. most-recent first, oldest
|
||||
@@ -11,6 +11,12 @@ export const knownGenesis: KnownGenesis = {
|
||||
acala: [
|
||||
'0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c'
|
||||
],
|
||||
astar: [
|
||||
'0x9eb76c5184c4ab8679d2d5d819fdf90b9c001403e9e17da2e14b6d8aec4029c6'
|
||||
],
|
||||
basilisk: [
|
||||
'0xa85cfb9b9fd4d622a5b28289a02347af987d8f73fa3108450e2b4a11c1ce5755'
|
||||
],
|
||||
bifrost: [
|
||||
'0x9f28c6a68e0fc9646eff64935684f6eeeece527e37bbe1f213d22caa1d9d6bed'
|
||||
],
|
||||
@@ -18,6 +24,7 @@ export const knownGenesis: KnownGenesis = {
|
||||
'0x67dddf2673b69e5f875f6f25277495834398eafd67f492e09f3f3345e003d1b5'
|
||||
],
|
||||
'dock-mainnet': [
|
||||
'0x6bfe24dca2a3be10f22212678ac13a6446ec764103c0f3471c71609eac384aae',
|
||||
'0xf73467c6544aa68df2ee546b135f955c46b90fa627e9b5d7935f41061bb8a5a9'
|
||||
],
|
||||
edgeware: [
|
||||
@@ -46,14 +53,17 @@ export const knownGenesis: KnownGenesis = {
|
||||
'0xe3777fa922cafbff200cadeaea1a76bd7898ad5b89f7848999058b50e715f636', // Kusama CC2
|
||||
'0x3fd7b9eb6a00376e5be61f01abb429ffb0b104be05eaff4d458da48fcd425baf' // Kusama CC1
|
||||
],
|
||||
'nodle-chain': [
|
||||
'0xa3d114c2b8d0627c1aa9b134eafcf7d05ca561fdc19fb388bb9457f81809fb23'
|
||||
'nodle-para': [
|
||||
'0x97da7ede98d7bad4e36b4d734b6055425a3be036da2a332ea5a7037656427a21'
|
||||
],
|
||||
parallel: [
|
||||
'0xe61a41c53f5dcd0beb09df93b34402aada44cb05117b71059cce40a2723a4e97'
|
||||
],
|
||||
picasso: [
|
||||
'0xe8e7f0f4c4f5a00720b4821dbfddefea7490bcf0b19009961cc46957984e2c1c'
|
||||
],
|
||||
plasm: [
|
||||
'0x3e86364d4b4894021cb2a0390bcf2feb5517d5292f2de2bb9404227e908b0b8b'
|
||||
polkadex: [
|
||||
'0x3920bcb4960a1eef5580cd5367ff3f430eef052774f78468852f7b9cb39f8a3c'
|
||||
],
|
||||
polkadot: [
|
||||
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'
|
||||
@@ -62,6 +72,8 @@ export const knownGenesis: KnownGenesis = {
|
||||
'0x6fbd74e5e1d0a61d52ccfe9d4adaed16dd3a7caa37c6bc4d0c2fa12e8b2f4063'
|
||||
],
|
||||
rococo: [
|
||||
'0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e',
|
||||
'0xaaf2cd1b74b5f726895921259421b534124726263982522174147046b8827897',
|
||||
'0x037f5f3c8e67b314062025fc886fcd6238ea25a4a9b45dce8d246815c9ebe770',
|
||||
'0xc196f81260cf1686172b47a79cf002120735d7cb0eb1474e8adce56618456fff',
|
||||
'0xf6e9983c37baf68846fedafe21e56718790e39fb1c582abc408b81bc7b208f9a',
|
||||
@@ -82,7 +94,16 @@ export const knownGenesis: KnownGenesis = {
|
||||
statemine: [
|
||||
'0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a'
|
||||
],
|
||||
statemint: [
|
||||
'0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f'
|
||||
],
|
||||
subsocial: [
|
||||
'0x0bd72c1c305172e1275278aaeb3f161e02eccb7a819e63f62d47bd53a28189f8'
|
||||
],
|
||||
westend: [
|
||||
'0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e'
|
||||
],
|
||||
xxnetwork: [
|
||||
'0x50dd5d206917bf10502c68fb4d18a59fc8aa31586f4e8856b493e43544aa82aa'
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KnownIcon } from '../types';
|
||||
|
||||
// these are icon overrides
|
||||
export const knownIcon: KnownIcon = {
|
||||
centrifuge: 'polkadot',
|
||||
kusama: 'polkadot',
|
||||
polkadot: 'polkadot',
|
||||
sora: 'polkadot',
|
||||
statemine: 'polkadot',
|
||||
statemint: 'polkadot',
|
||||
westmint: 'polkadot'
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { knownGenesis } from './genesis';
|
||||
export { knownIcon } from './icons';
|
||||
export { knownLedger } from './ledger';
|
||||
export { knownTestnet } from './testnets';
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KnownLedger } from '../types';
|
||||
|
||||
// These match up with the keys of the ledgerApps object in the @polkadot/hw-ledger/defaults.ts
|
||||
// and maps to the known slip44 (minus the `0x8` hard derivation flag)
|
||||
//
|
||||
// NOTE: Any network here needs to have a genesisHash attached in the ./genesis.ts config
|
||||
export const knownLedger: KnownLedger = {
|
||||
acala: 0x00000313,
|
||||
astar: 0x0000032a,
|
||||
bifrost: 0x00000314,
|
||||
centrifuge: 0x000002eb,
|
||||
'dock-mainnet': 0x00000252,
|
||||
edgeware: 0x0000020b,
|
||||
equilibrium: 0x05f5e0fd,
|
||||
genshiro: 0x05f5e0fc,
|
||||
karura: 0x000002ae,
|
||||
kusama: 0x000001b2,
|
||||
'nodle-para': 0x000003eb,
|
||||
parallel: 0x00000162,
|
||||
polkadex: 0x0000031f,
|
||||
polkadot: 0x00000162,
|
||||
polymesh: 0x00000253,
|
||||
sora: 0x00000269,
|
||||
statemine: 0x000001b2, // common-good on Kusama, shares derivation
|
||||
statemint: 0x00000162, // common-good on Polkadot, shares derivation
|
||||
xxnetwork: 0x000007a3
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KnownTestnet } from '../types';
|
||||
|
||||
// testnets should not allow selection
|
||||
export const knownTestnet: KnownTestnet = {
|
||||
'': true, // this is the default non-network entry
|
||||
'cess-testnet': true,
|
||||
'dock-testnet': true,
|
||||
jupiter: true,
|
||||
'mathchain-testnet': true,
|
||||
subspace_testnet: true,
|
||||
'zero-alphaville': true
|
||||
};
|
||||
@@ -6,9 +6,14 @@ import type { SubstrateNetwork } from './types';
|
||||
import { knownGenesis, knownIcon, knownLedger, knownTestnet } from './defaults';
|
||||
import { allNetworks, availableNetworks, selectableNetworks } from '.';
|
||||
|
||||
describe('selectableNetworks', (): void => {
|
||||
describe('availableNetworks', (): void => {
|
||||
it('has the correct starting order', (): void => {
|
||||
expect(selectableNetworks.slice(0, 3).map(({ prefix }) => prefix)).toEqual([0, 2, 42]);
|
||||
expect(availableNetworks.slice(0, 3).map(({ prefix }) => prefix)).toEqual([0, 2, 42]);
|
||||
});
|
||||
|
||||
it('has a sorted list (first external, last external)', (): void => {
|
||||
expect(availableNetworks[3].displayName).toEqual('Acala');
|
||||
expect(availableNetworks[availableNetworks.length - 1].displayName).toEqual('ZERO');
|
||||
});
|
||||
|
||||
it('has no ignored networks', (): void => {
|
||||
@@ -63,6 +68,28 @@ describe('selectableNetworks', (): void => {
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('has all the correct fields', (): void => {
|
||||
expect(availableNetworks[0]).toEqual({
|
||||
decimals: [10],
|
||||
displayName: 'Polkadot Relay Chain',
|
||||
genesisHash: [
|
||||
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'
|
||||
],
|
||||
hasLedgerSupport: true,
|
||||
icon: 'polkadot',
|
||||
isIgnored: false,
|
||||
isTestnet: false,
|
||||
network: 'polkadot',
|
||||
prefix: 0,
|
||||
slip44: 354,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['DOT'],
|
||||
website: 'https://polkadot.network'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('allNetworks', (): void => {
|
||||
it('has no ss58 duplicates', (): void => {
|
||||
const dupes: SubstrateNetwork[] = [];
|
||||
const uniques: SubstrateNetwork[] = [];
|
||||
@@ -78,3 +105,14 @@ describe('selectableNetworks', (): void => {
|
||||
expect(dupes).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('selectableNetworks', (): void => {
|
||||
it('has the correct starting order', (): void => {
|
||||
expect(selectableNetworks.slice(0, 3).map(({ prefix }) => prefix)).toEqual([0, 2, 42]);
|
||||
});
|
||||
|
||||
it('has a sorted list (first external, last external)', (): void => {
|
||||
expect(selectableNetworks[3].displayName).toEqual('Acala');
|
||||
expect(selectableNetworks[selectableNetworks.length - 1].displayName).toEqual('xx network');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// TODO: This was removed, really cannot recall the reason...
|
||||
// ... put it back, but keep it removed
|
||||
// import './detectPackage';
|
||||
|
||||
export * from './interfaces';
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
import type { KnownSubstrate, Network, SubstrateNetwork } from './types';
|
||||
|
||||
import knownSubstrate from '@substrate/ss58-registry';
|
||||
|
||||
import { knownGenesis, knownIcon, knownLedger, knownTestnet } from './defaults';
|
||||
import { knownSubstrate } from './substrate';
|
||||
|
||||
// These are known prefixes that are not sorted
|
||||
const UNSORTED = [0, 2, 42];
|
||||
@@ -25,7 +26,14 @@ function toExpanded (o: KnownSubstrate): SubstrateNetwork {
|
||||
|
||||
// filtering
|
||||
n.isTestnet = !!knownTestnet[network] || TESTNETS.includes(nameParts[nameParts.length - 1]);
|
||||
n.isIgnored = n.isTestnet || (!(o.standardAccount && o.decimals && o.symbols) && o.prefix !== 42);
|
||||
n.isIgnored = n.isTestnet || (
|
||||
!(
|
||||
o.standardAccount &&
|
||||
o.decimals && o.decimals.length &&
|
||||
o.symbols && o.symbols.length
|
||||
) &&
|
||||
o.prefix !== 42
|
||||
);
|
||||
|
||||
return n;
|
||||
}
|
||||
@@ -43,12 +51,12 @@ function sortNetworks (a: Network, b: Network): number {
|
||||
const isUnSortedB = UNSORTED.includes(b.prefix);
|
||||
|
||||
return isUnSortedA === isUnSortedB
|
||||
? 0
|
||||
? isUnSortedA
|
||||
? 0
|
||||
: a.displayName.localeCompare(b.displayName)
|
||||
: isUnSortedA
|
||||
? -1
|
||||
: isUnSortedB
|
||||
? 1
|
||||
: a.displayName.localeCompare(b.displayName);
|
||||
: 1;
|
||||
}
|
||||
|
||||
// This is all the Substrate networks with our additional information
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '8.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '9.4.1' };
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import known from '@substrate/ss58-registry';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import other from './test/ss58registry.test.json';
|
||||
|
||||
describe('@substrate/ss58-registry', (): void => {
|
||||
it('has known values', (): void => {
|
||||
const json = JSON.stringify(known, null, 2);
|
||||
|
||||
try {
|
||||
expect(JSON.parse(json)).toEqual(other);
|
||||
} catch (error) {
|
||||
if (process.env.GITHUB_REPOSITORY) {
|
||||
console.error(json);
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, './test/ss58registry.test.json'), json, { flag: 'w' });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,785 +0,0 @@
|
||||
// Copyright 2017-2022 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//
|
||||
// Auto-generated by yarn networks:sync (via scripts/fromSubstrate.mjs)
|
||||
//
|
||||
// This file should never be edited manually. Rather the process is as follow -
|
||||
//
|
||||
// - make a PR to the upstream registry found at https://github.com/paritytech/ss58-registry/
|
||||
// - ensure the PR gets merged
|
||||
// - yarn networks:sync in this repo to sync
|
||||
//
|
||||
// Any manual changes to this file will make CI cron checks fail and will be
|
||||
// lost when the registry is updated alongside the above sync.
|
||||
//
|
||||
|
||||
import type { KnownSubstrate } from './types';
|
||||
|
||||
export const knownSubstrate: KnownSubstrate[] = [
|
||||
{
|
||||
decimals: [10],
|
||||
displayName: 'Polkadot Relay Chain',
|
||||
network: 'polkadot',
|
||||
prefix: 0,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['DOT'],
|
||||
website: 'https://polkadot.network'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Bare 32-bit Schnorr/Ristretto (S/R 25519) public key.',
|
||||
network: 'BareSr25519',
|
||||
prefix: 1,
|
||||
standardAccount: 'Sr25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Kusama Relay Chain',
|
||||
network: 'kusama',
|
||||
prefix: 2,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['KSM'],
|
||||
website: 'https://kusama.network'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Bare 32-bit Ed25519 public key.',
|
||||
network: 'BareEd25519',
|
||||
prefix: 3,
|
||||
standardAccount: 'Ed25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Katal Chain',
|
||||
network: 'katalchain',
|
||||
prefix: 4,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [15],
|
||||
displayName: 'Plasm Network',
|
||||
network: 'plasm',
|
||||
prefix: 5,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PLM'],
|
||||
website: 'https://plasmnet.io'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Bifrost',
|
||||
network: 'bifrost',
|
||||
prefix: 6,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['BNC'],
|
||||
website: 'https://bifrost.finance/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Edgeware',
|
||||
network: 'edgeware',
|
||||
prefix: 7,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['EDG'],
|
||||
website: 'https://edgewa.re'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Karura',
|
||||
network: 'karura',
|
||||
prefix: 8,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['KAR'],
|
||||
website: 'https://karura.network/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Laminar Reynolds Canary',
|
||||
network: 'reynolds',
|
||||
prefix: 9,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['REY'],
|
||||
website: 'http://laminar.network/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
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: [6],
|
||||
displayName: 'Polymesh',
|
||||
network: 'polymesh',
|
||||
prefix: 12,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['POLYX'],
|
||||
website: 'https://polymath.network/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Integritee',
|
||||
network: 'integritee',
|
||||
prefix: 13,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['TEER'],
|
||||
website: 'https://integritee.network'
|
||||
},
|
||||
{
|
||||
decimals: [0],
|
||||
displayName: 'Totem',
|
||||
network: 'totem',
|
||||
prefix: 14,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['TOTEM'],
|
||||
website: 'https://totemaccounting.com'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Synesthesia',
|
||||
network: 'synesthesia',
|
||||
prefix: 15,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['SYN'],
|
||||
website: 'https://synesthesia.network/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Kulupu',
|
||||
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: [12],
|
||||
displayName: 'Stafi',
|
||||
network: 'stafi',
|
||||
prefix: 20,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['FIS'],
|
||||
website: 'https://stafi.io'
|
||||
},
|
||||
{
|
||||
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: [10],
|
||||
displayName: 'Jupiter',
|
||||
network: 'jupiter',
|
||||
prefix: 26,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['jDOT'],
|
||||
website: 'https://jupiter.patract.io'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Subsocial',
|
||||
network: 'subsocial',
|
||||
prefix: 28,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [12, 12],
|
||||
displayName: 'CORD Network',
|
||||
network: 'cord',
|
||||
prefix: 29,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['DHI', 'WAY'],
|
||||
website: 'https://cord.network/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Phala Network',
|
||||
network: 'phala',
|
||||
prefix: 30,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PHA'],
|
||||
website: 'https://phala.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Litentry Network',
|
||||
network: 'litentry',
|
||||
prefix: 31,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['LIT'],
|
||||
website: 'https://litentry.com/'
|
||||
},
|
||||
{
|
||||
decimals: [9],
|
||||
displayName: 'Robonomics',
|
||||
network: 'robonomics',
|
||||
prefix: 32,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['XRT'],
|
||||
website: 'https://robonomics.network'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'DataHighway',
|
||||
network: 'datahighway',
|
||||
prefix: 33,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Ares Protocol',
|
||||
network: 'ares',
|
||||
prefix: 34,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['ARES'],
|
||||
website: 'https://www.aresprotocol.com/'
|
||||
},
|
||||
{
|
||||
decimals: [15],
|
||||
displayName: 'Valiu Liquidity Network',
|
||||
network: 'vln',
|
||||
prefix: 35,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['USDv'],
|
||||
website: 'https://valiu.com/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Centrifuge Chain',
|
||||
network: 'centrifuge',
|
||||
prefix: 36,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CFG'],
|
||||
website: 'https://centrifuge.io/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Nodle Chain',
|
||||
network: 'nodle',
|
||||
prefix: 37,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['NODL'],
|
||||
website: 'https://nodle.io/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'KILT Chain',
|
||||
network: 'kilt',
|
||||
prefix: 38,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['KILT'],
|
||||
website: 'https://kilt.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: 'Polimec Chain',
|
||||
network: 'poli',
|
||||
prefix: 41,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: 'https://polimec.io/'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Substrate',
|
||||
network: 'substrate',
|
||||
prefix: 42,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: 'https://substrate.io/'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Bare 32-bit ECDSA SECP-256k1 public key.',
|
||||
network: 'BareSecp256k1',
|
||||
prefix: 43,
|
||||
standardAccount: 'secp256k1',
|
||||
symbols: null,
|
||||
website: null
|
||||
},
|
||||
{
|
||||
decimals: [8],
|
||||
displayName: 'ChainX',
|
||||
network: 'chainx',
|
||||
prefix: 44,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PCX'],
|
||||
website: 'https://chainx.org/'
|
||||
},
|
||||
{
|
||||
decimals: [12, 12],
|
||||
displayName: 'UniArts Network',
|
||||
network: 'uniarts',
|
||||
prefix: 45,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['UART', 'UINK'],
|
||||
website: 'https://uniarts.me'
|
||||
},
|
||||
{
|
||||
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: [12],
|
||||
displayName: 'Neatcoin Mainnet',
|
||||
network: 'neatcoin',
|
||||
prefix: 48,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['NEAT'],
|
||||
website: 'https://neatcoin.org'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Picasso',
|
||||
network: 'picasso',
|
||||
prefix: 49,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PICA'],
|
||||
website: 'https://picasso.composable.finance'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Composable',
|
||||
network: 'composable',
|
||||
prefix: 50,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['LAYR'],
|
||||
website: 'https://composable.finance'
|
||||
},
|
||||
{
|
||||
decimals: [9],
|
||||
displayName: 'xx network',
|
||||
network: 'xxnetwork',
|
||||
prefix: 55,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['XX'],
|
||||
website: 'https://xx.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'HydraDX',
|
||||
network: 'hydradx',
|
||||
prefix: 63,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['HDX'],
|
||||
website: 'https://hydradx.io'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'AvN Mainnet',
|
||||
network: 'aventus',
|
||||
prefix: 65,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['AVT'],
|
||||
website: 'https://aventus.io'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Crust Network',
|
||||
network: 'crust',
|
||||
prefix: 66,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CRU'],
|
||||
website: 'https://crust.network'
|
||||
},
|
||||
{
|
||||
decimals: [9, 9, 9],
|
||||
displayName: 'Genshiro Network',
|
||||
network: 'genshiro',
|
||||
prefix: 67,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['GENS', 'EQD', 'LPT0'],
|
||||
website: 'https://genshiro.equilibrium.io'
|
||||
},
|
||||
{
|
||||
decimals: [9],
|
||||
displayName: 'Equilibrium Network',
|
||||
network: 'equilibrium',
|
||||
prefix: 68,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['EQ'],
|
||||
website: 'https://equilibrium.io'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'SORA Network',
|
||||
network: 'sora',
|
||||
prefix: 69,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['XOR'],
|
||||
website: 'https://sora.org'
|
||||
},
|
||||
{
|
||||
decimals: [10],
|
||||
displayName: 'Zeitgeist',
|
||||
network: 'zeitgeist',
|
||||
prefix: 73,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['ZTG'],
|
||||
website: 'https://zeitgeist.pm'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Manta network',
|
||||
network: 'manta',
|
||||
prefix: 77,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['MANTA'],
|
||||
website: 'https://manta.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Calamari: Manta Canary Network',
|
||||
network: 'calamari',
|
||||
prefix: 78,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['KMA'],
|
||||
website: 'https://manta.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Polkadex Mainnet',
|
||||
network: 'polkadex',
|
||||
prefix: 88,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PDEX'],
|
||||
website: 'https://polkadex.trade'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'PolkaSmith Canary Network',
|
||||
network: 'polkasmith',
|
||||
prefix: 98,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PKS'],
|
||||
website: 'https://polkafoundry.com'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'PolkaFoundry Network',
|
||||
network: 'polkafoundry',
|
||||
prefix: 99,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PKF'],
|
||||
website: 'https://polkafoundry.com'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'OriginTrail Parachain',
|
||||
network: 'origintrail-parachain',
|
||||
prefix: 101,
|
||||
standardAccount: 'secp256k1',
|
||||
symbols: ['TRAC'],
|
||||
website: 'https://origintrail.io'
|
||||
},
|
||||
{
|
||||
decimals: [10],
|
||||
displayName: 'Pontem Network',
|
||||
network: 'pontem-network',
|
||||
prefix: 105,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PONT'],
|
||||
website: 'https://pontem.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Heiko',
|
||||
network: 'heiko',
|
||||
prefix: 110,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['HKO'],
|
||||
website: 'https://parallel.fi/'
|
||||
},
|
||||
{
|
||||
decimals: null,
|
||||
displayName: 'Integritee Incognito',
|
||||
network: 'integritee-incognito',
|
||||
prefix: 113,
|
||||
standardAccount: '*25519',
|
||||
symbols: null,
|
||||
website: 'https://integritee.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Clover Finance',
|
||||
network: 'clover',
|
||||
prefix: 128,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CLV'],
|
||||
website: 'https://clover.finance'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Altair',
|
||||
network: 'altair',
|
||||
prefix: 136,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['AIR'],
|
||||
website: 'https://centrifuge.io/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Parallel',
|
||||
network: 'parallel',
|
||||
prefix: 172,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['PARA'],
|
||||
website: 'https://parallel.fi/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Social Network',
|
||||
network: 'social-network',
|
||||
prefix: 252,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['NET'],
|
||||
website: 'https://social.network'
|
||||
},
|
||||
{
|
||||
decimals: [15],
|
||||
displayName: 'QUARTZ by UNIQUE',
|
||||
network: 'quartz_mainnet',
|
||||
prefix: 255,
|
||||
standardAccount: '*25519',
|
||||
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: 'Efinity',
|
||||
network: 'efinity',
|
||||
prefix: 1110,
|
||||
standardAccount: 'Sr25519',
|
||||
symbols: ['EFI'],
|
||||
website: 'https://efinity.io/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Moonbeam',
|
||||
network: 'moonbeam',
|
||||
prefix: 1284,
|
||||
standardAccount: 'secp256k1',
|
||||
symbols: ['GLMR'],
|
||||
website: 'https://moonbeam.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Moonriver',
|
||||
network: 'moonriver',
|
||||
prefix: 1285,
|
||||
standardAccount: 'secp256k1',
|
||||
symbols: ['MOVR'],
|
||||
website: 'https://moonbeam.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Kapex',
|
||||
network: 'kapex',
|
||||
prefix: 2007,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['KAPEX'],
|
||||
website: 'https://totemaccounting.com'
|
||||
},
|
||||
{
|
||||
decimals: [10],
|
||||
displayName: 'Interlay',
|
||||
network: 'interlay',
|
||||
prefix: 2032,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['INTR'],
|
||||
website: 'https://interlay.io/'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Kintsugi',
|
||||
network: 'kintsugi',
|
||||
prefix: 2092,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['KINT'],
|
||||
website: 'https://interlay.io/'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Subspace testnet',
|
||||
network: 'subspace_testnet',
|
||||
prefix: 2254,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['tSSC'],
|
||||
website: 'https://subspace.network'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Subspace',
|
||||
network: 'subspace',
|
||||
prefix: 6094,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['SSC'],
|
||||
website: 'https://subspace.network'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'Basilisk',
|
||||
network: 'basilisk',
|
||||
prefix: 10041,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['BSX'],
|
||||
website: 'https://bsx.fi'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'CESS Testnet',
|
||||
network: 'cess-testnet',
|
||||
prefix: 11330,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['TCESS'],
|
||||
website: 'https://cess.cloud'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
displayName: 'CESS',
|
||||
network: 'cess',
|
||||
prefix: 11331,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CESS'],
|
||||
website: 'https://cess.cloud'
|
||||
},
|
||||
{
|
||||
decimals: [18],
|
||||
displayName: 'Automata ContextFree',
|
||||
network: 'contextfree',
|
||||
prefix: 11820,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CTX'],
|
||||
website: 'https://ata.network'
|
||||
}
|
||||
];
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/keyring authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export type Icon = 'beachball' | 'empty' | 'jdenticon' | 'polkadot' | 'substrate';
|
||||
import type { RegistryEntry } from '@substrate/ss58-registry';
|
||||
|
||||
export interface KnownSubstrate {
|
||||
decimals: number[] | null,
|
||||
displayName: string;
|
||||
network: string | null;
|
||||
prefix: number;
|
||||
standardAccount: '*25519' | 'Ed25519' | 'Sr25519' | 'secp256k1' | null;
|
||||
symbols: string[] | null;
|
||||
website: string | null;
|
||||
}
|
||||
export type Icon = 'beachball' | 'empty' | 'jdenticon' | 'polkadot' | 'substrate';
|
||||
|
||||
export type KnownIcon = Record<string, Icon>;
|
||||
|
||||
@@ -19,6 +11,8 @@ export type KnownLedger = Record<string, number>;
|
||||
|
||||
export type KnownGenesis = Record<string, string[]>;
|
||||
|
||||
export type KnownSubstrate = RegistryEntry;
|
||||
|
||||
export type KnownTestnet = Record<string, true>;
|
||||
|
||||
export interface SubstrateNetwork extends KnownSubstrate {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"resolveJsonModule": true,
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": [
|
||||
"**/src/**/*.ts",
|
||||
"**/test/*.json"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../hw-ledger/tsconfig.build.json" },
|
||||
{ "path": "../util/tsconfig.build.json" },
|
||||
{ "path": "../x-fetch/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../hw-ledger" },
|
||||
{ "path": "../util" },
|
||||
{ "path": "../x-fetch" }
|
||||
]
|
||||
}
|
||||
@@ -16,35 +16,35 @@
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./cryptoInit.js",
|
||||
"./cryptoInit.cjs",
|
||||
"./bundleInit.js",
|
||||
"./bundleInit.cjs",
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"browser": {
|
||||
"crypto": false,
|
||||
"stream": false
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.7",
|
||||
"@noble/hashes": "0.5.7",
|
||||
"@noble/secp256k1": "1.3.4",
|
||||
"@polkadot/networks": "8.3.1",
|
||||
"@polkadot/util": "8.3.1",
|
||||
"@polkadot/wasm-crypto": "^4.5.1",
|
||||
"@polkadot/x-bigint": "8.3.1",
|
||||
"@polkadot/x-randomvalues": "8.3.1",
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@noble/hashes": "1.0.0",
|
||||
"@noble/secp256k1": "1.5.5",
|
||||
"@polkadot/networks": "9.4.1",
|
||||
"@polkadot/util": "9.4.1",
|
||||
"@polkadot/wasm-crypto": "^6.1.1",
|
||||
"@polkadot/x-bigint": "9.4.1",
|
||||
"@polkadot/x-randomvalues": "9.4.1",
|
||||
"@scure/base": "1.0.0",
|
||||
"ed2curve": "^0.3.0",
|
||||
"micro-base": "^0.10.2",
|
||||
"tweetnacl": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ed2curve": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "8.3.1"
|
||||
"@polkadot/util": "9.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,5 @@ import { decodeAddress } from './decode';
|
||||
* @summary Converts an SS58 address to its corresponding EVM address.
|
||||
*/
|
||||
export function addressToEvm (address: HexString | string | Uint8Array, ignoreChecksum?: boolean): Uint8Array {
|
||||
const decoded = decodeAddress(address, ignoreChecksum);
|
||||
|
||||
return decoded.subarray(0, 20);
|
||||
return decodeAddress(address, ignoreChecksum).subarray(0, 20);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
// Copyright 2017-2022 @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(networkToPrefix),
|
||||
allowedPrefix: availableNetworks.map(({ prefix }) => prefix),
|
||||
prefix: 42
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ const l = logger('setSS58Format');
|
||||
* @deprecated Use keyring.setSS58Format
|
||||
*/
|
||||
export function setSS58Format (prefix: Prefix): void {
|
||||
l.warn('Global setting of the ss58Format is deprecated and not recommended. Set format on the keyring (if used) or as pat of the address encode function');
|
||||
l.warn('Global setting of the ss58Format is deprecated and not recommended. Set format on the keyring (if used) or as part of the address encode function');
|
||||
|
||||
defaults.prefix = prefix;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { utils } from 'micro-base';
|
||||
import { utils } from '@scure/base';
|
||||
|
||||
import { createDecode, createEncode, createIs, createValidate } from './helpers';
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export function createDecode ({ coder, ipfs }: Config, validate: ValidateFn): De
|
||||
|
||||
return coder.decode(
|
||||
ipfs && ipfsCompat
|
||||
? value.substr(1)
|
||||
? value.substring(1)
|
||||
: value
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { base58 } from 'micro-base';
|
||||
import { base58 } from '@scure/base';
|
||||
|
||||
import { createDecode, createEncode, createIs, createValidate } from '../base32/helpers';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { base64 } from 'micro-base';
|
||||
import { base64 } from '@scure/base';
|
||||
|
||||
import { createDecode, createEncode, createIs, createValidate } from '../base32/helpers';
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ import { blake2b, isReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createAsHex } from '../helpers';
|
||||
|
||||
type BitLength = 64 | 128 | 256 | 384 | 512;
|
||||
|
||||
/**
|
||||
* @name blake2AsU8a
|
||||
* @summary Creates a blake2b u8a from the input.
|
||||
@@ -26,7 +24,7 @@ type BitLength = 64 | 128 | 256 | 384 | 512;
|
||||
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d]
|
||||
* ```
|
||||
*/
|
||||
export function blake2AsU8a (data: HexString | Uint8Array | string, bitLength: BitLength = 256, key?: Uint8Array | null, onlyJs?: boolean): Uint8Array {
|
||||
export function blake2AsU8a (data: HexString | Uint8Array | string, bitLength: 64 | 128 | 256 | 384 | 512 = 256, key?: Uint8Array | null, onlyJs?: boolean): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
const u8a = u8aToU8a(data);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './cryptoInit';
|
||||
import './bundleInit';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@ utilsNobleSecp256k1.hmacSha256Sync = (key: Uint8Array, ...messages: Uint8Array[]
|
||||
|
||||
// start init process immediately
|
||||
cryptoWaitReady().catch((): void => {
|
||||
// shouldn't happen, logged above
|
||||
// shouldn't happen, logged and caught inside cryptoWaitReady
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
describe('cryptoWaitReady', (): void => {
|
||||
it('should return false when it cannot initialize', async (): Promise<void> => {
|
||||
const old = global.WebAssembly;
|
||||
|
||||
global.WebAssembly = null as unknown as typeof WebAssembly;
|
||||
|
||||
const { cryptoWaitReady } = await import('./crypto');
|
||||
|
||||
expect(await cryptoWaitReady()).toBe(false);
|
||||
|
||||
global.WebAssembly = old;
|
||||
});
|
||||
});
|
||||
@@ -1,16 +1,17 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
import { isReady, waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
export const cryptoIsReady = isReady;
|
||||
|
||||
export function cryptoWaitReady (): Promise<boolean> {
|
||||
return waitReady()
|
||||
.then((): boolean => true)
|
||||
.catch((error): boolean => {
|
||||
console.error('Unable to initialize @polkadot/util-crypto', error);
|
||||
.then((): boolean => {
|
||||
assert(isReady(), 'Unable to initialize @polkadot/util-crypto');
|
||||
|
||||
return false;
|
||||
});
|
||||
return true;
|
||||
})
|
||||
.catch(() => false);
|
||||
}
|
||||
|
||||
@@ -14,13 +14,12 @@ interface DualHash {
|
||||
512: (u8a: Uint8Array) => Uint8Array;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function createAsHex <T extends (...args: any[]) => Uint8Array> (fn: T): (...args: Parameters<T>) => HexString {
|
||||
export function createAsHex <T extends (...args: never[]) => Uint8Array> (fn: T): (...args: Parameters<T>) => HexString {
|
||||
return (...args: Parameters<T>): HexString =>
|
||||
u8aToHex(fn(...args));
|
||||
}
|
||||
|
||||
export function createBitHasher <T> (bitLength: T, fn: (data: HexString | Buffer | Uint8Array | string, bitLength: T, onlyJs?: boolean) => Uint8Array): (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean) => Uint8Array {
|
||||
export function createBitHasher (bitLength: 256 | 512, fn: (data: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512, onlyJs?: boolean) => Uint8Array): (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean) => Uint8Array {
|
||||
return (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean): Uint8Array =>
|
||||
fn(data, bitLength, onlyJs);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import { sha512 } from '@noble/hashes/sha512';
|
||||
import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { hmacSha256, hmacSha512, isReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
type BitLength = 256 | 512;
|
||||
|
||||
const JS_HASH = {
|
||||
256: sha256,
|
||||
512: sha512
|
||||
@@ -20,7 +18,7 @@ const WA_MHAC = {
|
||||
512: hmacSha512
|
||||
};
|
||||
|
||||
function createSha (bitLength: BitLength): (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array {
|
||||
function createSha (bitLength: 256 | 512): (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array {
|
||||
return (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean): Uint8Array =>
|
||||
hmacShaAsU8a(key, data, bitLength, onlyJs);
|
||||
}
|
||||
@@ -29,7 +27,7 @@ function createSha (bitLength: BitLength): (key: Uint8Array | string, data: Uint
|
||||
* @name hmacShaAsU8a
|
||||
* @description creates a Hmac Sha (256/512) Uint8Array from the key & data
|
||||
*/
|
||||
export function hmacShaAsU8a (key: Uint8Array | string, data: Uint8Array, bitLength: BitLength = 256, onlyJs?: boolean): Uint8Array {
|
||||
export function hmacShaAsU8a (key: Uint8Array | string, data: Uint8Array, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array {
|
||||
const u8aKey = u8aToU8a(key);
|
||||
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
|
||||
@@ -20,7 +20,7 @@ export class DeriveJunction {
|
||||
public static from (value: string): DeriveJunction {
|
||||
const result = new DeriveJunction();
|
||||
const [code, isHard] = value.startsWith('/')
|
||||
? [value.substr(1), true]
|
||||
? [value.substring(1), true]
|
||||
: [value, false];
|
||||
|
||||
result.soft(
|
||||
|
||||
@@ -24,7 +24,7 @@ export function keyExtractPath (derivePath: string): ExtractResult {
|
||||
constructed = parts.join('');
|
||||
|
||||
for (const p of parts) {
|
||||
path.push(DeriveJunction.from(p.substr(1)));
|
||||
path.push(DeriveJunction.from(p.substring(1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// - Use util-crypto randomAsU8a (instead of randombytes)
|
||||
// - Remove setting of wordlist passing of wordlist in functions
|
||||
// - Remove mnemonicToSeed (we only use the sync variant)
|
||||
// - generateMnemonic takes number of words (instead of strength)
|
||||
|
||||
import { assert, stringToU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -73,7 +74,7 @@ export function mnemonicToEntropy (mnemonic: string): Uint8Array {
|
||||
// calculate the checksum and compare
|
||||
const entropyBytes = entropyBits.match(/(.{1,8})/g)?.map(binaryToByte);
|
||||
|
||||
assert(entropyBytes && entropyBytes.length % 4 === 0 && entropyBytes.length >= 16 && entropyBytes.length <= 32, INVALID_ENTROPY);
|
||||
assert(entropyBytes && (entropyBytes.length % 4 === 0) && (entropyBytes.length >= 16) && (entropyBytes.length <= 32), INVALID_ENTROPY);
|
||||
|
||||
const entropy = u8aToU8a(entropyBytes);
|
||||
const newChecksum = deriveChecksumBits(entropy);
|
||||
@@ -85,7 +86,7 @@ export function mnemonicToEntropy (mnemonic: string): Uint8Array {
|
||||
|
||||
export function entropyToMnemonic (entropy: Uint8Array): string {
|
||||
// 128 <= ENT <= 256
|
||||
assert(entropy.length % 4 === 0 && entropy.length >= 16 && entropy.length <= 32, INVALID_ENTROPY);
|
||||
assert((entropy.length % 4 === 0) && (entropy.length >= 16) && (entropy.length <= 32), INVALID_ENTROPY);
|
||||
|
||||
const entropyBits = bytesToBinary(Array.from(entropy));
|
||||
const checksumBits = deriveChecksumBits(entropy);
|
||||
@@ -97,12 +98,8 @@ export function entropyToMnemonic (entropy: Uint8Array): string {
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
export function generateMnemonic (strength?: number): string {
|
||||
strength = strength || 128;
|
||||
|
||||
assert(strength % 32 === 0, INVALID_ENTROPY);
|
||||
|
||||
return entropyToMnemonic(randomAsU8a(strength / 8));
|
||||
export function generateMnemonic (numWords: 12 | 15 | 18 | 21 | 24): string {
|
||||
return entropyToMnemonic(randomAsU8a((numWords / 3) * 4));
|
||||
}
|
||||
|
||||
export function validateMnemonic (mnemonic: string): boolean {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { cryptoWaitReady } from '..';
|
||||
import { mnemonicGenerate, WordCount } from './generate';
|
||||
import { mnemonicGenerate } from './generate';
|
||||
import { mnemonicValidate } from './validate';
|
||||
|
||||
describe('mnemonicGenerate', (): void => {
|
||||
@@ -17,7 +17,7 @@ describe('mnemonicGenerate', (): void => {
|
||||
});
|
||||
|
||||
describe.each([false, true])('onlyJs=%p', (onlyJs): void => {
|
||||
it.each([12, 15, 18, 21, 24] as WordCount[])('generates a valid mnemonic (%p words)', (num): void => {
|
||||
it.each([12, 15, 18, 21, 24] as 12[])('generates a valid mnemonic (%p words)', (num): void => {
|
||||
const mnemonic = mnemonicGenerate(num, onlyJs);
|
||||
const isValid = mnemonicValidate(mnemonic);
|
||||
|
||||
|
||||
@@ -6,17 +6,6 @@ import { bip39Generate, isReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { generateMnemonic } from './bip39';
|
||||
|
||||
export type WordCount = 12 | 15 | 18 | 21 | 24;
|
||||
|
||||
// mapping of words to the actual strength (as expected)
|
||||
const STRENGTH_MAP = {
|
||||
12: 16 * 8,
|
||||
15: 20 * 8,
|
||||
18: 24 * 8,
|
||||
21: 28 * 8,
|
||||
24: 32 * 8
|
||||
};
|
||||
|
||||
/**
|
||||
* @name mnemonicGenerate
|
||||
* @summary Creates a valid mnemonic string using using [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).
|
||||
@@ -29,8 +18,8 @@ const STRENGTH_MAP = {
|
||||
* const mnemonic = mnemonicGenerate(); // => string
|
||||
* ```
|
||||
*/
|
||||
export function mnemonicGenerate (numWords: WordCount = 12, onlyJs?: boolean): string {
|
||||
export function mnemonicGenerate (numWords: 12 | 15 | 18 | 21 | 24 = 12, onlyJs?: boolean): string {
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
? bip39Generate(numWords)
|
||||
: generateMnemonic(STRENGTH_MAP[numWords]);
|
||||
: generateMnemonic(numWords);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('mnemonicToMiniSecret', (): void => {
|
||||
u8aToHex(mnemonicToMiniSecret(mnemonic, 'Substrate', onlyJs))
|
||||
).toEqual(
|
||||
// mini returned here, only check first 32-bytes (64 hex + 2 prefix)
|
||||
seed.substr(0, 66)
|
||||
seed.substring(0, 66)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@polkadot/networks/interfaces';
|
||||
// Don't use a export * since we don't want to duplicate packageInfo
|
||||
export { allNetworks, availableNetworks, selectableNetworks } from '@polkadot/networks';
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '8.3.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '9.4.1' };
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Keypair } from '../../types';
|
||||
|
||||
import { getPublicKey } from '@noble/secp256k1';
|
||||
|
||||
import { assert, hasBigInt } from '@polkadot/util';
|
||||
import { assert, hasBigInt, u8aEmpty } from '@polkadot/util';
|
||||
import { isReady, secp256k1FromSeed } from '@polkadot/wasm-crypto';
|
||||
|
||||
/**
|
||||
@@ -17,9 +17,16 @@ export function secp256k1PairFromSeed (seed: Uint8Array, onlyJs?: boolean): Keyp
|
||||
|
||||
if (!hasBigInt || (!onlyJs && isReady())) {
|
||||
const full = secp256k1FromSeed(seed);
|
||||
const publicKey = full.slice(32);
|
||||
|
||||
// There is an issue with the secp256k1 when running in an ASM.js environment where
|
||||
// it seems that the lazy static section yields invalid results on the _first_ run.
|
||||
// If this happens, fail outright, we cannot allow invalid return values
|
||||
// https://github.com/polkadot-js/wasm/issues/307
|
||||
assert(!u8aEmpty(publicKey), 'Invalid publicKey generated from WASM interface');
|
||||
|
||||
return {
|
||||
publicKey: full.slice(32),
|
||||
publicKey,
|
||||
secretKey: full.slice(0, 32)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '../cryptoInit';
|
||||
import '../bundleInit';
|
||||
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '../cryptoInit';
|
||||
import '../bundleInit';
|
||||
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
@@ -67,7 +67,9 @@ function verifyMultisig (result: VerifyResult, { message, publicKey, signature }
|
||||
result.isValid = {
|
||||
ecdsa: () => verifyDetect(result, { message, publicKey, signature: signature.subarray(1) }, VERIFIERS_ECDSA).isValid,
|
||||
ed25519: () => ed25519Verify(message, signature.subarray(1), publicKey),
|
||||
none: () => { throw Error('no verify for `none` crypto type'); },
|
||||
none: () => {
|
||||
throw Error('no verify for `none` crypto type');
|
||||
},
|
||||
sr25519: () => sr25519Verify(message, signature.subarray(1), publicKey)
|
||||
}[type]();
|
||||
} catch (error) {
|
||||
|
||||
@@ -9,8 +9,6 @@ import { isReady, twox } from '@polkadot/wasm-crypto';
|
||||
import { createAsHex } from '../helpers';
|
||||
import { xxhash64 } from './xxhash64';
|
||||
|
||||
type BitLength = 64 | 128 | 192 | 256 | 320 | 384 | 448 | 512;
|
||||
|
||||
/**
|
||||
* @name xxhashAsU8a
|
||||
* @summary Creates a xxhash64 u8a from the input.
|
||||
@@ -25,7 +23,7 @@ type BitLength = 64 | 128 | 192 | 256 | 320 | 384 | 448 | 512;
|
||||
* xxhashAsU8a('abc'); // => 0x44bc2cf5ad770999
|
||||
* ```
|
||||
*/
|
||||
export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bitLength: BitLength = 64, onlyJs?: boolean): Uint8Array {
|
||||
export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bitLength: 64 | 128 | 192 | 256 | 320 | 384 | 448 | 512 = 64, onlyJs?: boolean): Uint8Array {
|
||||
const rounds = Math.ceil(bitLength / 64);
|
||||
const u8a = u8aToU8a(data);
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../networks/tsconfig.build.json" },
|
||||
{ "path": "../util/tsconfig.build.json" },
|
||||
{ "path": "../x-bigint/tsconfig.build.json" },
|
||||
{ "path": "../x-randomvalues/tsconfig.build.json" }
|
||||
]
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../networks" },
|
||||
{ "path": "../util" },
|
||||
{ "path": "../x-bigint" },
|
||||
{ "path": "../x-randomvalues" }
|
||||
]
|
||||
}
|
||||
+11
-11
@@ -9,13 +9,13 @@
|
||||
"exports": {
|
||||
"./hex/toU8a": {
|
||||
"node": {
|
||||
"require": "./hex/toU8aBuffer.cjs",
|
||||
"require": "./cjs/hex/toU8aBuffer.js",
|
||||
"default": "./hex/toU8aBuffer.js"
|
||||
}
|
||||
},
|
||||
"./u8a/toHex": {
|
||||
"node": {
|
||||
"require": "./u8a/toHexBuffer.cjs",
|
||||
"require": "./cjs/u8a/toHexBuffer.js",
|
||||
"default": "./u8a/toHexBuffer.js"
|
||||
}
|
||||
}
|
||||
@@ -34,19 +34,19 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.3.1",
|
||||
"version": "9.4.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.7",
|
||||
"@polkadot/x-bigint": "8.3.1",
|
||||
"@polkadot/x-global": "8.3.1",
|
||||
"@polkadot/x-textdecoder": "8.3.1",
|
||||
"@polkadot/x-textencoder": "8.3.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.12.0",
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/x-bigint": "9.4.1",
|
||||
"@polkadot/x-global": "9.4.1",
|
||||
"@polkadot/x-textdecoder": "9.4.1",
|
||||
"@polkadot/x-textencoder": "9.4.1",
|
||||
"@types/bn.js": "^5.1.0",
|
||||
"bn.js": "^5.2.1",
|
||||
"ip-regex": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/x-randomvalues": "8.3.1"
|
||||
"@polkadot/x-randomvalues": "9.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { arrayChunk } from '.';
|
||||
import { performance } from '../test/performance';
|
||||
import { arrayChunk, arrayRange } from '.';
|
||||
|
||||
describe('arrayChunk', (): void => {
|
||||
it('chunks arrays', (): void => {
|
||||
@@ -9,4 +10,6 @@ describe('arrayChunk', (): void => {
|
||||
arrayChunk([1, 2, 3, 4, 5, 6, 7], 3)
|
||||
).toEqual([[1, 2, 3], [4, 5, 6], [7]]);
|
||||
});
|
||||
|
||||
performance('arrayChunk', 200_000, [[arrayRange(500), 50]], arrayChunk);
|
||||
});
|
||||
|
||||
@@ -2,23 +2,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { HexString, ToBigInt, ToBn, ToBnOptions } from '../types';
|
||||
import type { HexString, NumberOptions, ToBigInt, ToBn } from '../types';
|
||||
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { u8aToHex } from '../u8a';
|
||||
import { nToU8a } from './toU8a';
|
||||
|
||||
interface Options extends ToBnOptions {
|
||||
bitLength?: number;
|
||||
}
|
||||
|
||||
const ZERO_STR = '0x00';
|
||||
|
||||
/**
|
||||
* @name nToHex
|
||||
* @summary Creates a hex value from a bigint object.
|
||||
*/
|
||||
export function nToHex <ExtToBn extends ToBn | ToBigInt> (value?: ExtToBn | BN | bigint | number | null, options?: Options): HexString {
|
||||
export function nToHex <ExtToBn extends ToBn | ToBigInt> (value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions): HexString {
|
||||
return !value
|
||||
? ZERO_STR
|
||||
: u8aToHex(
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { ToBigInt, ToBn, ToBnOptions } from '../types';
|
||||
import type { NumberOptions, ToBigInt, ToBn } from '../types';
|
||||
|
||||
import { BigInt } from '@polkadot/x-bigint';
|
||||
|
||||
@@ -10,20 +10,10 @@ import { objectSpread } from '../object/spread';
|
||||
import { _0n, _1n } from './consts';
|
||||
import { nToBigInt } from './toBigInt';
|
||||
|
||||
interface Options extends ToBnOptions {
|
||||
bitLength?: number;
|
||||
}
|
||||
|
||||
const DIV = BigInt(256);
|
||||
const NEG_MASK = BigInt(0xff);
|
||||
|
||||
function createEmpty ({ bitLength = 0 }: Options): Uint8Array {
|
||||
return bitLength === -1
|
||||
? new Uint8Array()
|
||||
: new Uint8Array(Math.ceil(bitLength / 8));
|
||||
}
|
||||
|
||||
function toU8a (value: bigint, { isLe, isNegative }: Options): Uint8Array {
|
||||
function toU8a (value: bigint, { isLe, isNegative }: NumberOptions): Uint8Array {
|
||||
const arr: number[] = [];
|
||||
|
||||
if (isNegative) {
|
||||
@@ -54,8 +44,8 @@ function toU8a (value: bigint, { isLe, isNegative }: Options): Uint8Array {
|
||||
* @name nToU8a
|
||||
* @summary Creates a Uint8Array object from a bigint.
|
||||
*/
|
||||
export function nToU8a <ExtToBn extends ToBn | ToBigInt> (value?: ExtToBn | BN | bigint | number | null, options?: Options): Uint8Array {
|
||||
const opts: Options = objectSpread(
|
||||
export function nToU8a <ExtToBn extends ToBn | ToBigInt> (value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions): Uint8Array {
|
||||
const opts: NumberOptions = objectSpread(
|
||||
{ bitLength: -1, isLe: true, isNegative: false },
|
||||
options
|
||||
);
|
||||
@@ -63,7 +53,9 @@ export function nToU8a <ExtToBn extends ToBn | ToBigInt> (value?: ExtToBn | BN |
|
||||
const valueBi = nToBigInt(value);
|
||||
|
||||
if (valueBi === _0n) {
|
||||
return createEmpty(opts);
|
||||
return opts.bitLength === -1
|
||||
? new Uint8Array()
|
||||
: new Uint8Array(Math.ceil((opts.bitLength || 0) / 8));
|
||||
}
|
||||
|
||||
const u8a = toU8a(valueBi, opts);
|
||||
|
||||
@@ -27,10 +27,9 @@ import { BN } from './bn';
|
||||
* ```
|
||||
*/
|
||||
export function bnToBn <ExtToBn extends ToBigInt | ToBn> (value?: HexString | ExtToBn | BN | bigint | string | number | null): BN {
|
||||
return BN.isBN(value)
|
||||
? value
|
||||
: !value
|
||||
? new BN(0)
|
||||
return value
|
||||
? BN.isBN(value)
|
||||
? value
|
||||
: isHex(value)
|
||||
? hexToBn(value.toString())
|
||||
: isBigInt(value)
|
||||
@@ -39,5 +38,6 @@ export function bnToBn <ExtToBn extends ToBigInt | ToBn> (value?: HexString | Ex
|
||||
? value.toBn()
|
||||
: isToBigInt(value)
|
||||
? new BN(value.toBigInt().toString())
|
||||
: new BN(value);
|
||||
: new BN(value)
|
||||
: new BN(0);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ describe('bnToHex', (): void => {
|
||||
).toBe('0xfffffb2e');
|
||||
});
|
||||
|
||||
it('handles backwards compatibility', (): void => {
|
||||
it('handles legacy compatibility', (): void => {
|
||||
expect(
|
||||
bnToHex(new BN(1234), 32)
|
||||
).toBe(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString, ToBn, ToBnOptions } from '../types';
|
||||
import type { HexString, NumberOptions, ToBn } from '../types';
|
||||
import type { BN } from './bn';
|
||||
|
||||
import { isNumber } from '../is/number';
|
||||
@@ -9,12 +9,8 @@ import { objectSpread } from '../object/spread';
|
||||
import { u8aToHex } from '../u8a';
|
||||
import { bnToU8a } from './toU8a';
|
||||
|
||||
interface Options extends ToBnOptions {
|
||||
bitLength?: number;
|
||||
}
|
||||
|
||||
const ZERO_STR = '0x00';
|
||||
const DEFAULT_OPTS: Options = { bitLength: -1, isLe: false, isNegative: false };
|
||||
const DEFAULT_OPTS: NumberOptions = { bitLength: -1, isLe: false, isNegative: false };
|
||||
|
||||
/**
|
||||
* @name bnToHex
|
||||
@@ -31,9 +27,11 @@ const DEFAULT_OPTS: Options = { bitLength: -1, isLe: false, isNegative: false };
|
||||
* bnToHex(new BN(0x123456)); // => '0x123456'
|
||||
* ```
|
||||
*/
|
||||
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, options?: Options): HexString;
|
||||
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions): HexString;
|
||||
/** @deprecated Use bnToHex (value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions) */
|
||||
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, bitLength?: number, isLe?: boolean): HexString;
|
||||
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, arg1: number | Options = DEFAULT_OPTS, arg2?: boolean): HexString {
|
||||
/** @deprecated Use bnToHex (value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions) */
|
||||
function bnToHex <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, arg1: number | NumberOptions = DEFAULT_OPTS, arg2?: boolean): HexString {
|
||||
return !value
|
||||
? ZERO_STR
|
||||
: u8aToHex(
|
||||
|
||||
@@ -50,12 +50,18 @@ describe('bnToU8a', (): void => {
|
||||
).toEqual(new Uint8Array([251, 46]));
|
||||
});
|
||||
|
||||
it('converts negative numbers (bitLength)', (): void => {
|
||||
it('converts negative numbers (LE)', (): void => {
|
||||
expect(
|
||||
bnToU8a(new BN(-1234), { bitLength: 32, isNegative: true })
|
||||
).toEqual(new Uint8Array([46, 251, 255, 255]));
|
||||
});
|
||||
|
||||
it('converts negative numbers (LE, bitLength)', (): void => {
|
||||
expect(
|
||||
bnToU8a(new BN(-123456), { bitLength: 32, isNegative: true })
|
||||
).toEqual(new Uint8Array([192, 29, 254, 255]));
|
||||
});
|
||||
|
||||
it('handles backwards compatibility', (): void => {
|
||||
expect(
|
||||
bnToU8a(new BN(1234), 32, false)
|
||||
|
||||
@@ -1,35 +1,14 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ToBn, ToBnOptions } from '../types';
|
||||
import type { NumberOptions, ToBn } 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 {
|
||||
bitLength?: number;
|
||||
}
|
||||
|
||||
const DEFAULT_OPTS: Options = { bitLength: -1, isLe: true, isNegative: false };
|
||||
|
||||
function createEmpty (byteLength: number, options: Options): Uint8Array {
|
||||
return options.bitLength === -1
|
||||
? new Uint8Array()
|
||||
: new Uint8Array(byteLength);
|
||||
}
|
||||
|
||||
function createValue (valueBn: BN, byteLength: number, { isLe, isNegative }: Options): Uint8Array {
|
||||
const output = new Uint8Array(byteLength);
|
||||
const bn = isNegative
|
||||
? valueBn.toTwos(byteLength * 8)
|
||||
: valueBn;
|
||||
|
||||
output.set(bn.toArray(isLe ? 'le' : 'be', byteLength), 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
const DEFAULT_OPTS: NumberOptions = { bitLength: -1, isLe: true, isNegative: false };
|
||||
|
||||
/**
|
||||
* @name bnToU8a
|
||||
@@ -45,10 +24,12 @@ function createValue (valueBn: BN, byteLength: number, { isLe, isNegative }: Opt
|
||||
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
* ```
|
||||
*/
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, options?: Options): Uint8Array;
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions): Uint8Array;
|
||||
/** @deprecated Use bnToU8a(value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions) */
|
||||
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 = DEFAULT_OPTS, arg2?: boolean): Uint8Array {
|
||||
const options: Options = objectSpread(
|
||||
/** @deprecated Use bnToU8a(value?: ExtToBn | BN | bigint | number | null, options?: NumberOptions) */
|
||||
function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number | null, arg1: number | NumberOptions = DEFAULT_OPTS, arg2?: boolean): Uint8Array {
|
||||
const { bitLength, isLe, isNegative }: NumberOptions = objectSpread(
|
||||
{ bitLength: -1, isLe: true, isNegative: false },
|
||||
isNumber(arg1)
|
||||
? { bitLength: arg1, isLe: arg2 }
|
||||
@@ -56,13 +37,24 @@ function bnToU8a <ExtToBn extends ToBn> (value?: ExtToBn | BN | bigint | number
|
||||
);
|
||||
|
||||
const valueBn = bnToBn(value);
|
||||
const byteLength = options.bitLength === -1
|
||||
const byteLength = bitLength === -1
|
||||
? Math.ceil(valueBn.bitLength() / 8)
|
||||
: Math.ceil((options.bitLength || 0) / 8);
|
||||
: Math.ceil((bitLength || 0) / 8);
|
||||
|
||||
return value
|
||||
? createValue(valueBn, byteLength, options)
|
||||
: createEmpty(byteLength, options);
|
||||
if (!value) {
|
||||
return bitLength === -1
|
||||
? new Uint8Array()
|
||||
: new Uint8Array(byteLength);
|
||||
}
|
||||
|
||||
const output = new Uint8Array(byteLength);
|
||||
const bn = isNegative
|
||||
? valueBn.toTwos(byteLength * 8)
|
||||
: valueBn;
|
||||
|
||||
output.set(bn.toArray(isLe ? 'le' : 'be', byteLength), 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
export { bnToU8a };
|
||||
|
||||
@@ -20,6 +20,7 @@ export * from './is';
|
||||
export * from './lazy';
|
||||
export * from './logger';
|
||||
export * from './memoize';
|
||||
export * from './nextTick';
|
||||
export * from './number';
|
||||
export * from './object';
|
||||
export * from './promisify';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aConcat } from '../u8a';
|
||||
import { u8aConcatStrict } from '../u8a';
|
||||
import { compactToU8a } from './toU8a';
|
||||
|
||||
/**
|
||||
@@ -17,8 +17,8 @@ import { compactToU8a } from './toU8a';
|
||||
* ```
|
||||
*/
|
||||
export function compactAddLength (input: Uint8Array): Uint8Array {
|
||||
return u8aConcat(
|
||||
return u8aConcatStrict([
|
||||
compactToU8a(input.length),
|
||||
input
|
||||
);
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
import { BN } from '../bn/bn';
|
||||
import { hexToU8a } from '../hex/toU8a';
|
||||
import { compactFromU8a } from '.';
|
||||
import { performance } from '../test/performance';
|
||||
import { compactFromU8a, compactFromU8aLim } from '.';
|
||||
|
||||
describe('compactFromU8a', (): void => {
|
||||
it('decoded u8 value', (): void => {
|
||||
@@ -14,16 +15,25 @@ describe('compactFromU8a', (): void => {
|
||||
|
||||
it('decodes from same u16 encoded value', (): void => {
|
||||
expect(
|
||||
compactFromU8a(new Uint8Array([0b11111101, 0b00000111]))
|
||||
).toEqual([2, new BN(511)]);
|
||||
compactFromU8a(new Uint8Array([0b11111101, 0b00000111])).toString()
|
||||
).toEqual(
|
||||
[2, new BN(511)].toString()
|
||||
);
|
||||
});
|
||||
|
||||
it('decodes from same u32 encoded value (short)', (): void => {
|
||||
expect(
|
||||
compactFromU8a(new Uint8Array([254, 255, 3, 0]))
|
||||
compactFromU8a(new Uint8Array([254, 255, 3, 0])).toString()
|
||||
).toEqual(
|
||||
// since we use in-place, the words are different... HACK it
|
||||
[4, new BN(0xffff).ishln(16).ishrn(16)]
|
||||
[4, new BN(0xffff)].toString()
|
||||
);
|
||||
});
|
||||
|
||||
it('decodes from same u32 encoded value (short)', (): void => {
|
||||
expect(
|
||||
compactFromU8a(new Uint8Array([254, 255, 255, 255])).toString()
|
||||
).toEqual(
|
||||
[4, new BN(1073741823)].toString()
|
||||
);
|
||||
});
|
||||
|
||||
@@ -47,6 +57,14 @@ describe('compactFromU8a', (): void => {
|
||||
).toEqual([7, new BN('5af3107a4000', 16)]);
|
||||
});
|
||||
|
||||
it('decodes an actual value (Buffer)', (): void => {
|
||||
expect(
|
||||
compactFromU8a(
|
||||
Buffer.from('0b00407a10f35a', 'hex')
|
||||
)
|
||||
).toEqual([7, new BN('5af3107a4000', 16)]);
|
||||
});
|
||||
|
||||
it('decodes an actual value', (): void => {
|
||||
expect(
|
||||
compactFromU8a(
|
||||
@@ -54,4 +72,11 @@ describe('compactFromU8a', (): void => {
|
||||
)[1].toString()
|
||||
).toEqual('100000000');
|
||||
});
|
||||
|
||||
performance('compactFromU8a (u8)', 1_000_000, [[new Uint8Array([63 << 2])]], compactFromU8a);
|
||||
performance('compactFromU8a (u16)', 1_000_000, [[new Uint8Array([0b11111101, 0b00000111])]], compactFromU8a);
|
||||
performance('compactFromU8a (u32)', 1_000_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8a);
|
||||
performance('compactFromU8aLim (u32)', 1_000_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8aLim);
|
||||
performance('compactFromU8a (u48)', 1_000_000, [[hexToU8a('0x0b00407a10f35a')]], compactFromU8a);
|
||||
performance('compactFromU8a (u96)', 250_000, [[new Uint8Array([23, 52, 0x40, 0x7a, 0x10, 0xf3, 0x5a, 0, 0, 18])]], compactFromU8a);
|
||||
});
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
import type { U8aLike } from '../types';
|
||||
|
||||
import { BN, BN_FOUR } from '../bn';
|
||||
import { BN } from '../bn';
|
||||
import { u8aToBn, u8aToU8a } from '../u8a';
|
||||
|
||||
/**
|
||||
* @name compactFromU8a
|
||||
* @description Retrievs the offset and encoded length from a compact-prefixed value
|
||||
* @description Retrives the offset and encoded length from a compact-prefixed value
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
@@ -22,22 +22,86 @@ import { u8aToBn, u8aToU8a } from '../u8a';
|
||||
*/
|
||||
export function compactFromU8a (input: U8aLike): [number, BN] {
|
||||
const u8a = u8aToU8a(input);
|
||||
const flag = u8a[0] & 0b11;
|
||||
|
||||
if (flag === 0b00) {
|
||||
return [1, new BN(u8a[0]).ishrn(2)];
|
||||
} else if (flag === 0b01) {
|
||||
return [2, u8aToBn(u8a.subarray(0, 2), true).ishrn(2)];
|
||||
} else if (flag === 0b10) {
|
||||
return [4, u8aToBn(u8a.subarray(0, 4), true).ishrn(2)];
|
||||
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster
|
||||
// than doing an additional call to u8aToBn (as with variable length)
|
||||
switch (u8a[0] & 0b11) {
|
||||
case 0b00:
|
||||
return [1, new BN(u8a[0] >>> 2)];
|
||||
|
||||
case 0b01:
|
||||
return [2, new BN((u8a[0] + (u8a[1] * 0x1_00)) >>> 2)];
|
||||
|
||||
case 0b10:
|
||||
return [4, new BN((u8a[0] + (u8a[1] * 0x1_00) + (u8a[2] * 0x1_00_00) + (u8a[3] * 0x1_00_00_00)) >>> 2)];
|
||||
|
||||
// 0b11
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const offset = 1 + (
|
||||
new BN(u8a[0])
|
||||
.ishrn(2) // clear flag
|
||||
.iadd(BN_FOUR) // add 4 for base length
|
||||
.toNumber()
|
||||
);
|
||||
// add 5 to shifted (4 for base length, 1 for this byte)
|
||||
const offset = (u8a[0] >>> 2) + 5;
|
||||
|
||||
return [offset, u8aToBn(u8a.subarray(1, offset), true)];
|
||||
// we unroll the loop
|
||||
switch (offset) {
|
||||
// there still could be 4 bytes data, similar to 0b10 above (with offsets)
|
||||
case 5:
|
||||
return [5, new BN(u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00))];
|
||||
|
||||
case 6:
|
||||
return [6, new BN(u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00) + (u8a[5] * 0x1_00_00_00_00))];
|
||||
|
||||
// 6 bytes data is the maximum, 48 bits (56 would overflow)
|
||||
case 7:
|
||||
return [7, new BN(u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00) + (u8a[5] * 0x1_00_00_00_00) + (u8a[6] * 0x1_00_00_00_00_00))];
|
||||
|
||||
// for anything else, use the non-unrolled version
|
||||
default:
|
||||
return [offset, u8aToBn(u8a.subarray(1, offset))];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name compactFromU8aLim
|
||||
* @description A limited version of [[compactFromU8a]], accepting only Uint8Array inputs for values <= 48 bits
|
||||
*/
|
||||
export function compactFromU8aLim (u8a: Uint8Array): [number, number] {
|
||||
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster
|
||||
// than doing an additional call to u8aToBn (as with variable length)
|
||||
switch (u8a[0] & 0b11) {
|
||||
case 0b00:
|
||||
return [1, u8a[0] >>> 2];
|
||||
|
||||
case 0b01:
|
||||
return [2, (u8a[0] + (u8a[1] * 0x1_00)) >>> 2];
|
||||
|
||||
case 0b10:
|
||||
return [4, (u8a[0] + (u8a[1] * 0x1_00) + (u8a[2] * 0x1_00_00) + (u8a[3] * 0x1_00_00_00)) >>> 2];
|
||||
|
||||
// 0b11
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// add 5 to shifted (4 for base length, 1 for this byte)
|
||||
const offset = (u8a[0] >>> 2) + 5;
|
||||
|
||||
// we unroll the loop
|
||||
switch (offset) {
|
||||
// there still could be 4 bytes data, similar to 0b10 above (with offsets)
|
||||
case 5:
|
||||
return [5, u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00)];
|
||||
|
||||
case 6:
|
||||
return [6, u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00) + (u8a[5] * 0x1_00_00_00_00)];
|
||||
|
||||
// 6 bytes data is the maximum, 48 bits (56 would overflow)
|
||||
case 7:
|
||||
return [7, u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00) + (u8a[5] * 0x1_00_00_00_00) + (u8a[6] * 0x1_00_00_00_00_00)];
|
||||
|
||||
// for anything else, use the non-unrolled version
|
||||
default:
|
||||
throw new Error('Compact input is > Number.MAX_SAFE_INTEGER');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@
|
||||
|
||||
export { compactAddLength } from './addLength';
|
||||
export { compactStripLength } from './stripLength';
|
||||
export { compactFromU8a } from './fromU8a';
|
||||
export { compactFromU8a, compactFromU8aLim } from './fromU8a';
|
||||
export { compactToU8a } from './toU8a';
|
||||
|
||||
@@ -61,7 +61,7 @@ describe('encode', (): void => {
|
||||
);
|
||||
});
|
||||
|
||||
it('encodes a large value', (): void => {
|
||||
it('encodes a large value (6 bytes)', (): void => {
|
||||
expect(
|
||||
compactToU8a(
|
||||
new BN('00005af3107a4000', 16)
|
||||
@@ -71,6 +71,16 @@ describe('encode', (): void => {
|
||||
);
|
||||
});
|
||||
|
||||
it('encodes a large value (9 bytes)', (): void => {
|
||||
expect(
|
||||
compactToU8a(
|
||||
new BN('1200005af3107a4034', 16)
|
||||
)
|
||||
).toEqual(
|
||||
new Uint8Array([23, 52, 0x40, 0x7a, 0x10, 0xf3, 0x5a, 0, 0, 18])
|
||||
);
|
||||
});
|
||||
|
||||
it('does not modify the original', (): void => {
|
||||
const original = new BN(123456);
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
import { assert } from '../assert';
|
||||
import { BN, BN_ONE, BN_TWO, bnToBn, bnToU8a } from '../bn';
|
||||
import { u8aConcat } from '../u8a';
|
||||
import { u8aConcatStrict } from '../u8a';
|
||||
|
||||
const MAX_U8 = BN_TWO.pow(new BN(8 - 2)).isub(BN_ONE);
|
||||
const MAX_U16 = BN_TWO.pow(new BN(16 - 2)).isub(BN_ONE);
|
||||
const MAX_U32 = BN_TWO.pow(new BN(32 - 2)).isub(BN_ONE);
|
||||
const BL_16 = { bitLength: 16 };
|
||||
const BL_32 = { bitLength: 32 };
|
||||
|
||||
/**
|
||||
* @name compactToU8a
|
||||
@@ -27,9 +29,9 @@ export function compactToU8a (value: BN | bigint | number): Uint8Array {
|
||||
if (bn.lte(MAX_U8)) {
|
||||
return new Uint8Array([bn.toNumber() << 2]);
|
||||
} else if (bn.lte(MAX_U16)) {
|
||||
return bnToU8a(bn.shln(2).iadd(BN_ONE), 16, true);
|
||||
return bnToU8a(bn.shln(2).iadd(BN_ONE), BL_16);
|
||||
} else if (bn.lte(MAX_U32)) {
|
||||
return bnToU8a(bn.shln(2).iadd(BN_TWO), 32, true);
|
||||
return bnToU8a(bn.shln(2).iadd(BN_TWO), BL_32);
|
||||
}
|
||||
|
||||
const u8a = bnToU8a(bn);
|
||||
@@ -42,9 +44,9 @@ export function compactToU8a (value: BN | bigint | number): Uint8Array {
|
||||
|
||||
assert(length >= 4, 'Invalid length, previous checks match anything less than 2^30');
|
||||
|
||||
return u8aConcat(
|
||||
return u8aConcatStrict([
|
||||
// subtract 4 as minimum (also catered for in decoding)
|
||||
[((length - 4) << 2) + 0b11],
|
||||
new Uint8Array([((length - 4) << 2) + 0b11]),
|
||||
u8a.subarray(0, length)
|
||||
);
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -21,14 +21,33 @@ interface SetDefaults {
|
||||
}
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* @description The number of decimals
|
||||
*/
|
||||
decimals?: number;
|
||||
/**
|
||||
* @description Format the number with this specific unit
|
||||
*/
|
||||
forceUnit?: string;
|
||||
/**
|
||||
* @description Format with SI, i.e. m/M/etc.
|
||||
*/
|
||||
withSi?: boolean;
|
||||
/**
|
||||
* @description Format with full SI, i.e. mili/Mega/etc.
|
||||
*/
|
||||
withSiFull?: boolean;
|
||||
/**
|
||||
* @description Add the unit (useful in Balance formats)
|
||||
*/
|
||||
withUnit?: boolean | string;
|
||||
}
|
||||
|
||||
interface BalanceFormatter {
|
||||
<ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, options?: Options): string;
|
||||
/** @deprecated Use balanceFormat(input?: number | string | BN | bigint | ExtToBn, options?: Options) */
|
||||
<ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, options?: boolean, decimals?: number): string;
|
||||
/** @deprecated Use balanceFormat(input?: number | string | BN | bigint | ExtToBn, options?: Options) */
|
||||
<ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, options?: Options, decimals?: number): string;
|
||||
calcSi (text: string, decimals?: number): SiDef;
|
||||
findSi (type: string): SiDef;
|
||||
|
||||
@@ -9,7 +9,7 @@ export function formatDecimal (value: string): string {
|
||||
// we rather strip and re-add the negative sign in the output
|
||||
const isNegative = value[0].startsWith('-');
|
||||
const matched = isNegative
|
||||
? value.substr(1).match(NUMBER_REGEX)
|
||||
? value.substring(1).match(NUMBER_REGEX)
|
||||
: value.match(NUMBER_REGEX);
|
||||
|
||||
return matched
|
||||
|
||||
@@ -21,7 +21,7 @@ export function hexStripPrefix (value?: string | null): string {
|
||||
if (!value || value === '0x') {
|
||||
return '';
|
||||
} else if (REGEX_HEX_PREFIXED.test(value)) {
|
||||
return value.substr(2);
|
||||
return value.substring(2);
|
||||
} else if (REGEX_HEX_NOPREFIX.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user