Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -1,6 +1,8 @@
|
||||
--test-*
|
||||
_book/
|
||||
build/
|
||||
build-cjs/
|
||||
build-esm/
|
||||
build-docs/
|
||||
coverage/
|
||||
docs/.vuepress/dist/
|
||||
|
||||
@@ -1,5 +1,56 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 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
|
||||
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
1280 Jaco 8.6.1 (#1439)
|
||||
1316 Jaco 9.2.1 (#1489)
|
||||
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)
|
||||
@@ -20,6 +20,7 @@
|
||||
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 Carlo Sala feat(networks): add statemint to KnownLedger (#1467)
|
||||
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)
|
||||
@@ -33,6 +34,7 @@
|
||||
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)
|
||||
@@ -44,4 +46,5 @@
|
||||
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)
|
||||
+5
-5
@@ -10,7 +10,7 @@
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
@@ -27,11 +27,11 @@
|
||||
"test:one": "polkadot-dev-run-test --runInBand"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.17.8",
|
||||
"@polkadot/dev": "^0.65.97",
|
||||
"@types/jest": "^27.4.1"
|
||||
"@babel/core": "^7.17.10",
|
||||
"@polkadot/dev": "^0.66.21",
|
||||
"@types/jest": "^27.5.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"typescript": "^4.6.2"
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@ledgerhq/hw-transport": "^6.24.1",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.24.1",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.24.1",
|
||||
"@polkadot/util": "8.6.1"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.27.1",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.27.1",
|
||||
"@polkadot/util": "9.2.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.26.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.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@ledgerhq/hw-transport": "^6.24.1",
|
||||
"@polkadot/hw-ledger-transports": "8.6.1",
|
||||
"@polkadot/util": "8.6.1",
|
||||
"@zondax/ledger-substrate": "^0.24.0"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@polkadot/hw-ledger-transports": "9.2.1",
|
||||
"@polkadot/util": "9.2.1",
|
||||
"@zondax/ledger-substrate": "^0.27.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,20 +4,24 @@
|
||||
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, newBifrostApp, newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKaruraApp, newKusamaApp, newNodleApp, 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/ledger.ts
|
||||
export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp> = {
|
||||
acala: newAcalaApp,
|
||||
bifrost: newBifrostApp,
|
||||
centrifuge: newCentrifugeApp,
|
||||
'dock-mainnet': newDockApp,
|
||||
edgeware: newEdgewareApp,
|
||||
equilibrium: newEquilibriumApp,
|
||||
genshiro: newGenshiroApp,
|
||||
karura: newKaruraApp,
|
||||
kusama: newKusamaApp,
|
||||
'nodle-chain': newNodleApp,
|
||||
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.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '9.2.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];
|
||||
}
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/util": "8.6.1",
|
||||
"@polkadot/util-crypto": "8.6.1"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/util": "9.2.1",
|
||||
"@polkadot/util-crypto": "9.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "8.6.1",
|
||||
"@polkadot/util-crypto": "8.6.1"
|
||||
"@polkadot/util": "9.2.1",
|
||||
"@polkadot/util-crypto": "9.2.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.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '9.2.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;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/util": "8.6.1",
|
||||
"@substrate/ss58-registry": "^1.17.0"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/util": "9.2.1",
|
||||
"@substrate/ss58-registry": "^1.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/hw-ledger": "8.6.1",
|
||||
"@polkadot/x-fetch": "8.6.1"
|
||||
"@polkadot/hw-ledger": "9.2.1",
|
||||
"@polkadot/x-fetch": "9.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ export const knownGenesis: KnownGenesis = {
|
||||
'0x6fbd74e5e1d0a61d52ccfe9d4adaed16dd3a7caa37c6bc4d0c2fa12e8b2f4063'
|
||||
],
|
||||
rococo: [
|
||||
'0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e',
|
||||
'0xaaf2cd1b74b5f726895921259421b534124726263982522174147046b8827897',
|
||||
'0x037f5f3c8e67b314062025fc886fcd6238ea25a4a9b45dce8d246815c9ebe770',
|
||||
'0xc196f81260cf1686172b47a79cf002120735d7cb0eb1474e8adce56618456fff',
|
||||
@@ -87,10 +88,16 @@ export const knownGenesis: KnownGenesis = {
|
||||
statemine: [
|
||||
'0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a'
|
||||
],
|
||||
statemint: [
|
||||
'0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f'
|
||||
],
|
||||
subsocial: [
|
||||
'0x0bd72c1c305172e1275278aaeb3f161e02eccb7a819e63f62d47bd53a28189f8'
|
||||
],
|
||||
westend: [
|
||||
'0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e'
|
||||
],
|
||||
xxnetwork: [
|
||||
'0x50dd5d206917bf10502c68fb4d18a59fc8aa31586f4e8856b493e43544aa82aa'
|
||||
]
|
||||
};
|
||||
|
||||
@@ -8,16 +8,20 @@ import type { KnownLedger } from '../types';
|
||||
//
|
||||
// NOTE: Any network here needs to have a genesisHash attached in the ./genesis.ts config
|
||||
export const knownLedger: KnownLedger = {
|
||||
acala: 0x00000313,
|
||||
bifrost: 0x00000314,
|
||||
centrifuge: 0x000002eb,
|
||||
'dock-mainnet': 0x00000252,
|
||||
edgeware: 0x0000020b,
|
||||
equilibrium: 0x05f5e0fd,
|
||||
genshiro: 0x05f5e0fc,
|
||||
karura: 0x000002ae,
|
||||
kusama: 0x000001b2,
|
||||
'nodle-chain': 0x000003eb,
|
||||
polkadot: 0x00000162,
|
||||
polymesh: 0x00000253,
|
||||
sora: 0x00000269,
|
||||
statemine: 0x000001b2 // common-good on Kusama, shares derivation
|
||||
statemine: 0x000001b2, // common-good on Kusama, shares derivation
|
||||
statemint: 0x00000162, // common-good on Polkadot, shares derivation
|
||||
xxnetwork: 0x000007a3
|
||||
};
|
||||
|
||||
@@ -113,6 +113,6 @@ describe('selectableNetworks', (): void => {
|
||||
|
||||
it('has a sorted list (first external, last external)', (): void => {
|
||||
expect(selectableNetworks[3].displayName).toEqual('Acala');
|
||||
expect(selectableNetworks[selectableNetworks.length - 1].displayName).toEqual('Stafi');
|
||||
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,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -245,22 +245,9 @@
|
||||
"standardAccount": "*25519",
|
||||
"website": "https://stafi.io"
|
||||
},
|
||||
{
|
||||
"prefix": 21,
|
||||
"network": "dock-testnet",
|
||||
"displayName": "Dock Testnet",
|
||||
"symbols": [
|
||||
"DCK"
|
||||
],
|
||||
"decimals": [
|
||||
6
|
||||
],
|
||||
"standardAccount": "*25519",
|
||||
"website": "https://dock.io"
|
||||
},
|
||||
{
|
||||
"prefix": 22,
|
||||
"network": "dock-mainnet",
|
||||
"network": "dock-pos-mainnet",
|
||||
"displayName": "Dock Mainnet",
|
||||
"symbols": [
|
||||
"DCK"
|
||||
@@ -459,12 +446,12 @@
|
||||
{
|
||||
"prefix": 38,
|
||||
"network": "kilt",
|
||||
"displayName": "KILT Chain",
|
||||
"displayName": "KILT Spiritnet",
|
||||
"symbols": [
|
||||
"KILT"
|
||||
],
|
||||
"decimals": [
|
||||
18
|
||||
15
|
||||
],
|
||||
"standardAccount": "*25519",
|
||||
"website": "https://kilt.io/"
|
||||
@@ -824,13 +811,13 @@
|
||||
"network": "origintrail-parachain",
|
||||
"displayName": "OriginTrail Parachain",
|
||||
"symbols": [
|
||||
"TRAC"
|
||||
"OTP"
|
||||
],
|
||||
"decimals": [
|
||||
18
|
||||
12
|
||||
],
|
||||
"standardAccount": "secp256k1",
|
||||
"website": "https://origintrail.io"
|
||||
"standardAccount": "*25519",
|
||||
"website": "https://parachain.origintrail.io/"
|
||||
},
|
||||
{
|
||||
"prefix": 105,
|
||||
@@ -1024,7 +1011,7 @@
|
||||
"website": "https://moonbeam.network"
|
||||
},
|
||||
{
|
||||
"prefix": 1337,
|
||||
"prefix": 1328,
|
||||
"network": "ajuna",
|
||||
"displayName": "Ajuna Network",
|
||||
"symbols": [
|
||||
@@ -1033,7 +1020,20 @@
|
||||
"decimals": [
|
||||
12
|
||||
],
|
||||
"standardAccount": "Sr25519",
|
||||
"standardAccount": "*25519",
|
||||
"website": "https://ajuna.io"
|
||||
},
|
||||
{
|
||||
"prefix": 1337,
|
||||
"network": "bajun",
|
||||
"displayName": "Bajun Network",
|
||||
"symbols": [
|
||||
"BAJU"
|
||||
],
|
||||
"decimals": [
|
||||
12
|
||||
],
|
||||
"standardAccount": "*25519",
|
||||
"website": "https://ajuna.io"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -16,27 +16,27 @@
|
||||
"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.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": {
|
||||
"crypto": false,
|
||||
"stream": false
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@noble/hashes": "1.0.0",
|
||||
"@noble/secp256k1": "1.5.5",
|
||||
"@polkadot/networks": "8.6.1",
|
||||
"@polkadot/util": "8.6.1",
|
||||
"@polkadot/wasm-crypto": "^5.0.1",
|
||||
"@polkadot/x-bigint": "8.6.1",
|
||||
"@polkadot/x-randomvalues": "8.6.1",
|
||||
"@polkadot/networks": "9.2.1",
|
||||
"@polkadot/util": "9.2.1",
|
||||
"@polkadot/wasm-crypto": "^6.1.1",
|
||||
"@polkadot/x-bigint": "9.2.1",
|
||||
"@polkadot/x-randomvalues": "9.2.1",
|
||||
"@scure/base": "1.0.0",
|
||||
"ed2curve": "^0.3.0",
|
||||
"tweetnacl": "^1.0.3"
|
||||
@@ -45,6 +45,6 @@
|
||||
"@types/ed2curve": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "8.6.1"
|
||||
"@polkadot/util": "9.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 './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
|
||||
});
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -34,19 +34,19 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-bigint": "8.6.1",
|
||||
"@polkadot/x-global": "8.6.1",
|
||||
"@polkadot/x-textdecoder": "8.6.1",
|
||||
"@polkadot/x-textencoder": "8.6.1",
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-bigint": "9.2.1",
|
||||
"@polkadot/x-global": "9.2.1",
|
||||
"@polkadot/x-textdecoder": "9.2.1",
|
||||
"@polkadot/x-textencoder": "9.2.1",
|
||||
"@types/bn.js": "^5.1.0",
|
||||
"bn.js": "^5.2.0",
|
||||
"ip-regex": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/x-randomvalues": "8.6.1"
|
||||
"@polkadot/x-randomvalues": "9.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import { BN } from '../bn/bn';
|
||||
import { hexToU8a } from '../hex/toU8a';
|
||||
import { performance } from '../test/performance';
|
||||
import { compactFromU8a } from '.';
|
||||
|
||||
describe('compactFromU8a', (): 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()
|
||||
);
|
||||
});
|
||||
|
||||
@@ -54,4 +64,9 @@ describe('compactFromU8a', (): void => {
|
||||
)[1].toString()
|
||||
).toEqual('100000000');
|
||||
});
|
||||
|
||||
performance('compactFromU8a (u8)', 500_000, [[new Uint8Array([63 << 2])]], compactFromU8a);
|
||||
performance('compactFromU8a (u16)', 500_000, [[new Uint8Array([0b11111101, 0b00000111])]], compactFromU8a);
|
||||
performance('compactFromU8a (u32)', 500_000, [[new Uint8Array([254, 255, 3, 0])]], compactFromU8a);
|
||||
performance('compactFromU8a (u64)', 500_000, [[hexToU8a('0x0b00407a10f35a')]], 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>
|
||||
*
|
||||
@@ -24,20 +24,18 @@ export function compactFromU8a (input: U8aLike): [number, BN] {
|
||||
const u8a = u8aToU8a(input);
|
||||
const flag = u8a[0] & 0b11;
|
||||
|
||||
// The u8a is manually converted here, it is 2x faster that doing an
|
||||
// additional call to u8aToBn
|
||||
if (flag === 0b00) {
|
||||
return [1, new BN(u8a[0]).ishrn(2)];
|
||||
return [1, new BN(u8a[0] >>> 2)];
|
||||
} else if (flag === 0b01) {
|
||||
return [2, u8aToBn(u8a.subarray(0, 2), true).ishrn(2)];
|
||||
return [2, new BN((u8a[0] + (u8a[1] * 0x1_00)) >>> 2)];
|
||||
} else if (flag === 0b10) {
|
||||
return [4, u8aToBn(u8a.subarray(0, 4), true).ishrn(2)];
|
||||
return [4, new BN((u8a[0] + (u8a[1] * 0x1_00) + (u8a[2] * 0x1_00_00) + (u8a[3] * 0x1_00_00_00)) >>> 2)];
|
||||
}
|
||||
|
||||
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)];
|
||||
return [offset, u8aToBn(u8a.subarray(1, offset))];
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import { u8aConcat } 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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('hexToBn', (): void => {
|
||||
).toBe(256);
|
||||
});
|
||||
|
||||
it('handles backwards compatibility', (): void => {
|
||||
it('handles legacy compatibility', (): void => {
|
||||
expect(
|
||||
hexToBn('0x0001000000000000', false).eq(
|
||||
hexToBn('0x0001000000000000', { isLe: false })
|
||||
|
||||
@@ -8,8 +8,6 @@ import { isBoolean } from '../is/boolean';
|
||||
import { objectSpread } from '../object/spread';
|
||||
import { hexStripPrefix } from './stripPrefix';
|
||||
|
||||
const DEFAULT_OPTS: ToBnOptions = { isLe: false, isNegative: false };
|
||||
|
||||
/**
|
||||
* @name hexToBn
|
||||
* @summary Creates a BN.js object from a hex string.
|
||||
@@ -28,12 +26,17 @@ const DEFAULT_OPTS: ToBnOptions = { isLe: false, isNegative: false };
|
||||
* hexToBn('0x123480001f'); // => BN(0x123480001f)
|
||||
* ```
|
||||
*/
|
||||
export function hexToBn (value?: string | null, options: ToBnOptions | boolean = DEFAULT_OPTS): BN {
|
||||
function hexToBn (value?: string | null, options?: ToBnOptions): BN;
|
||||
/** @deprecated Use hexToBn (value?: string | null, options?: ToBnOptions) */
|
||||
function hexToBn (value?: string | null, options?: boolean): BN;
|
||||
/** @deprecated Use hexToBn (value?: string | null, options?: ToBnOptions) */
|
||||
function hexToBn (value?: string | null, options: ToBnOptions | boolean = {}): BN {
|
||||
if (!value || value === '0x') {
|
||||
return new BN(0);
|
||||
}
|
||||
|
||||
const { isLe, isNegative }: ToBnOptions = objectSpread(
|
||||
// For hex, default to BE
|
||||
const { isLe, isNegative } = objectSpread<ToBnOptions>(
|
||||
{ isLe: false, isNegative: false },
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
@@ -43,8 +46,10 @@ export function hexToBn (value?: string | null, options: ToBnOptions | boolean =
|
||||
const bn = new BN(stripped, 16, isLe ? 'le' : 'be');
|
||||
|
||||
// fromTwos takes as parameter the number of bits, which is the hex length
|
||||
// multiplied by 4.
|
||||
// multiplied by 4 (2 bytes being 8 bits)
|
||||
return isNegative
|
||||
? bn.fromTwos(stripped.length * 4)
|
||||
: bn;
|
||||
}
|
||||
|
||||
export { hexToBn };
|
||||
|
||||
@@ -42,11 +42,13 @@ export function hexToU8a (_value?: HexString | string | null, bitLength = -1): U
|
||||
const length = endLength - offset - mod;
|
||||
|
||||
for (let i = 0; i < length; i += 2) {
|
||||
dv.setUint16(i, HEX_TO_U16[value.substr(i * 2, 4)]);
|
||||
const idx = i * 2;
|
||||
|
||||
dv.setUint16(i, HEX_TO_U16[value.substring(idx, idx + 4)]);
|
||||
}
|
||||
|
||||
if (mod) {
|
||||
dv.setUint8(length, HEX_TO_U8[value.substr(value.length - 2, 2)]);
|
||||
dv.setUint8(length, HEX_TO_U8[value.substring(value.length - 2)]);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { isHex } from '.';
|
||||
|
||||
describe('isHex', (): void => {
|
||||
const test = '1234abcd';
|
||||
const ptest = '0x1234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef11234adbcdef5798351773526352876adbcdef2358735adbcdef2623587adbcdef1';
|
||||
const ptest = `0x${'1234567890abcdef'.repeat(8192)}`;
|
||||
|
||||
it('returns true on 0x hex values', (): void => {
|
||||
expect(
|
||||
@@ -71,5 +71,5 @@ describe('isHex', (): void => {
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
performance('isHex (1024-bit)', 1000000, [[ptest]], isHex);
|
||||
performance(`isHex (${(ptest.length - 2) / 2} bytes)`, 5000, [[ptest]], isHex);
|
||||
});
|
||||
|
||||
@@ -59,7 +59,7 @@ function formatWithLength (maxLength: number): (v: unknown) => unknown {
|
||||
|
||||
return r.length < maxLength
|
||||
? v
|
||||
: `${r.substr(0, maxLength)} ...`;
|
||||
: `${r.substring(0, maxLength)} ...`;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/util', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -20,5 +20,5 @@ import type { AnyString } from '../types';
|
||||
export function stringShorten (value: AnyString, prefixLength = 6): string {
|
||||
return value.length <= 2 + 2 * prefixLength
|
||||
? value.toString()
|
||||
: `${value.substr(0, prefixLength)}…${value.slice(-prefixLength)}`;
|
||||
: `${value.substring(0, prefixLength)}…${value.slice(-prefixLength)}`;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,23 @@ export interface Logger {
|
||||
}
|
||||
|
||||
export interface ToBnOptions {
|
||||
/**
|
||||
* @description Convert in LE format
|
||||
*/
|
||||
isLe?: boolean;
|
||||
/**
|
||||
* @description Number is negative, apply two's complement
|
||||
*/
|
||||
isNegative?: boolean;
|
||||
}
|
||||
|
||||
export interface NumberOptions extends ToBnOptions {
|
||||
/**
|
||||
* @description Limit to the specified bitLength, despite input length
|
||||
*/
|
||||
bitLength?: number;
|
||||
}
|
||||
|
||||
export type BnList = {
|
||||
0: BN;
|
||||
1: BN;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
import { u8aToBigInt } from '.';
|
||||
|
||||
describe('u8aToBigInt', (): void => {
|
||||
@@ -42,10 +43,10 @@ describe('u8aToBigInt', (): void => {
|
||||
it('handles negative numbers (little-endian)', (): void => {
|
||||
expect(
|
||||
u8aToBigInt(
|
||||
new Uint8Array([46, 251]),
|
||||
new Uint8Array([192, 29, 254]),
|
||||
{ isLe: true, isNegative: true }
|
||||
)
|
||||
).toEqual(-1234n);
|
||||
).toEqual(-123456n);
|
||||
});
|
||||
|
||||
it('handles negative numbers (big-endian)', (): void => {
|
||||
@@ -56,4 +57,6 @@ describe('u8aToBigInt', (): void => {
|
||||
)
|
||||
).toEqual(-1234n);
|
||||
});
|
||||
|
||||
performance('u8aToBigInt', 500000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToBigInt);
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ export function u8aToBigInt (value: Uint8Array, options: ToBnOptions = {}): bigi
|
||||
return BigInt(0);
|
||||
}
|
||||
|
||||
const { isLe, isNegative }: ToBnOptions = objectSpread({ isLe: true, isNegative: false }, options);
|
||||
const { isLe, isNegative } = objectSpread<ToBnOptions>({ isLe: true, isNegative: false }, options);
|
||||
const u8a = isLe
|
||||
? value.reverse()
|
||||
: value;
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
import { u8aToBn } from '.';
|
||||
|
||||
describe('u8aToBn', (): void => {
|
||||
it('supports legacy compatibility', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array([0x12, 0x34]),
|
||||
true
|
||||
).toString(16)
|
||||
).toBe('3412');
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array([0x12, 0x34]),
|
||||
false
|
||||
).toString(16)
|
||||
).toBe('1234');
|
||||
});
|
||||
|
||||
it('converts little-endian by default', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
@@ -11,6 +27,7 @@ describe('u8aToBn', (): void => {
|
||||
).toString(16)
|
||||
).toBe('3412');
|
||||
});
|
||||
|
||||
it('converts values (big-endian)', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
@@ -29,13 +46,42 @@ describe('u8aToBn', (): void => {
|
||||
).toBe('3412');
|
||||
});
|
||||
|
||||
it('converts empty', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array(),
|
||||
{ isLe: true }
|
||||
).toString(16)
|
||||
).toBe('0');
|
||||
describe('empty creation', (): void => {
|
||||
it('handles unsigned (le)', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array(),
|
||||
{ isLe: true }
|
||||
).toString(16)
|
||||
).toBe('0');
|
||||
});
|
||||
|
||||
it('handles signed (le)', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array(),
|
||||
{ isLe: true, isNegative: true }
|
||||
).toString(16)
|
||||
).toBe('0');
|
||||
});
|
||||
|
||||
it('handles unsigned (be)', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array(),
|
||||
{ isLe: false }
|
||||
).toString(16)
|
||||
).toBe('0');
|
||||
});
|
||||
|
||||
it('handles signed (be)', (): void => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array(),
|
||||
{ isLe: false, isNegative: true }
|
||||
).toString(16)
|
||||
).toBe('0');
|
||||
});
|
||||
});
|
||||
|
||||
it('handles negative numbers (little-endian)', (): void => {
|
||||
@@ -89,4 +135,6 @@ describe('u8aToBn', (): void => {
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
performance('u8aToBn', 500000, [[new Uint8Array([0x68, 0x65, 0x6c, 0x6c])]], u8aToBn);
|
||||
});
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '../bn/bn';
|
||||
import type { ToBnOptions } from '../types';
|
||||
|
||||
import { hexToBn } from '../hex/toBn';
|
||||
import { u8aToHex } from './toHex';
|
||||
|
||||
const DEFAULT_OPTS: ToBnOptions = { isLe: true, isNegative: false };
|
||||
import { BN } from '../bn/bn';
|
||||
import { isBoolean } from '../is/boolean';
|
||||
import { objectSpread } from '../object/spread';
|
||||
|
||||
/**
|
||||
* @name u8aToBn
|
||||
@@ -16,7 +14,7 @@ const DEFAULT_OPTS: ToBnOptions = { isLe: true, isNegative: false };
|
||||
* `UInt8Array` input values return the actual BN. `null` or `undefined` values returns an `0x0` value.
|
||||
* @param value The value to convert
|
||||
* @param options Options to pass while converting
|
||||
* @param options.isLe Convert using Little Endian
|
||||
* @param options.isLe Convert using Little Endian (default)
|
||||
* @param options.isNegative Convert using two's complement
|
||||
* @example
|
||||
* <BR>
|
||||
@@ -27,9 +25,24 @@ const DEFAULT_OPTS: ToBnOptions = { isLe: true, isNegative: false };
|
||||
* u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
* ```
|
||||
*/
|
||||
export function u8aToBn (value: Uint8Array, options: ToBnOptions | boolean = DEFAULT_OPTS): BN {
|
||||
return hexToBn(
|
||||
u8aToHex(value),
|
||||
options
|
||||
function u8aToBn (value: Uint8Array, options?: ToBnOptions): BN;
|
||||
/** @deprecated Use u8aToBn(value: Uint8Array, options?: ToBnOptions) */
|
||||
function u8aToBn (value: Uint8Array, options?: boolean): BN;
|
||||
/** @deprecated Use hexToBn (value?: string | null, options?: ToBnOptions) */
|
||||
function u8aToBn (value: Uint8Array, options: ToBnOptions | boolean = {}): BN {
|
||||
// NOTE: This is the same process as followed in the hexToBn conversion
|
||||
// For Uint8Array, default to LE
|
||||
const { isLe, isNegative } = objectSpread<ToBnOptions>(
|
||||
{ isLe: true, isNegative: false },
|
||||
isBoolean(options)
|
||||
? { isLe: options }
|
||||
: options
|
||||
);
|
||||
const bn = new BN(value, isLe ? 'le' : 'be');
|
||||
|
||||
return isNegative && value.length
|
||||
? bn.fromTwos(value.length * 8)
|
||||
: bn;
|
||||
}
|
||||
|
||||
export { u8aToBn };
|
||||
|
||||
@@ -25,13 +25,13 @@ import { stringToU8a } from '../string/toU8a';
|
||||
* ```
|
||||
*/
|
||||
export function u8aToU8a (value?: U8aLike | null): Uint8Array {
|
||||
return !value
|
||||
? new Uint8Array()
|
||||
: Array.isArray(value) || isBuffer(value)
|
||||
return value
|
||||
? Array.isArray(value) || isBuffer(value)
|
||||
? new Uint8Array(value)
|
||||
: isU8a(value)
|
||||
? value
|
||||
: isHex(value)
|
||||
? hexToU8a(value)
|
||||
: stringToU8a(value);
|
||||
: stringToU8a(value)
|
||||
: new Uint8Array();
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ describe('detectPackage', (): void => {
|
||||
const MISMATCH = `@polkadot/util has multiple versions, ensure that there is only one installed.
|
||||
Either remove and explicitly install matching versions or dedupe using your package manager.
|
||||
The following conflicting packages were found:
|
||||
\t ${VER1}\t${PATH}/01
|
||||
\tesm ${VER2} \tpath/02`;
|
||||
\t ${VER1}\tnode_modules/@polkadot/util
|
||||
\tesm ${VER2} \tnode_modules/@polkadot/api/node_modules/@polkadot/util`;
|
||||
|
||||
it('should not log the first time', (): void => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
detectPackage({ name: PKG, version: VER1 }, `${PATH}/01`);
|
||||
detectPackage({ name: PKG, version: VER1 }, PATH);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
spy.mockRestore();
|
||||
});
|
||||
@@ -27,7 +27,7 @@ The following conflicting packages were found:
|
||||
it('should log the second time', (): void => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
detectPackage({ name: PKG, path: 'path/02', type: 'esm', version: VER2 });
|
||||
detectPackage({ name: PKG, path: '/Users/jaco/Projects/polkadot-js/api/node_modules/@polkadot/api/node_modules/@polkadot/util', type: 'esm', version: VER2 });
|
||||
expect(spy).toHaveBeenCalledWith(MISMATCH);
|
||||
spy.mockRestore();
|
||||
});
|
||||
@@ -35,9 +35,9 @@ The following conflicting packages were found:
|
||||
it('should allow for function use', (): void => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
detectPackage({ name: PKG, type: 'cjs', version: VER3 }, () => `${PATH}/03`);
|
||||
detectPackage({ name: PKG, type: 'cjs', version: VER3 }, () => PATH);
|
||||
expect(spy).toHaveBeenCalledWith(`${MISMATCH}
|
||||
\tcjs ${VER3} \t${PATH}/03`);
|
||||
\tcjs ${VER3} \tnode_modules/@polkadot/util`);
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import { xglobal } from '@polkadot/x-global';
|
||||
|
||||
import { isFunction } from './is/function';
|
||||
import { isString } from './is/string';
|
||||
import { assert } from './assert';
|
||||
|
||||
type This = typeof globalThis;
|
||||
@@ -26,14 +25,14 @@ interface PjsChecks extends This {
|
||||
__polkadotjs: Record<string, VersionPath[]>;
|
||||
}
|
||||
|
||||
type PjsWindow = (Window & This) & PjsChecks;
|
||||
type PjsGlobal = (Window & This) & PjsChecks;
|
||||
type FnString = () => string | undefined;
|
||||
|
||||
const DEDUPE = 'Either remove and explicitly install matching versions or dedupe using your package manager.\nThe following conflicting packages were found:';
|
||||
|
||||
/** @internal */
|
||||
function getEntry (name: string): VersionPath[] {
|
||||
const _global = xglobal as PjsWindow;
|
||||
const _global = xglobal as PjsGlobal;
|
||||
|
||||
if (!_global.__polkadotjs) {
|
||||
_global.__polkadotjs = {};
|
||||
@@ -46,37 +45,45 @@ function getEntry (name: string): VersionPath[] {
|
||||
return _global.__polkadotjs[name];
|
||||
}
|
||||
|
||||
function getVersionLength (all: { version: string }[]): number {
|
||||
let length = 0;
|
||||
/** @internal */
|
||||
function formatDisplay <T extends { version: string }> (all: T[], fmt: (version: string, data: T) => string[]): string {
|
||||
let max = 0;
|
||||
|
||||
for (const { version } of all) {
|
||||
length = Math.max(length, version.length);
|
||||
for (let i = 0; i < all.length; i++) {
|
||||
max = Math.max(max, all[i].version.length);
|
||||
}
|
||||
|
||||
return length;
|
||||
return all
|
||||
.map((d) => `\t${fmt(d.version.padEnd(max), d).join('\t')}`)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function flattenInfos (all: PackageJson[]): string {
|
||||
const verLength = getVersionLength(all);
|
||||
const stringify = ({ name, version }: PackageJson) =>
|
||||
`\t${version.padEnd(verLength)}\t${name}`;
|
||||
|
||||
return all.map(stringify).join('\n');
|
||||
function formatInfo (version: string, { name }: PackageJson): string[] {
|
||||
return [
|
||||
version,
|
||||
name
|
||||
];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function flattenVersions (entry: VersionPath[]): string {
|
||||
const toPath = (version: VersionPath | string): VersionPath =>
|
||||
isString(version)
|
||||
? { version }
|
||||
: version;
|
||||
const all = entry.map(toPath);
|
||||
const verLength = getVersionLength(all);
|
||||
const stringify = ({ path, type, version }: VersionPath) =>
|
||||
`\t${`${type || ''}`.padStart(3)} ${version.padEnd(verLength)}\t${(!path || path.length < 5) ? '<unknown>' : path}`;
|
||||
function formatVersion (version: string, { path, type }: VersionPath): string[] {
|
||||
let extracted: string;
|
||||
|
||||
return all.map(stringify).join('\n');
|
||||
if (path && path.length >= 5) {
|
||||
const nmIndex = path.indexOf('node_modules');
|
||||
|
||||
extracted = nmIndex === -1
|
||||
? path
|
||||
: path.substring(nmIndex);
|
||||
} else {
|
||||
extracted = '<unknown>';
|
||||
}
|
||||
|
||||
return [
|
||||
`${`${type || ''}`.padStart(3)} ${version}`,
|
||||
extracted
|
||||
];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@@ -94,6 +101,11 @@ function getPath (infoPath?: string, pathOrFn?: FnString | string | false | null
|
||||
return pathOrFn || '';
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function warn <T extends { version: string }> (pre: string, all: T[], fmt: (version: string, data: T) => string[]): void {
|
||||
console.warn(`${pre}\n${DEDUPE}\n${formatDisplay(all, fmt)}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name detectPackage
|
||||
* @summary Checks that a specific package is only imported once
|
||||
@@ -107,12 +119,12 @@ export function detectPackage ({ name, path, type, version }: PackageJson, pathO
|
||||
entry.push({ path: getPath(path, pathOrFn), type, version });
|
||||
|
||||
if (entry.length !== 1) {
|
||||
console.warn(`${name} has multiple versions, ensure that there is only one installed.\n${DEDUPE}\n${flattenVersions(entry)}`);
|
||||
warn(`${name} has multiple versions, ensure that there is only one installed.`, entry, formatVersion);
|
||||
} else {
|
||||
const mismatches = deps.filter((d) => d && d.version !== version);
|
||||
|
||||
if (mismatches.length) {
|
||||
console.warn(`${name} requires direct dependencies exactly matching version ${version}.\n${DEDUPE}\n${flattenInfos(mismatches)}`);
|
||||
warn(`${name} requires direct dependencies exactly matching version ${version}.`, mismatches, formatInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
"./shim.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-global": "8.6.1"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-global": "9.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-bigint', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bigint', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/util": "8.6.1",
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/util": "9.2.1",
|
||||
"buffer-es6": "^4.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-bundle', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-global": "8.6.1",
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-global": "9.2.1",
|
||||
"@types/node-fetch": "^2.6.1",
|
||||
"node-fetch": "^2.6.7"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-fetch', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8"
|
||||
"@babel/runtime": "^7.17.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-global', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-global', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-global": "8.6.1"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-global": "9.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-native": "^0.67.3"
|
||||
"@types/react-native": "^0.67.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-randomvalues', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-global": "8.6.1"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-global": "9.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textdecoder', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-global": "8.6.1"
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-global": "9.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-textencoder', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.6.1",
|
||||
"version": "9.2.1",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.17.8",
|
||||
"@polkadot/x-global": "8.6.1",
|
||||
"@babel/runtime": "^7.17.9",
|
||||
"@polkadot/x-global": "9.2.1",
|
||||
"@types/websocket": "^1.0.5",
|
||||
"websocket": "^1.0.34"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/x-ws', path: 'auto', type: 'auto', version: '8.6.1' };
|
||||
export const packageInfo = { name: '@polkadot/x-ws', path: 'auto', type: 'auto', version: '9.2.1' };
|
||||
|
||||
Reference in New Issue
Block a user