Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bff05aad32 | ||
|
|
0f98c1ac22 | ||
|
|
f72d9a2a26 | ||
|
|
1d0558a537 | ||
|
|
94e7c05573 | ||
|
|
12601805b1 | ||
|
|
9194f417fe | ||
|
|
6a3118e66c | ||
|
|
4ccad202c5 | ||
|
|
96a019f6eb | ||
|
|
bad6a1b991 | ||
|
|
d83e50ee19 | ||
|
|
feae08fc0f | ||
|
|
fdd32df12f | ||
|
|
17a9b653ac | ||
|
|
6154454c38 | ||
|
|
ac0ec5be55 | ||
|
|
3802426046 | ||
|
|
d91b27b180 | ||
|
|
1f9a1a5f8a | ||
|
|
6b3edffe55 | ||
|
|
7d46eb8423 | ||
|
|
a7eb0ed319 | ||
|
|
227a34d55d | ||
|
|
8a29dc2b57 | ||
|
|
88d1a71df8 | ||
|
|
6f53068297 | ||
|
|
5bf71dab41 | ||
|
|
b6f3dfb2ca | ||
|
|
4d3a2d9610 | ||
|
|
7eaf013572 | ||
|
|
c673b96963 | ||
|
|
c57eee5027 | ||
|
|
9efd2db377 | ||
|
|
c90246ec0b | ||
|
|
fbe1532f62 | ||
|
|
f514402b15 | ||
|
|
5ea6992704 | ||
|
|
7955022ce5 | ||
|
|
000d097de2 | ||
|
|
8a6c8b64df | ||
|
|
306e503d23 | ||
|
|
648019f9d4 | ||
|
|
5e48cfbbaa | ||
|
|
57825fc73b | ||
|
|
19ae016723 | ||
|
|
8d7bed5865 | ||
|
|
e019a3043a | ||
|
|
9dfd013755 | ||
|
|
a5df4ed764 | ||
|
|
a938a9f998 | ||
|
|
1a6f81e2a7 | ||
|
|
6ab85a42bb | ||
|
|
21c9e1aefd | ||
|
|
58f740f3de | ||
|
|
ddc6b83e96 | ||
|
|
285e595930 | ||
|
|
dce16d59e6 | ||
|
|
b8edcb0e65 | ||
|
|
b63607c4a0 | ||
|
|
c56c86432a | ||
|
|
e52fe9a838 | ||
|
|
06dca3d955 | ||
|
|
0908dbb861 | ||
|
|
e97410df52 | ||
|
|
faa6734329 | ||
|
|
f2f25815c1 |
+2
-1
@@ -24,4 +24,5 @@
|
||||
8.0.3
|
||||
8.0.4
|
||||
8.0.5
|
||||
8.1.2
|
||||
8.1.2
|
||||
8.2.2
|
||||
@@ -1,3 +1,17 @@
|
||||
checks:
|
||||
argument-count:
|
||||
config:
|
||||
threshold: 5
|
||||
method-complexity:
|
||||
config:
|
||||
threshold: 7
|
||||
method-count:
|
||||
config:
|
||||
threshold: 25
|
||||
method-lines:
|
||||
config:
|
||||
threshold: 30
|
||||
|
||||
exclude_patterns:
|
||||
- "**/*.spec.js"
|
||||
- "**/*.spec.ts"
|
||||
|
||||
+2
-8
@@ -6,18 +6,12 @@ const base = require('@polkadot/dev/config/eslint.cjs');
|
||||
module.exports = {
|
||||
...base,
|
||||
ignorePatterns: [
|
||||
'.eslintrc.js',
|
||||
'.github/**',
|
||||
'.vscode/**',
|
||||
'.yarn/**',
|
||||
'**/build/*',
|
||||
'**/coverage/*',
|
||||
'**/node_modules/*'
|
||||
...base.ignorePatterns
|
||||
],
|
||||
parserOptions: {
|
||||
...base.parserOptions,
|
||||
project: [
|
||||
'./tsconfig.json'
|
||||
'./tsconfig.eslint.json'
|
||||
]
|
||||
},
|
||||
rules: {
|
||||
|
||||
+3
-2
@@ -11,7 +11,9 @@ tmp/
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.idea
|
||||
.npmrc
|
||||
.vscode
|
||||
.yarn/*
|
||||
!.yarn/releases
|
||||
!.yarn/plugins
|
||||
@@ -24,5 +26,4 @@ yarn-debug.log*
|
||||
yarn-error.log*
|
||||
store.db
|
||||
store.db.compacted
|
||||
.idea
|
||||
.vscode
|
||||
tsconfig.*buildinfo
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 8.2.2 Dec 19, 2021
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add Bifrost Ledger capabilities (Thanks to https://github.com/awesomepan)
|
||||
- Add Sora genesisHash & Ledger capabilities (Thanks to https://github.com/NoodleSploder)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `isPromise` check utility function
|
||||
- Add `assertUnreachable` for codepaths that should not be followed
|
||||
- Preserve all-caps word splits in `stringCamelCase`
|
||||
- Adjust `x-*` fallbacks via `x-global/extractGlobal`
|
||||
- Sync with upstream Substrate ss58 registry
|
||||
- Additional tests for `bip39` wordlists
|
||||
- Maintainability cleanups
|
||||
- Update to latest Ledger dependencies
|
||||
- Swap to upstream `@noble` packages
|
||||
- Adjust tsconfig with references
|
||||
- 8.2.2 (8.2.1 failed CI due to incorrect CHANGELOG)
|
||||
|
||||
|
||||
## 8.1.2 Dec 5, 2021
|
||||
|
||||
Changes:
|
||||
|
||||
+1
-2
@@ -14,7 +14,6 @@ module.exports = Object.assign({}, config, {
|
||||
// eslint-disable-next-line sort-keys
|
||||
'@polkadot/util(.*)$': '<rootDir>/packages/util/src/$1',
|
||||
'@polkadot/x-(bigint|global)(.*)$': '<rootDir>/packages/x-$1/src/$2',
|
||||
'@polkadot/x-(fetch|randomvalues|textdecoder|textencoder|ws)(.*)$': '<rootDir>/packages/x-$1/src/node',
|
||||
'@polkadot/x-noble-(hashes|secp256k1)(.*)$': '<rootDir>/packages/x-noble-$1/src/$2'
|
||||
'@polkadot/x-(fetch|randomvalues|textdecoder|textencoder|ws)(.*)$': '<rootDir>/packages/x-$1/src/node'
|
||||
}
|
||||
});
|
||||
|
||||
+5
-5
@@ -10,7 +10,7 @@
|
||||
"url": "https://github.com/polkadot-js/common.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
@@ -28,12 +28,12 @@
|
||||
"test:one": "polkadot-dev-run-test --runInBand"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.16.0",
|
||||
"@polkadot/dev": "^0.63.35",
|
||||
"@polkadot/ts": "^0.4.16",
|
||||
"@babel/core": "^7.16.5",
|
||||
"@polkadot/dev": "^0.64.5",
|
||||
"@polkadot/ts": "^0.4.20",
|
||||
"@types/jest": "^27.0.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"typescript": "^4.5.2"
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@ledgerhq/hw-transport": "^6.11.2",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.11.2",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.11.2"
|
||||
"@babel/runtime": "^7.16.5",
|
||||
"@ledgerhq/hw-transport": "^6.20.0",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.20.0",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.20.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.11.2"
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.20.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '8.1.2' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger-transports', version: '8.2.2' };
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": []
|
||||
}
|
||||
@@ -19,12 +19,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/hw-ledger-transports": "8.1.2",
|
||||
"@polkadot/util": "8.1.2",
|
||||
"@zondax/ledger-substrate": "^0.18.0"
|
||||
"@babel/runtime": "^7.16.5",
|
||||
"@polkadot/hw-ledger-transports": "8.2.2",
|
||||
"@polkadot/util": "8.2.2",
|
||||
"@zondax/ledger-substrate": "^0.23.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/hw-ledger authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { knownLedger } from '@polkadot/networks/defaults';
|
||||
|
||||
import { ledgerApps } from './defaults';
|
||||
|
||||
describe('defaults', (): void => {
|
||||
it('has entries for each of the apps (hwledger -> networks)', (): void => {
|
||||
expect(
|
||||
Object.keys(knownLedger).filter((network) =>
|
||||
!ledgerApps[network]
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('has entries for each of the apps (networks -> hwledger)', (): void => {
|
||||
expect(
|
||||
Object.keys(ledgerApps).filter((network) =>
|
||||
!knownLedger[network]
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -4,10 +4,11 @@
|
||||
import type Transport from '@ledgerhq/hw-transport';
|
||||
import type { SubstrateApp } from '@zondax/ledger-substrate';
|
||||
|
||||
import { newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newStatemineApp } from '@zondax/ledger-substrate';
|
||||
import { newBifrostApp, newCentrifugeApp, newDockApp, newEdgewareApp, newEquilibriumApp, newGenshiroApp, newKusamaApp, newNodleApp, newPolkadotApp, newPolymeshApp, newSoraApp, newStatemineApp } from '@zondax/ledger-substrate';
|
||||
|
||||
// These match up with the keys of the knownLedger object in the @polkadot/networks/defaults.ts
|
||||
export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp> = {
|
||||
bifrost: newBifrostApp,
|
||||
centrifuge: newCentrifugeApp,
|
||||
'dock-mainnet': newDockApp,
|
||||
edgeware: newEdgewareApp,
|
||||
@@ -17,5 +18,6 @@ export const ledgerApps: Record<string, (transport: Transport) => SubstrateApp>
|
||||
'nodle-chain': newNodleApp,
|
||||
polkadot: newPolkadotApp,
|
||||
polymesh: newPolymeshApp,
|
||||
sora: newSoraApp,
|
||||
statemine: newStatemineApp
|
||||
};
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '8.1.2' };
|
||||
export const packageInfo = { name: '@polkadot/hw-ledger', version: '8.2.2' };
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../hw-ledger-transports" },
|
||||
{ "path": "../util" }
|
||||
]
|
||||
}
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/util": "8.1.2",
|
||||
"@polkadot/util-crypto": "8.1.2"
|
||||
"@babel/runtime": "^7.16.5",
|
||||
"@polkadot/util": "8.2.2",
|
||||
"@polkadot/util-crypto": "8.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "8.1.2",
|
||||
"@polkadot/util-crypto": "8.1.2"
|
||||
"@polkadot/util": "8.2.2",
|
||||
"@polkadot/util-crypto": "8.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +369,14 @@ describe('keypair', (): void => {
|
||||
).toEqual(ETH_ADDRESS_ONE);
|
||||
});
|
||||
|
||||
it('creates with dev phrase with derivation path specified - addFromUri with type', (): void => {
|
||||
const keyringUntyped = new Keyring();
|
||||
|
||||
expect(
|
||||
keyringUntyped.addFromUri(PHRASE, {}, 'ethereum').address
|
||||
).toEqual(ETH_ADDRESS_ONE);
|
||||
});
|
||||
|
||||
it('encodes a pair toJSON (and decodes)', (): void => {
|
||||
const pair = keyring.createFromUri(PHRASE);
|
||||
const json = pair.toJson('password');
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '8.1.2' };
|
||||
export const packageInfo = { name: '@polkadot/keyring', version: '8.2.2' };
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { KeyringInstance, KeyringOptions } from './types';
|
||||
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { assert, hexToU8a } from '@polkadot/util';
|
||||
import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
|
||||
import { Keyring } from './keyring';
|
||||
@@ -111,6 +111,15 @@ export const PAIRSETHEREUM: PairDef[] = [
|
||||
}
|
||||
];
|
||||
|
||||
function createMeta (name?: string, seed?: string) {
|
||||
assert(name || seed, 'Testing pair should have either a name or a seed');
|
||||
|
||||
return {
|
||||
isTesting: true,
|
||||
name: name || (seed && seed.replace('//', '_').toLowerCase())
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @name testKeyring
|
||||
* @summary Create an instance of Keyring pre-populated with locked test accounts
|
||||
@@ -119,17 +128,12 @@ export const PAIRSETHEREUM: PairDef[] = [
|
||||
*/
|
||||
export function createTestKeyring (options: KeyringOptions = {}, isDerived = true): KeyringInstance {
|
||||
const keyring = new Keyring(options);
|
||||
const pairs: PairDef[] = (options.type && options.type === 'ethereum') ? PAIRSETHEREUM : PAIRSSR25519;
|
||||
const pairs = (options.type && options.type === 'ethereum')
|
||||
? PAIRSETHEREUM
|
||||
: PAIRSSR25519;
|
||||
|
||||
for (const { name, publicKey, secretKey, seed, type } of pairs) {
|
||||
if (!name && !seed) {
|
||||
throw new Error('Testing pair should have either a name or a seed');
|
||||
}
|
||||
|
||||
const meta = {
|
||||
isTesting: true,
|
||||
name: name || (seed && seed.replace('//', '_').toLowerCase())
|
||||
};
|
||||
const meta = createMeta(name, seed);
|
||||
const pair = !isDerived && !name && seed
|
||||
? keyring.addFromUri(seed, meta, options.type)
|
||||
: keyring.addPair(
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../util" },
|
||||
{ "path": "../util-crypto" }
|
||||
]
|
||||
}
|
||||
@@ -17,13 +17,14 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3"
|
||||
"@babel/runtime": "^7.16.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util": "8.1.2",
|
||||
"@polkadot/x-fetch": "8.1.2"
|
||||
"@polkadot/hw-ledger": "8.2.2",
|
||||
"@polkadot/util": "8.2.2",
|
||||
"@polkadot/x-fetch": "8.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,46 @@
|
||||
// Copyright 2017-2021 @polkadot/networks authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ledgerApps } from '@polkadot/hw-ledger/defaults';
|
||||
import { isHex } from '@polkadot/util';
|
||||
|
||||
import { knownGenesis, knownLedger } from './defaults';
|
||||
|
||||
describe('defaults', (): void => {
|
||||
it('has hex values for all genesis chains', (): void => {
|
||||
expect(
|
||||
Object.keys(knownGenesis).filter((network) =>
|
||||
!knownGenesis[network].length ||
|
||||
knownGenesis[network].some((g) => !isHex(g, 256))
|
||||
)
|
||||
).toEqual([]);
|
||||
describe('genesis', (): void => {
|
||||
it('has hex values for all genesis chains', (): void => {
|
||||
expect(
|
||||
Object.keys(knownGenesis).filter((network) =>
|
||||
!knownGenesis[network].length ||
|
||||
knownGenesis[network].some((g) => !isHex(g, 256))
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('has genesis for all Ledger chains', (): void => {
|
||||
expect(
|
||||
Object.keys(knownLedger).filter((network) =>
|
||||
!knownGenesis[network]
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('has genesis for all Ledger chains', (): void => {
|
||||
expect(
|
||||
Object.keys(knownLedger).filter((network) =>
|
||||
!knownGenesis[network]
|
||||
)
|
||||
).toEqual([]);
|
||||
describe('Ledger', (): void => {
|
||||
it('has entries for each of the apps (hwledger -> networks)', (): void => {
|
||||
expect(
|
||||
Object.keys(knownLedger).filter((network) =>
|
||||
!ledgerApps[network]
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('has entries for each of the apps (networks -> hwledger)', (): void => {
|
||||
expect(
|
||||
Object.keys(ledgerApps).filter((network) =>
|
||||
!knownLedger[network]
|
||||
)
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,6 +63,9 @@ export const knownGenesis: KnownGenesis = {
|
||||
polymesh: [
|
||||
'0x6fbd74e5e1d0a61d52ccfe9d4adaed16dd3a7caa37c6bc4d0c2fa12e8b2f4063'
|
||||
],
|
||||
sora: [
|
||||
'0x7e4e32d0feafd4f9c9414b0be86373f9a1efa904809b683453a9af6856d38ad5'
|
||||
],
|
||||
stafi: [
|
||||
'0x290a4149f09ea0e402c74c1c7e96ae4239588577fe78932f94f5404c68243d80'
|
||||
],
|
||||
@@ -79,6 +82,7 @@ export const knownIcon: KnownIcon = {
|
||||
centrifuge: 'polkadot',
|
||||
kusama: 'polkadot',
|
||||
polkadot: 'polkadot',
|
||||
sora: 'polkadot',
|
||||
statemine: 'polkadot',
|
||||
statemint: 'polkadot',
|
||||
westmint: 'polkadot'
|
||||
@@ -88,6 +92,7 @@ export const knownIcon: KnownIcon = {
|
||||
// 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,
|
||||
@@ -97,6 +102,7 @@ export const knownLedger: KnownLedger = {
|
||||
'nodle-chain': 0x000003eb,
|
||||
polkadot: 0x00000162,
|
||||
polymesh: 0x00000253,
|
||||
sora: 0x00000269,
|
||||
statemine: 0x000001b2 // common-good on Kusama, shares derivation
|
||||
};
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '8.1.2' };
|
||||
export const packageInfo = { name: '@polkadot/networks', version: '8.2.2' };
|
||||
|
||||
@@ -504,12 +504,21 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
website: 'https://crust.network'
|
||||
},
|
||||
{
|
||||
decimals: [0, 9, 9, 9, 9, 9, 9, 9],
|
||||
displayName: 'Equilibrium Network',
|
||||
network: 'equilibrium',
|
||||
decimals: [9, 9, 9],
|
||||
displayName: 'Genshiro Network',
|
||||
network: 'genshiro',
|
||||
prefix: 67,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['Unknown', 'USD', 'EQ', 'ETH', 'BTC', 'EOS', 'DOT', 'CRV'],
|
||||
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'
|
||||
},
|
||||
{
|
||||
@@ -531,12 +540,12 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
website: 'https://zeitgeist.pm'
|
||||
},
|
||||
{
|
||||
decimals: [12],
|
||||
decimals: [18],
|
||||
displayName: 'Manta network',
|
||||
network: 'manta',
|
||||
prefix: 77,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['MA'],
|
||||
symbols: ['MANTA'],
|
||||
website: 'https://manta.network'
|
||||
},
|
||||
{
|
||||
@@ -665,6 +674,15 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
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',
|
||||
@@ -692,6 +710,24 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
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',
|
||||
@@ -723,7 +759,7 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
decimals: [12],
|
||||
displayName: 'CESS Testnet',
|
||||
network: 'cess-testnet',
|
||||
prefix: 10042,
|
||||
prefix: 11330,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['TCESS'],
|
||||
website: 'https://cess.cloud'
|
||||
@@ -732,7 +768,7 @@ export const knownSubstrate: KnownSubstrate[] = [
|
||||
decimals: [12],
|
||||
displayName: 'CESS',
|
||||
network: 'cess',
|
||||
prefix: 10043,
|
||||
prefix: 11331,
|
||||
standardAccount: '*25519',
|
||||
symbols: ['CESS'],
|
||||
website: 'https://cess.cloud'
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../hw-ledger" },
|
||||
{ "path": "../util" },
|
||||
{ "path": "../x-fetch" }
|
||||
]
|
||||
}
|
||||
@@ -22,31 +22,29 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"browser": {
|
||||
"crypto": false,
|
||||
"stream": false
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@noble/hashes": "0.4.1",
|
||||
"@noble/secp256k1": "^1.3.0",
|
||||
"@polkadot/networks": "8.1.2",
|
||||
"@polkadot/util": "8.1.2",
|
||||
"@babel/runtime": "^7.16.5",
|
||||
"@noble/hashes": "^0.4.5",
|
||||
"@noble/secp256k1": "^1.3.4",
|
||||
"@polkadot/networks": "8.2.2",
|
||||
"@polkadot/util": "8.2.2",
|
||||
"@polkadot/wasm-crypto": "^4.5.1",
|
||||
"@polkadot/x-bigint": "8.1.2",
|
||||
"@polkadot/x-noble-hashes": "8.1.2",
|
||||
"@polkadot/x-noble-secp256k1": "8.1.2",
|
||||
"@polkadot/x-randomvalues": "8.1.2",
|
||||
"@polkadot/x-bigint": "8.2.2",
|
||||
"@polkadot/x-randomvalues": "8.2.2",
|
||||
"ed2curve": "^0.3.0",
|
||||
"micro-base": "^0.9.0",
|
||||
"micro-base": "^0.10.0",
|
||||
"tweetnacl": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ed2curve": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "8.1.2"
|
||||
"@polkadot/util": "8.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,21 +3,15 @@
|
||||
|
||||
import { hexToU8a, stringToU8a, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { createTestPairs, TestKeyringMap } from '../../../keyring/src/testingPairs';
|
||||
import { ALICE_PUBLIC_SR } from './encode.spec';
|
||||
import { decodeAddress } from '.';
|
||||
|
||||
describe('decodeAddress', (): void => {
|
||||
let keyring: TestKeyringMap;
|
||||
|
||||
beforeAll((): void => {
|
||||
keyring = createTestPairs({ type: 'sr25519' });
|
||||
});
|
||||
|
||||
it('decodes an address', (): void => {
|
||||
expect(
|
||||
decodeAddress('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
||||
).toEqual(
|
||||
keyring.alice.publicKey
|
||||
ALICE_PUBLIC_SR
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { createTestPairs } from '@polkadot/keyring/testingPairs';
|
||||
|
||||
import { encodeAddress } from '.';
|
||||
|
||||
const keyring = createTestPairs({ type: 'ed25519' }, false);
|
||||
export const ALICE_PUBLIC_SR = new Uint8Array([212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125]);
|
||||
|
||||
export const ALICE_PUBLIC_ED = new Uint8Array([209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79]);
|
||||
|
||||
const SUBKEY = [
|
||||
{
|
||||
@@ -69,7 +69,7 @@ const SUBKEY = [
|
||||
describe('encode', (): void => {
|
||||
it('encodes an address to a valid value', (): void => {
|
||||
expect(
|
||||
keyring.alice.address
|
||||
encodeAddress(ALICE_PUBLIC_ED)
|
||||
).toEqual('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua');
|
||||
});
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('encode', (): void => {
|
||||
it('fails when non-valid publicKey provided', (): void => {
|
||||
expect(
|
||||
(): string => encodeAddress(
|
||||
keyring.alice.publicKey.slice(0, 30)
|
||||
ALICE_PUBLIC_ED.slice(0, 30)
|
||||
)
|
||||
).toThrow(/Expected a valid key/);
|
||||
});
|
||||
@@ -141,7 +141,7 @@ describe('encode', (): void => {
|
||||
|
||||
it('encodes with 2 byte prefix', (): void => {
|
||||
expect(
|
||||
encodeAddress(keyring.alice.publicKey, 255)
|
||||
encodeAddress(ALICE_PUBLIC_ED, 255)
|
||||
).toEqual('yGHU8YKprxHbHdEv7oUK4rzMZXtsdhcXVG2CAMyC9WhzhjH2k');
|
||||
});
|
||||
|
||||
@@ -155,19 +155,19 @@ describe('encode', (): void => {
|
||||
|
||||
it('does not encode for > 16,383, < 0', (): void => {
|
||||
expect(
|
||||
() => encodeAddress(keyring.alice.publicKey, -1)
|
||||
() => encodeAddress(ALICE_PUBLIC_ED, -1)
|
||||
).toThrow(/range ss58Format specified/);
|
||||
expect(
|
||||
() => encodeAddress(keyring.alice.publicKey, 16384)
|
||||
() => encodeAddress(ALICE_PUBLIC_ED, 16384)
|
||||
).toThrow(/range ss58Format specified/);
|
||||
});
|
||||
|
||||
it('does not encode reserved', (): void => {
|
||||
expect(
|
||||
() => encodeAddress(keyring.alice.publicKey, 46)
|
||||
() => encodeAddress(ALICE_PUBLIC_ED, 46)
|
||||
).toThrow(/range ss58Format specified/);
|
||||
expect(
|
||||
() => encodeAddress(keyring.alice.publicKey, 47)
|
||||
() => encodeAddress(ALICE_PUBLIC_ED, 47)
|
||||
).toThrow(/range ss58Format specified/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { createTestPairs } from '@polkadot/keyring/testingPairs';
|
||||
|
||||
import { ALICE_PUBLIC_SR } from './encode.spec';
|
||||
import { addressEq } from '.';
|
||||
|
||||
describe('addressEq', (): void => {
|
||||
@@ -34,12 +33,10 @@ describe('addressEq', (): void => {
|
||||
});
|
||||
|
||||
it('returns true for equal, address vs publicKey', (): void => {
|
||||
const keyring = createTestPairs({ type: 'sr25519' });
|
||||
|
||||
expect(
|
||||
addressEq(
|
||||
'5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
|
||||
keyring.alice.publicKey
|
||||
ALICE_PUBLIC_SR
|
||||
)
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { U8aLike } from '@polkadot/util/types';
|
||||
|
||||
import { assert, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
// NOTE: Work around a TS issue. These are re-defined like in @polkadot/util/types
|
||||
// since without it the import
|
||||
//
|
||||
// import type { U8aLike } from '@polkadot/util/types';
|
||||
//
|
||||
// ends up in the build-generated code as
|
||||
//
|
||||
// impor("../../../util/src/types").U8aLike
|
||||
//
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type U8aLike = number[] | Buffer | Uint8Array | string | String;
|
||||
// re-export the type so *.d.ts files don't have ../src imports
|
||||
export type { U8aLike } from '@polkadot/util/types';
|
||||
|
||||
interface Coder {
|
||||
decode: (value: string) => Uint8Array;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { blake2AsU8a } from '.';
|
||||
|
||||
describe('blake2AsU8a', (): void => {
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { blake2b as blake2bJs } from '@noble/hashes/lib/blake2b';
|
||||
|
||||
import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2b, isReady } from '@polkadot/wasm-crypto';
|
||||
import { blake2b as blake2bJs } from '@polkadot/x-noble-hashes/blake2b';
|
||||
|
||||
import { createAsHex } from '../helpers';
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
import '@polkadot/x-bigint/shim';
|
||||
|
||||
import { utils as utilsNobleSecp256k1 } from '@noble/secp256k1';
|
||||
|
||||
import { u8aConcat } from '@polkadot/util';
|
||||
import { utils as utilsNobleSecp256k1 } from '@polkadot/x-noble-secp256k1';
|
||||
|
||||
import { cryptoWaitReady } from './crypto';
|
||||
import { hmacSha256AsU8a } from './hmac';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { ed25519PairFromSeed, ed25519Sign } from '.';
|
||||
|
||||
const PAIR = ed25519PairFromSeed(
|
||||
|
||||
@@ -3,7 +3,16 @@
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
import { hasBigInt, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
// re-export so TS *.d.ts generation is correct
|
||||
export type { HexString } from '@polkadot/util/types';
|
||||
|
||||
interface DualHash {
|
||||
256: (u8a: Uint8Array) => Uint8Array;
|
||||
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 {
|
||||
@@ -15,3 +24,13 @@ export function createBitHasher <T> (bitLength: T, fn: (data: HexString | Buffer
|
||||
return (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean): Uint8Array =>
|
||||
fn(data, bitLength, onlyJs);
|
||||
}
|
||||
|
||||
export function createDualHasher (wa: DualHash, js: DualHash): (value: HexString | Buffer | Uint8Array | string, bitLength?: 256 | 512, onlyJs?: boolean) => Uint8Array {
|
||||
return (value: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array => {
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
? wa[bitLength](u8a)
|
||||
: js[bitLength](u8a);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a, stringToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { hmacShaAsU8a } from '.';
|
||||
|
||||
describe('hmacShaAsU8a', (): void => {
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { hmac } from '@noble/hashes/lib/hmac';
|
||||
import { sha256 } from '@noble/hashes/lib/sha256';
|
||||
import { sha512 } from '@noble/hashes/lib/sha512';
|
||||
|
||||
import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { hmacSha256, hmacSha512, isReady } from '@polkadot/wasm-crypto';
|
||||
import { hmac } from '@polkadot/x-noble-hashes/hmac';
|
||||
import { sha256 } from '@polkadot/x-noble-hashes/sha256';
|
||||
import { sha512 } from '@polkadot/x-noble-hashes/sha512';
|
||||
|
||||
type BitLength = 256 | 512;
|
||||
|
||||
const JS_HASH = {
|
||||
256: sha256,
|
||||
512: sha512
|
||||
};
|
||||
|
||||
const WA_MHAC = {
|
||||
256: hmacSha256,
|
||||
512: hmacSha512
|
||||
};
|
||||
|
||||
function createSha (bitLength: BitLength): (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean) => Uint8Array {
|
||||
return (key: Uint8Array | string, data: Uint8Array, onlyJs?: boolean): Uint8Array =>
|
||||
hmacShaAsU8a(key, data, bitLength, onlyJs);
|
||||
@@ -19,16 +30,11 @@ function createSha (bitLength: BitLength): (key: Uint8Array | string, data: Uint
|
||||
* @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 {
|
||||
const is256 = bitLength === 256;
|
||||
const u8aKey = u8aToU8a(key);
|
||||
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
? is256
|
||||
? hmacSha256(u8aKey, data)
|
||||
: hmacSha512(u8aKey, data)
|
||||
: is256
|
||||
? hmac(sha256, u8aKey, data)
|
||||
: hmac(sha512, u8aKey, data);
|
||||
? WA_MHAC[bitLength](u8aKey, data)
|
||||
: hmac(JS_HASH[bitLength], u8aKey, data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a, stringToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { keccakAsU8a } from '.';
|
||||
|
||||
describe('keccakAsU8a', (): void => {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from '@noble/hashes/lib/sha3';
|
||||
|
||||
import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, keccak256, keccak512 } from '@polkadot/wasm-crypto';
|
||||
import { keccak_256 as keccak256Js, keccak_512 as keccak512Js } from '@polkadot/x-noble-hashes/sha3';
|
||||
import { keccak256, keccak512 } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createAsHex, createBitHasher } from '../helpers';
|
||||
|
||||
type BitLength = 256 | 512;
|
||||
import { createAsHex, createBitHasher, createDualHasher } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name keccakAsU8a
|
||||
@@ -25,18 +21,11 @@ type BitLength = 256 | 512;
|
||||
* keccakAsU8a('123'); // => Uint8Array
|
||||
* ```
|
||||
*/
|
||||
export function keccakAsU8a (value: HexString | Buffer | Uint8Array | string, bitLength: BitLength = 256, onlyJs?: boolean): Uint8Array {
|
||||
const is256 = bitLength === 256;
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
? is256
|
||||
? keccak256(u8a)
|
||||
: keccak512(u8a)
|
||||
: is256
|
||||
? keccak256Js(u8a)
|
||||
: keccak512Js(u8a);
|
||||
}
|
||||
export const keccakAsU8a = createDualHasher(
|
||||
{ 256: keccak256, 512: keccak512 },
|
||||
{ 256: keccak256Js, 512: keccak512Js }
|
||||
);
|
||||
|
||||
/**
|
||||
* @name keccak256AsU8a
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import DEFAULT_WORDLIST from './bip39-en';
|
||||
|
||||
describe('wordlist', (): void => {
|
||||
it('has the correct number of words', (): void => {
|
||||
expect(DEFAULT_WORDLIST).toHaveLength(2048);
|
||||
});
|
||||
|
||||
it('has no empty words', (): void => {
|
||||
expect(DEFAULT_WORDLIST.some((n) => !n.length || n.trim() !== n)).toEqual(false);
|
||||
});
|
||||
});
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '8.1.2' };
|
||||
export const packageInfo = { name: '@polkadot/util-crypto', version: '8.2.2' };
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import { u8aEq, u8aToHex } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { pbkdf2Encode } from '.';
|
||||
|
||||
const KNOWN_SALT = new Uint8Array([
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
import { pbkdf2 as pbkdf2Js } from '@noble/hashes/lib/pbkdf2';
|
||||
import { sha512 } from '@noble/hashes/lib/sha512';
|
||||
|
||||
import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, pbkdf2 } from '@polkadot/wasm-crypto';
|
||||
import { pbkdf2 as pbkdf2Js } from '@polkadot/x-noble-hashes/pbkdf2';
|
||||
import { sha512 } from '@polkadot/x-noble-hashes/sha512';
|
||||
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { DEFAULT_PARAMS } from './defaults';
|
||||
import { scryptEncode } from '.';
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Params } from './types';
|
||||
|
||||
import { scrypt as scryptJs } from '@noble/hashes/lib/scrypt';
|
||||
|
||||
import { hasBigInt, objectSpread, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, scrypt } from '@polkadot/wasm-crypto';
|
||||
import { scrypt as scryptJs } from '@polkadot/x-noble-hashes/scrypt';
|
||||
|
||||
import { randomAsU8a } from '../random/asU8a';
|
||||
import { DEFAULT_PARAMS } from './defaults';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { secp256k1Compress } from '.';
|
||||
|
||||
describe('secp256k1Compress', (): void => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Point } from '@noble/secp256k1';
|
||||
|
||||
import { assert, hasBigInt } from '@polkadot/util';
|
||||
import { isReady, secp256k1Compress as wasm } from '@polkadot/wasm-crypto';
|
||||
import { Point } from '@polkadot/x-noble-secp256k1';
|
||||
|
||||
export function secp256k1Compress (publicKey: Uint8Array, onlyJs?: boolean): Uint8Array {
|
||||
if (publicKey.length === 33) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { secp256k1Expand } from '.';
|
||||
|
||||
describe('secp256k1Expand', (): void => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Point } from '@noble/secp256k1';
|
||||
|
||||
import { assert, bnToU8a, hasBigInt, u8aConcat } from '@polkadot/util';
|
||||
import { isReady, secp256k1Expand as wasm } from '@polkadot/wasm-crypto';
|
||||
import { Point } from '@polkadot/x-noble-secp256k1';
|
||||
|
||||
import { BN_BE_256_OPTS } from '../bn';
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../../test/performance';
|
||||
import { mnemonicToMiniSecret } from '../../mnemonic';
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { secp256k1PairFromSeed } from '..';
|
||||
|
||||
// mnemonic, secret, public, account_id
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
|
||||
import type { Keypair } from '../../types';
|
||||
|
||||
import { getPublicKey } from '@noble/secp256k1';
|
||||
|
||||
import { assert, hasBigInt } from '@polkadot/util';
|
||||
import { isReady, secp256k1FromSeed } from '@polkadot/wasm-crypto';
|
||||
import { getPublicKey } from '@polkadot/x-noble-secp256k1';
|
||||
|
||||
/**
|
||||
* @name secp256k1PairFromSeed
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
import { u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { keccakAsU8a } from '../keccak';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { secp256k1Recover } from '.';
|
||||
|
||||
const sig = u8aToU8a('0x7505f2880114da51b3f5d535f8687953c0ab9af4ab81e592eaebebf53b728d2b6dfd9b5bcd70fee412b1f31360e7c2774009305cb84fc50c1d0ff8034dfa5fff');
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { HashType } from './types';
|
||||
|
||||
import { recoverPublicKey, Signature } from '@noble/secp256k1';
|
||||
|
||||
import { assert, hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, secp256k1Recover as wasm } from '@polkadot/wasm-crypto';
|
||||
import { recoverPublicKey, Signature } from '@polkadot/x-noble-secp256k1';
|
||||
|
||||
import { secp256k1Compress } from './compress';
|
||||
import { secp256k1Expand } from './expand';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { secp256k1PairFromSeed, secp256k1Sign } from '.';
|
||||
|
||||
const pair = secp256k1PairFromSeed(hexToU8a('0x4380de832af797688026ce24f85204d508243f201650c1a134929e5458b7fbae'));
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
import type { Keypair } from '../types';
|
||||
import type { HashType } from './types';
|
||||
|
||||
import { Signature, signSync } from '@noble/secp256k1';
|
||||
|
||||
import { assert, bnToU8a, hasBigInt, u8aConcat } from '@polkadot/util';
|
||||
import { isReady, secp256k1Sign as wasm } from '@polkadot/wasm-crypto';
|
||||
import { Signature, signSync } from '@polkadot/x-noble-secp256k1';
|
||||
|
||||
import { BN_BE_256_OPTS } from '../bn';
|
||||
import { hasher } from './hasher';
|
||||
|
||||
@@ -6,7 +6,7 @@ import '../cryptoInit';
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { hasher } from './hasher';
|
||||
import { secp256k1PairFromSeed, secp256k1Verify } from '.';
|
||||
|
||||
|
||||
@@ -1,33 +1,21 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import { sha256 as sha256Js } from '@noble/hashes/lib/sha256';
|
||||
import { sha512 as sha512Js } from '@noble/hashes/lib/sha512';
|
||||
|
||||
import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
||||
import { isReady, sha256, sha512 } from '@polkadot/wasm-crypto';
|
||||
import { sha256 as sha256Js } from '@polkadot/x-noble-hashes/sha256';
|
||||
import { sha512 as sha512Js } from '@polkadot/x-noble-hashes/sha512';
|
||||
import { sha256, sha512 } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { createBitHasher } from '../helpers';
|
||||
|
||||
type BitLength = 256 | 512;
|
||||
import { createBitHasher, createDualHasher } from '../helpers';
|
||||
|
||||
/**
|
||||
* @name shaAsU8a
|
||||
* @summary Creates a sha Uint8Array from the input.
|
||||
*/
|
||||
export function shaAsU8a (value: HexString | Buffer | Uint8Array | string, bitLength: BitLength = 256, onlyJs?: boolean): Uint8Array {
|
||||
const is256 = bitLength === 256;
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
? is256
|
||||
? sha256(u8a)
|
||||
: sha512(u8a)
|
||||
: is256
|
||||
? sha256Js(u8a)
|
||||
: sha512Js(u8a);
|
||||
}
|
||||
export const shaAsU8a = createDualHasher(
|
||||
{ 256: sha256, 512: sha512 },
|
||||
{ 256: sha256Js, 512: sha512Js }
|
||||
);
|
||||
|
||||
/**
|
||||
* @name sha256AsU8a
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { sha256AsU8a } from '.';
|
||||
|
||||
const TESTS = [
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { sha512AsU8a } from '.';
|
||||
|
||||
describe('sha512AsU8a', (): void => {
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { arrayRange } from '@polkadot/util';
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
import { performance, performanceCmp } from '@polkadot/util/test/performance';
|
||||
|
||||
import { performance, performanceCmp } from '../../util/test/performance';
|
||||
import { randomAsU8a } from '..';
|
||||
|
||||
type ExecFn = (input: Uint8Array, onlyJs: boolean) => unknown;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
import { waitReady } from '@polkadot/wasm-crypto';
|
||||
|
||||
import { performanceWasm } from '../../test/performance';
|
||||
import { performanceWasm } from '../test/performance';
|
||||
import { xxhashAsU8a } from '.';
|
||||
|
||||
describe('xxhashAsU8a', (): void => {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"references": [
|
||||
{ "path": "../networks" },
|
||||
{ "path": "../util" },
|
||||
{ "path": "../x-bigint" },
|
||||
{ "path": "../x-randomvalues" }
|
||||
]
|
||||
}
|
||||
@@ -34,16 +34,19 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.1.2",
|
||||
"version": "8.2.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/x-bigint": "8.1.2",
|
||||
"@polkadot/x-global": "8.1.2",
|
||||
"@polkadot/x-textdecoder": "8.1.2",
|
||||
"@polkadot/x-textencoder": "8.1.2",
|
||||
"@babel/runtime": "^7.16.5",
|
||||
"@polkadot/x-bigint": "8.2.2",
|
||||
"@polkadot/x-global": "8.2.2",
|
||||
"@polkadot/x-textdecoder": "8.2.2",
|
||||
"@polkadot/x-textencoder": "8.2.2",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.12.0",
|
||||
"ip-regex": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/x-randomvalues": "8.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,3 +42,11 @@ export function assertReturn <T> (value: T | undefined | null, message: string |
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name assertUnreachable
|
||||
* @description An assertion helper that ensures all codepaths are followed
|
||||
*/
|
||||
export function assertUnreachable (x: never): never {
|
||||
throw new Error(`This codepath should be unreachable. Unhandled input: ${x as unknown as string}`);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ export * from './consts';
|
||||
|
||||
export { nSqrt } from './sqrt';
|
||||
export { nToBigInt } from './toBigInt';
|
||||
export { nMax } from './max';
|
||||
export { nMin } from './min';
|
||||
export { nMax, nMin } from './min';
|
||||
export { nToHex } from './toHex';
|
||||
export { nToU8a } from './toU8a';
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert } from '../assert';
|
||||
|
||||
/**
|
||||
* @name nMax
|
||||
* @summary Finds and returns the highest value in an array of bigint.
|
||||
*/
|
||||
export function nMax (...items: bigint[]): bigint {
|
||||
assert(items.length >= 1, 'Must provide one or more bigint arguments');
|
||||
|
||||
let result = items[0];
|
||||
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
if (items[i] > result) {
|
||||
result = items[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -3,20 +3,40 @@
|
||||
|
||||
import { assert } from '../assert';
|
||||
|
||||
/**
|
||||
* @name nMin
|
||||
* @summary Finds and returns the lowest value in an array of bigint.
|
||||
*/
|
||||
export function nMin (...items: bigint[]): bigint {
|
||||
function gt (a: bigint, b: bigint): boolean {
|
||||
return a > b;
|
||||
}
|
||||
|
||||
function lt (a: bigint, b: bigint): boolean {
|
||||
return a < b;
|
||||
}
|
||||
|
||||
function find (items: bigint[], cmp: (a: bigint, b: bigint) => boolean): bigint {
|
||||
assert(items.length >= 1, 'Must provide one or more bigint arguments');
|
||||
|
||||
let result = items[0];
|
||||
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
if (items[i] < result) {
|
||||
if (cmp(items[i], result)) {
|
||||
result = items[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name nMax
|
||||
* @summary Finds and returns the highest value in an array of bigint.
|
||||
*/
|
||||
export function nMax (...items: bigint[]): bigint {
|
||||
return find(items, gt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name nMin
|
||||
* @summary Finds and returns the lowest value in an array of bigint.
|
||||
*/
|
||||
export function nMin (...items: bigint[]): bigint {
|
||||
return find(items, lt);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performance } from '../../test/performance';
|
||||
import { arrayRange } from '../array';
|
||||
import { performance } from '../test/performance';
|
||||
import { nToU8a } from '.';
|
||||
|
||||
const ptest = arrayRange(65536).map((v) => [v]);
|
||||
|
||||
@@ -9,8 +9,7 @@ export * from './consts';
|
||||
|
||||
export { BN } from './bn';
|
||||
export { bnFromHex } from './fromHex';
|
||||
export { bnMax } from './max';
|
||||
export { bnMin } from './min';
|
||||
export { bnMax, bnMin } from './min';
|
||||
export { bnSqrt } from './sqrt';
|
||||
export { bnToBn } from './toBn';
|
||||
export { bnToHex } from './toHex';
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert } from '../assert';
|
||||
import { BN } from './bn';
|
||||
|
||||
export function checkMaxMin (type: 'max' | 'min', items: BN[]): BN {
|
||||
assert(items.length >= 1, 'Must provide one or more BN arguments');
|
||||
|
||||
let result = items[0];
|
||||
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
result = BN[type](result, items[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name bnMax
|
||||
* @summary Finds and returns the highest value in an array of BNs.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnMax } from '@polkadot/util';
|
||||
*
|
||||
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
|
||||
* ```
|
||||
*/
|
||||
export function bnMax (...items: BN[]): BN {
|
||||
return checkMaxMin('max', items);
|
||||
}
|
||||
@@ -1,9 +1,37 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from './bn';
|
||||
import { assert } from '../assert';
|
||||
import { BN } from './bn';
|
||||
|
||||
import { checkMaxMin } from './max';
|
||||
export function find (items: BN[], cmp: (a: BN, b: BN) => BN): BN {
|
||||
assert(items.length >= 1, 'Must provide one or more BN arguments');
|
||||
|
||||
let result = items[0];
|
||||
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
result = cmp(result, items[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name bnMax
|
||||
* @summary Finds and returns the highest value in an array of BNs.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnMax } from '@polkadot/util';
|
||||
*
|
||||
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
|
||||
* ```
|
||||
*/
|
||||
export function bnMax (...items: BN[]): BN {
|
||||
return find(items, BN.max);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name bnMin
|
||||
@@ -19,5 +47,5 @@ import { checkMaxMin } from './max';
|
||||
* ```
|
||||
*/
|
||||
export function bnMin (...items: BN[]): BN {
|
||||
return checkMaxMin('min', items);
|
||||
return find(items, BN.min);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performance } from '../../test/performance';
|
||||
import { arrayRange } from '../array';
|
||||
import { performance } from '../test/performance';
|
||||
import { BN, bnToU8a } from '.';
|
||||
|
||||
const ptest = arrayRange(65536).map((v) => [v]);
|
||||
|
||||
@@ -43,6 +43,33 @@ const DEFAULT_UNIT = SI[SI_MID].text;
|
||||
let defaultDecimals = DEFAULT_DECIMALS;
|
||||
let defaultUnit = DEFAULT_UNIT;
|
||||
|
||||
function getUnits (si: SiDef, withSi: boolean, withSiFull: boolean, withUnit: boolean | string): string {
|
||||
const unit = isBoolean(withUnit)
|
||||
? SI[SI_MID].text
|
||||
: withUnit;
|
||||
|
||||
return withSi || withSiFull
|
||||
? si.value === '-'
|
||||
? withUnit
|
||||
? ` ${unit}`
|
||||
: ''
|
||||
: ` ${withSiFull ? `${si.text}${withUnit ? ' ' : ''}` : si.value}${withUnit ? unit : ''}`
|
||||
: '';
|
||||
}
|
||||
|
||||
function getPrePost (text: string, decimals: number, forceUnit?: string): [SiDef, string, string] {
|
||||
// NOTE We start at midpoint (8) minus 1 - this means that values display as
|
||||
// 123.456 instead of 0.123k (so always 6 relevant). Additionally we use ceil
|
||||
// so there are at most 3 decimal before the decimal separator
|
||||
const si = calcSi(text, decimals, forceUnit);
|
||||
const mid = text.length - (decimals + si.power);
|
||||
const prefix = text.substring(0, mid);
|
||||
const padding = mid < 0 ? 0 - mid : 0;
|
||||
const postfix = `${`${new Array(padding + 1).join('0')}${text}`.substring(mid < 0 ? 0 : mid)}0000`.substring(0, 4);
|
||||
|
||||
return [si, prefix || '0', postfix];
|
||||
}
|
||||
|
||||
// Formats a string/number with <prefix>.<postfix><type> notation
|
||||
function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, options: Options | boolean = true, optDecimals: number = defaultDecimals): string {
|
||||
let text = bnToBn(input).toString();
|
||||
@@ -51,39 +78,27 @@ function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | b
|
||||
return '0';
|
||||
}
|
||||
|
||||
// strip the negative sign so we can work with clean groupings, re-add this in the
|
||||
// end when we return the result (from here on we work with positive numbers)
|
||||
const isNegative = text[0].startsWith('-');
|
||||
|
||||
if (isNegative) {
|
||||
text = text.substr(1);
|
||||
}
|
||||
|
||||
// extract options - the boolean case is for backwards-compat
|
||||
const { decimals = optDecimals, forceUnit = undefined, withSi = true, withSiFull = false, withUnit = true } = isBoolean(options)
|
||||
? { withSi: options }
|
||||
: options;
|
||||
|
||||
// NOTE We start at midpoint (8) minus 1 - this means that values display as
|
||||
// 123.456 instead of 0.123k (so always 6 relevant). Additionally we use ceil
|
||||
// so there are at most 3 decimal before the decimal separator
|
||||
const si = calcSi(text, decimals, forceUnit);
|
||||
const mid = text.length - (decimals + si.power);
|
||||
const prefix = text.substr(0, mid);
|
||||
const padding = mid < 0 ? 0 - mid : 0;
|
||||
const postfix = `${`${new Array(padding + 1).join('0')}${text}`.substr(mid < 0 ? 0 : mid)}0000`.substr(0, 4);
|
||||
const units = withSi || withSiFull
|
||||
? si.value === '-'
|
||||
? withUnit
|
||||
? ` ${isBoolean(withUnit) ? si.text : withUnit}`
|
||||
: ''
|
||||
: ` ${withSiFull ? si.text : si.value}${withUnit ? `${withSiFull ? ' ' : ''}${(isBoolean(withUnit) ? SI[SI_MID].text : withUnit)}` : ''}`
|
||||
: '';
|
||||
// strip the negative sign so we can work with clean groupings, re-add this in the
|
||||
// end when we return the result (from here on we work with positive numbers)
|
||||
let sign = '';
|
||||
|
||||
return `${isNegative ? '-' : ''}${formatDecimal(prefix || '0')}.${postfix}${units}`;
|
||||
if (text[0].startsWith('-')) {
|
||||
sign = '-';
|
||||
text = text.substring(1);
|
||||
}
|
||||
|
||||
const [si, prefix, postfix] = getPrePost(text, decimals, forceUnit);
|
||||
const units = getUnits(si, withSi, withSiFull, withUnit);
|
||||
|
||||
return `${sign}${formatDecimal(prefix)}.${postfix}${units}`;
|
||||
}
|
||||
|
||||
const formatBalance = _formatBalance as BalanceFormatter;
|
||||
export const formatBalance = _formatBalance as BalanceFormatter;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
formatBalance.calcSi = (text: string, decimals: number = defaultDecimals): SiDef =>
|
||||
@@ -126,5 +141,3 @@ formatBalance.setDefaults = ({ decimals, unit }: SetDefaults): void => {
|
||||
|
||||
SI[SI_MID].text = defaultUnit;
|
||||
};
|
||||
|
||||
export { formatBalance };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceCmp } from '../../test/performance';
|
||||
import { performanceCmp } from '../test/performance';
|
||||
import { U16_TO_HEX } from './alphabet';
|
||||
import { hexToU8a as hexToU8aBuffer } from './toU8aBuffer';
|
||||
import { hexToU8a } from '.';
|
||||
|
||||
@@ -19,4 +19,22 @@ describe('isCodec', (): void => {
|
||||
})
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('is true when invalid codec-like signature is found', (): void => {
|
||||
expect(
|
||||
isCodec({
|
||||
toHex: () => '0x',
|
||||
toU8a: () => new Uint8Array()
|
||||
})
|
||||
).toEqual(false);
|
||||
expect(
|
||||
isCodec({
|
||||
registry: {
|
||||
get: () => null
|
||||
},
|
||||
toHex: 1,
|
||||
toU8a: () => new Uint8Array()
|
||||
})
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { HexString } from '../types';
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
import { isOnObject } from './helpers';
|
||||
|
||||
interface Registry {
|
||||
get: (...params: unknown[]) => unknown;
|
||||
@@ -17,11 +16,9 @@ interface Codec {
|
||||
toU8a: (isBare?: unknown) => Uint8Array;
|
||||
}
|
||||
|
||||
const checkCodec = isOnObject<Codec>('toHex', 'toU8a');
|
||||
const checkRegistry = isOnObject<Registry>('get');
|
||||
|
||||
export function isCodec <T extends Codec = Codec> (value?: unknown): value is T {
|
||||
return (
|
||||
isObject<T>(value) &&
|
||||
isFunction(value.toU8a) &&
|
||||
isObject<Registry>(value.registry) &&
|
||||
isFunction(value.registry.get)
|
||||
);
|
||||
return checkCodec(value) && checkRegistry(value.registry);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { BN } from '../bn/bn';
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
import { isOnObject } from './helpers';
|
||||
|
||||
interface Compact<T> {
|
||||
toBigInt (): bigint;
|
||||
@@ -13,16 +12,12 @@ interface Compact<T> {
|
||||
unwrap (): T;
|
||||
}
|
||||
|
||||
const checker = isOnObject('toBigInt', 'toBn', 'toNumber', 'unwrap');
|
||||
|
||||
/**
|
||||
* @name isCompact
|
||||
* @summary Tests for SCALE-Compact-like object instance.
|
||||
*/
|
||||
export function isCompact <T> (value?: unknown): value is Compact<T> {
|
||||
return (
|
||||
isObject<Compact<T>>(value) &&
|
||||
isFunction(value.toBigInt) &&
|
||||
isFunction(value.toBn) &&
|
||||
isFunction(value.toNumber) &&
|
||||
isFunction(value.unwrap)
|
||||
);
|
||||
return checker(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
|
||||
export function isOn <T> (...fns: (keyof T)[]): (value?: unknown) => value is T {
|
||||
return (value?: unknown): value is T =>
|
||||
(isObject(value) || isFunction(value)) &&
|
||||
fns.every((f) => isFunction((value as T)[f]));
|
||||
}
|
||||
|
||||
export function isOnObject <T> (...fns: (keyof T)[]): (value?: unknown) => value is T {
|
||||
return (value?: unknown): value is T =>
|
||||
isObject(value) &&
|
||||
fns.every((f) => isFunction((value as T)[f]));
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performance } from '../../test/performance';
|
||||
import { performance } from '../test/performance';
|
||||
import { isHex } from '.';
|
||||
|
||||
describe('isHex', (): void => {
|
||||
|
||||
@@ -22,17 +22,15 @@ export const REGEX_HEX_NOPREFIX = /^[\da-fA-F]+$/;
|
||||
* isHex('0x1234', 8); // => false
|
||||
* ```
|
||||
*/
|
||||
export function isHex (value: unknown, bitLength = -1, ignoreLength = false): value is HexString {
|
||||
export function isHex (value: unknown, bitLength = -1, ignoreLength?: boolean): value is HexString {
|
||||
return (
|
||||
typeof value === 'string' && (
|
||||
value === '0x' ||
|
||||
REGEX_HEX_PREFIXED.test(value)
|
||||
)
|
||||
)
|
||||
? bitLength === -1
|
||||
? ignoreLength
|
||||
? true
|
||||
: (value.length % 2 === 0)
|
||||
) && (
|
||||
bitLength === -1
|
||||
? (ignoreLength || (value.length % 2 === 0))
|
||||
: (value.length === (2 + Math.ceil(bitLength / 4)))
|
||||
: false;
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export { isNull } from './null';
|
||||
export { isNumber } from './number';
|
||||
export { isObject } from './object';
|
||||
export { isObservable } from './observable';
|
||||
export { isPromise } from './promise';
|
||||
export { isString } from './string';
|
||||
export { isTestChain } from './testChain';
|
||||
export { isToBigInt } from './toBigInt';
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
import type { Observable } from '../types';
|
||||
|
||||
interface Observable {
|
||||
next: (...params: unknown[]) => unknown;
|
||||
}
|
||||
import { isOn } from './helpers';
|
||||
|
||||
/**
|
||||
* @name isBObservable
|
||||
@@ -22,9 +19,4 @@ interface Observable {
|
||||
* console.log('isObservable', isObservable(...));
|
||||
* ```
|
||||
*/
|
||||
export function isObservable (value: unknown): value is Observable {
|
||||
return (
|
||||
isObject(value) &&
|
||||
isFunction((value as Observable).next)
|
||||
);
|
||||
}
|
||||
export const isObservable = isOn<Observable>('next');
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isPromise } from '.';
|
||||
|
||||
describe('isPromise', (): void => {
|
||||
it('returns true on valid Promise (Promise-like)', (): void => {
|
||||
expect(
|
||||
isPromise(Promise.resolve(1))
|
||||
).toEqual(true);
|
||||
expect(
|
||||
isPromise({ catch: () => null, then: () => null })
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('returns false on invalid objects', (): void => {
|
||||
expect(
|
||||
isPromise('notAnObservable')
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns false on invalid catch/then functions', (): void => {
|
||||
expect(
|
||||
isPromise({ catch: () => null, then: true })
|
||||
).toEqual(false);
|
||||
expect(
|
||||
isPromise({ catch: true, then: () => null })
|
||||
).toEqual(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isOnObject } from './helpers';
|
||||
|
||||
export const isPromise = isOnObject<Promise<unknown>>('catch', 'then');
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
import type { ToBigInt } from '../types';
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isOn } from './helpers';
|
||||
|
||||
export function isToBigInt (value?: unknown): value is ToBigInt {
|
||||
return !!value && isFunction((value as ToBigInt).toBigInt);
|
||||
}
|
||||
export const isToBigInt = isOn<ToBigInt>('toBigInt');
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
import type { ToBn } from '../types';
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isOn } from './helpers';
|
||||
|
||||
export function isToBn (value?: unknown): value is ToBn {
|
||||
return !!value && isFunction((value as ToBn).toBn);
|
||||
}
|
||||
export const isToBn = isOn<ToBn>('toBn');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aEq } from '../u8a/eq';
|
||||
import { isU8a } from './u8a';
|
||||
|
||||
const WASM_MAGIC = new Uint8Array([0, 97, 115, 109]); // \0asm
|
||||
|
||||
@@ -11,6 +12,6 @@ const WASM_MAGIC = new Uint8Array([0, 97, 115, 109]); // \0asm
|
||||
* @description
|
||||
* Checks to see if the input Uint8Array contains a valid WASM header
|
||||
*/
|
||||
export function isWasm (value?: Uint8Array): boolean {
|
||||
return !!value && u8aEq(value.subarray(0, 4), WASM_MAGIC);
|
||||
export function isWasm (value?: unknown): value is Uint8Array {
|
||||
return isU8a(value) && u8aEq(value.subarray(0, 4), WASM_MAGIC);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
type Entries<T> = {
|
||||
[K in keyof T]: [K, T[K]]
|
||||
}[keyof T][];
|
||||
type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][];
|
||||
|
||||
/**
|
||||
* @name objectEntries
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
type Values<T extends object> = T[keyof T][];
|
||||
|
||||
/**
|
||||
* @name objectValues
|
||||
* @summary A version of Object.values that is typed for TS
|
||||
*/
|
||||
export function objectValues<T extends object> (obj: T): Values<T> {
|
||||
return Object.values(obj) as Values<T>;
|
||||
export function objectValues<T extends object> (obj: T): T[keyof T][] {
|
||||
return Object.values(obj) as T[keyof T][];
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/util', version: '8.1.2' };
|
||||
export const packageInfo = { name: '@polkadot/util', version: '8.2.2' };
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { randomAsNumber } from '@polkadot/util-crypto';
|
||||
import words from '@polkadot/util-crypto/mnemonic/bip39-en';
|
||||
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||
|
||||
import { performance } from '../../test/performance';
|
||||
import { arrayRange } from '../array';
|
||||
import { performance } from '../test/performance';
|
||||
import { stringCamelCase, stringUpperFirst } from '.';
|
||||
|
||||
const SEPS = [' ', '_', '-', '.', ','];
|
||||
const words = 'bring|brisk|broccoli|broken|bronze|broom|brother|brown|brush|bubble|buddy|budget|buffalo|build|bulb|bulk|bullet|bundle|bunker|burden'.split('|');
|
||||
|
||||
function randomAsNumber (): number {
|
||||
const rand = getRandomValues(new Uint8Array(4));
|
||||
|
||||
return rand.reduce((v, t) => (v * t) + v, 0);
|
||||
}
|
||||
|
||||
const randomWords = arrayRange(256).map((): [string] => {
|
||||
let result = '';
|
||||
@@ -68,6 +74,27 @@ describe('stringCamelCase', (): void => {
|
||||
expect(
|
||||
stringCamelCase('BLAKE2B')
|
||||
).toEqual('blake2b');
|
||||
expect(
|
||||
stringCamelCase('NFTOrder')
|
||||
).toEqual('nftOrder');
|
||||
expect(
|
||||
stringCamelCase('EVM')
|
||||
).toEqual('evm');
|
||||
expect(
|
||||
stringCamelCase('A')
|
||||
).toEqual('a');
|
||||
expect(
|
||||
stringCamelCase('A1')
|
||||
).toEqual('a1');
|
||||
expect(
|
||||
stringCamelCase('A1b')
|
||||
).toEqual('a1b');
|
||||
expect(
|
||||
stringCamelCase('A1B')
|
||||
).toEqual('a1b');
|
||||
expect(
|
||||
stringCamelCase('RawVRFOutput')
|
||||
).toEqual('rawVRFOutput');
|
||||
});
|
||||
|
||||
it('adjusts with leading _', (): void => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { AnyString } from '../types';
|
||||
// a 10+x improvement over the original camelcase npm package (at running)
|
||||
//
|
||||
// original: 20.88 μs/op
|
||||
// this: 2.97 μs/op
|
||||
// this: 2.86 μs/op
|
||||
//
|
||||
// Caveat of this: only Ascii, but acceptable for the intended usecase
|
||||
function converter (fn: (w: string, i: number) => string): (value: AnyString) => string {
|
||||
@@ -32,7 +32,10 @@ function converter (fn: (w: string, i: number) => string): (value: AnyString) =>
|
||||
// all full uppercase + letters are changed to lowercase
|
||||
? w.toLowerCase()
|
||||
// all consecutive capitals + letters are changed to lowercase
|
||||
: w.replace(/[A-Z]{2,}[0-9]{2,}/g, (w) => w.toLowerCase()),
|
||||
// e.g. UUID64 -> uuid64, while preserving splits, eg. NFTOrder -> nftOrder
|
||||
: w.replace(/^[A-Z0-9]{2,}[^a-z]/, (w) =>
|
||||
w.slice(0, w.length - 1).toLowerCase() + w.slice(-1).toUpperCase()
|
||||
),
|
||||
i
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { formatDecimal, formatNumber } from '@polkadot/util';
|
||||
import { formatDecimal, formatNumber } from '..';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type ExecFn = (...params: any[]) => unknown;
|
||||
@@ -85,3 +85,7 @@ export interface IBigIntConstructor {
|
||||
*/
|
||||
asUintN (bits: number, int: bigint): bigint;
|
||||
}
|
||||
|
||||
export interface Observable {
|
||||
next: (...params: unknown[]) => unknown;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ export function u8aCmp (a: HexString | Uint8Array | string, b: HexString | Uint8
|
||||
return 1;
|
||||
} else if (u8aa[i] !== u8ab[i]) {
|
||||
// the number in this index doesn't match
|
||||
// (we don't use u8aa[i] - u8ab[i] since that doesn't match with localeCompare)
|
||||
return u8aa[i] > u8ab[i]
|
||||
? 1
|
||||
: -1;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
import { getRandomValues } from '@polkadot/x-randomvalues';
|
||||
|
||||
import { performance } from '../../test/performance';
|
||||
import { arrayRange } from '../array';
|
||||
import { performance } from '../test/performance';
|
||||
import { u8aConcat } from '.';
|
||||
|
||||
const ptest = arrayRange(10).map(() => randomAsU8a());
|
||||
const ptest = arrayRange(10).map(() => getRandomValues(new Uint8Array(32)));
|
||||
|
||||
describe('u8aConcat', (): void => {
|
||||
it('concatenates arrays', (): void => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performance } from '../../test/performance';
|
||||
import { performance } from '../test/performance';
|
||||
import { u8aEq } from '.';
|
||||
|
||||
const ptest = new Uint8Array(32768);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { performanceCmp } from '../../test/performance';
|
||||
import { performanceCmp } from '../test/performance';
|
||||
import { u8aToHex as u8aToHexBuffer } from './toHexBuffer';
|
||||
import { u8aToHex } from '.';
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user