Compare commits

...
39 Commits
Author SHA1 Message Date
github-actions[bot] 1fdc2c8dae [CI Skip] release/stable 12.2.2
skip-checks: true
2023-06-04 09:06:26 +00:00
Jaco b6a2693e5f 12.2.2 (#1839) 2023-06-04 11:58:18 +03:00
github-actions[bot] 8b3687e062 [CI Skip] bump/beta 12.2.2-7-x
skip-checks: true
2023-06-04 08:30:55 +00:00
Jaco 3a8429b687 Bump noble/{curves, hashes} (#1838) 2023-06-04 11:24:40 +03:00
github-actions[bot] 26e9b01198 [CI Skip] bump/beta 12.2.2-6-x
skip-checks: true
2023-06-02 10:51:44 +00:00
Jaco 76d71d946d Bump deps (w/ TS 5.1) (#1837)
* Bump deps (w/ TS 5.1)

* Adjust fallback

* Revert promisify adjustments
2023-06-02 13:44:54 +03:00
github-actions[bot] 0ebc7bd374 [CI Skip] bump/beta 12.2.2-5-x
skip-checks: true
2023-05-30 08:57:58 +00:00
Jaco d94c126744 Apply missing count assignment in for loops (#1836) 2023-05-30 11:50:04 +03:00
github-actions[bot] 86597dcb17 [CI Skip] bump/beta 12.2.2-4-x
skip-checks: true
2023-05-28 07:53:44 +00:00
Jaco 1be682827b Bump deps (incl Ledger) (#1835) 2023-05-28 10:47:42 +03:00
github-actions[bot] 081b6b4f2b [CI Skip] bump/beta 12.2.2-3-x
skip-checks: true
2023-05-25 07:37:17 +00:00
Jaco 7dc38e78cf jg-bump-deps (#1834) 2023-05-25 10:29:17 +03:00
github-actions[bot] dcf214f250 [CI Skip] bump/beta 12.2.2-2-x
skip-checks: true
2023-05-21 09:48:48 +00:00
Jaco 2e82528e1b Bump dev (w/ eslint config adj) (#1832) 2023-05-21 12:42:39 +03:00
github-actions[bot] 090b91910f [CI Skip] bump/beta 12.2.2-1-x
skip-checks: true
2023-05-18 09:05:38 +00:00
Jaco 058d197646 Adjust tsconfig usage (w/ latest dev) (#1831) 2023-05-18 11:59:17 +03:00
github-actions[bot] 0fca8904e6 [CI Skip] bump/beta 12.2.2-0-x
skip-checks: true
2023-05-18 05:35:04 +00:00
Jaco 0bf7bc416a Bump dev deps (#1830) 2023-05-18 08:29:07 +03:00
github-actions[bot] ea08763307 [CI Skip] release/stable 12.2.1
skip-checks: true
2023-05-13 08:25:36 +00:00
Jaco 5272645abe 12.2.1 (#1829) 2023-05-13 11:17:53 +03:00
Jaco e5373c35c8 Unroll u8aToBigInt loops (#1821)
* Unroll u8aToBigInt loops

* Bump dev

* Rolling tests
2023-05-13 10:51:46 +03:00
github-actions[bot] b73b96e412 [CI Skip] bump/beta 12.1.3-2-x
skip-checks: true
2023-05-06 09:00:28 +00:00
Jaco 18d24bf509 Bump dev (#1827) 2023-05-06 11:52:33 +03:00
github-actions[bot] fe230f143f [CI Skip] bump/beta 12.1.3-1-x
skip-checks: true
2023-05-05 07:07:53 +00:00
Jaco 6357c1e040 Update Constructor interface params (#1823)
* Update Constructor interface params

* Adjust

* Adjust
2023-05-05 10:01:56 +03:00
github-actions[bot] 1876efe13e [CI Skip] bump/beta 12.1.3-0-x
skip-checks: true
2023-05-05 06:46:01 +00:00
Jaco 9de142b5f6 Bump deps (#1826) 2023-05-05 09:39:58 +03:00
github-actions[bot] e5cb0ba2b4 [CI Skip] release/stable 12.1.2
skip-checks: true
2023-05-01 16:14:41 +00:00
Jaco dba5d3e7b3 Fix typings for isChildClass (#1824)
* Fix typings for isChildClass

* Adjust
2023-05-01 19:08:41 +03:00
github-actions[bot] 8ccfecfff8 [CI Skip] bump/beta 12.1.2-0-x
skip-checks: true
2023-04-29 10:42:54 +00:00
Jaco f2e79ffe67 Align u8aToBigInt tests with u8aToBn (#1820)
* Align u8aToBigInt tests with u8aToBn

* Remove unused import
2023-04-29 13:33:53 +03:00
github-actions[bot] e7f595a11f [CI Skip] release/stable 12.1.1
skip-checks: true
2023-04-29 05:50:45 +00:00
Jaco 770471aef0 12.1.1 (#1819) 2023-04-29 08:44:25 +03:00
github-actions[bot] 6b1ff0036e [CI Skip] bump/beta 12.0.2-2-x
skip-checks: true
2023-04-28 06:13:30 +00:00
Jaco fee81b89ac Bump deps (#1818) 2023-04-28 09:07:41 +03:00
github-actions[bot] c4d5b8e1ae [CI Skip] bump/beta 12.0.2-1-x
skip-checks: true
2023-04-26 09:36:39 +00:00
Jaco 5674b1df67 Bump deps w/ export ordering (#1817) 2023-04-26 12:29:21 +03:00
github-actions[bot] 5ccb3e85f8 [CI Skip] bump/beta 12.0.2-0-x
skip-checks: true
2023-04-24 04:59:26 +00:00
Jaco 785a23433d Flatten Buffer | Uint8Array types (#1816)
* Flatten Buffer | Uint8Array types

* Remove dangling Buffer references

* CHANGELOG

* Adjust
2023-04-24 07:53:31 +03:00
153 changed files with 1827 additions and 1021 deletions
-2
View File
@@ -1,2 +0,0 @@
packages/x-noble-hashes/**/*.ts
packages/x-noble-secp256k1/**/*.ts
-22
View File
@@ -1,22 +0,0 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
const base = require('@polkadot/dev/config/eslint.cjs');
module.exports = {
...base,
ignorePatterns: [
...base.ignorePatterns
],
parserOptions: {
...base.parserOptions,
project: [
'./tsconfig.eslint.json'
]
},
rules: {
...base.rules,
// this seems very broken atm, false positives
'@typescript-eslint/unbound-method': 'off'
}
};
+1 -1
View File
@@ -22,5 +22,5 @@ jobs:
- name: ${{ matrix.step }}
if: always()
run: |
yarn install --immutable | grep -v 'YN0013'
yarn install --immutable
yarn ${{ matrix.step }}
+1 -1
View File
@@ -27,5 +27,5 @@ jobs:
node-version: 'lts/*'
- name: ${{ matrix.step }}
run: |
yarn install --immutable | grep -v 'YN0013'
yarn install --immutable
yarn ${{ matrix.step }}
+5
View File
@@ -2,6 +2,11 @@ enableImmutableInstalls: false
enableProgressBars: false
logFilters:
# Discard any "cannot be found in cache" messages
- code: YN0013
level: discard
nodeLinker: node-modules
plugins:
+38
View File
@@ -1,5 +1,43 @@
# CHANGELOG
## 12.2.2 Jun 4, 2023
Changes:
- Apply missing count assignment for `for (...)` loops
- Remove unused `@types/*` dev dependencies
- Upgrade dependencies to latest stable versions
## 12.2.1 May 13, 2023
Changes:
- Align `u8aToBigInt` tests with `u8aToBn`
- Unroll loops on most-frequently used paths for `u8aToBigInt`
- Add `module` to `package.json` export map (ESM-only)
- Upgrade dependencies to latest stable versions
## 12.1.2 May 1, 2023
Changes:
- Adjust typing for `isChildClass` & `Constructor` usage
## 12.1.1 Apr 29, 2023
Changes:
- Add shareable `identity` & `noop` functions
- Flatten `Buffer | Uint8Array` types (as used) to base-only `Uint8Array`
- Apply `readonly` specifiers to private class fields where applicable
- Adjust compilation output for `__internal__` class fields
- Remove unused types from `util`
- Upgrade dependencies to latest stable versions
## 12.0.1 Apr 22, 2023
Contributed:
+1 -1
View File
@@ -1,4 +1,4 @@
1602 Jaco 12.0.1 (#1815)
1622 Jaco 12.2.2 (#1839)
12 Carlo Sala feat(networks): support ledger for pendulum (#1739)
9 Antoine Estienne Add eth uri keyring test (#1291)
6 Amaury Martiny Add tests from Rust (#283)
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2023 @polkadot/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
import baseConfig from '@polkadot/dev/config/eslint';
export default [
...baseConfig
];
+6 -6
View File
@@ -14,10 +14,10 @@
},
"sideEffects": false,
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"versions": {
"git": "12.0.1",
"npm": "12.0.1"
"git": "12.2.2",
"npm": "12.2.2"
},
"workspaces": [
"packages/*"
@@ -37,10 +37,10 @@
"test:one": "polkadot-dev-run-test --env browser"
},
"devDependencies": {
"@polkadot/dev": "^0.73.2",
"@types/node": "^18.15.13"
"@polkadot/dev": "^0.75.16",
"@types/node": "^20.2.5"
},
"resolutions": {
"typescript": "^5.0.4"
"typescript": "^5.1.3"
}
}
+7 -7
View File
@@ -14,18 +14,18 @@
},
"sideEffects": false,
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"browser": "browser.js",
"main": "node.js",
"react-native": "react-native.js",
"dependencies": {
"@ledgerhq/hw-transport": "^6.28.2",
"@ledgerhq/hw-transport-webhid": "^6.27.13",
"@ledgerhq/hw-transport-webusb": "^6.27.13",
"@polkadot/util": "12.0.1",
"tslib": "^2.5.0"
"@ledgerhq/hw-transport": "^6.28.4",
"@ledgerhq/hw-transport-webhid": "^6.27.15",
"@ledgerhq/hw-transport-webusb": "^6.27.15",
"@polkadot/util": "12.2.2",
"tslib": "^2.5.3"
},
"optionalDependencies": {
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.10"
"@ledgerhq/hw-transport-node-hid-singleton": "^6.28.12"
}
}
@@ -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: '12.0.1' };
export const packageInfo = { name: '@polkadot/hw-ledger-transports', path: 'auto', type: 'auto', version: '12.2.2' };
@@ -5,6 +5,9 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/mod.ts"
],
"references": [
{ "path": "../util/tsconfig.build.json" }
]
+4 -4
View File
@@ -17,12 +17,12 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"main": "index.js",
"dependencies": {
"@polkadot/hw-ledger-transports": "12.0.1",
"@polkadot/util": "12.0.1",
"@polkadot/hw-ledger-transports": "12.2.2",
"@polkadot/util": "12.2.2",
"@zondax/ledger-substrate": "^0.40.7",
"tslib": "^2.5.0"
"tslib": "^2.5.3"
}
}
+4 -5
View File
@@ -39,12 +39,11 @@ async function wrapError <T extends WrappedResult> (promise: Promise<T>): Promis
* - Promises reject with errors (unwrapped errors from @zondax/ledger-substrate)
*/
export class Ledger {
readonly #ledgerName: string;
readonly #transportDef: TransportDef;
#app: SubstrateApp | null = null;
#ledgerName: string;
#transportDef: TransportDef;
constructor (transport: TransportType, chain: Chain) {
const ledgerName = ledgerApps[chain];
const transportDef = transports.find(({ type }) => type === transport);
@@ -90,7 +89,7 @@ export class Ledger {
}
/**
* Signs a transcation on the Ledger device
* Signs a transaction on the Ledger device
*/
public async sign (message: Uint8Array, accountOffset = 0, addressOffset = 0, { account = LEDGER_DEFAULT_ACCOUNT, addressIndex = LEDGER_DEFAULT_INDEX, change = LEDGER_DEFAULT_CHANGE }: Partial<AccountOptions> = {}): Promise<LedgerSignature> {
return this.withApp(async (app: SubstrateApp): Promise<LedgerSignature> => {
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '12.0.1' };
export const packageInfo = { name: '@polkadot/hw-ledger', path: 'auto', type: 'auto', version: '12.2.2' };
+4
View File
@@ -5,6 +5,10 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/*.spec.ts",
"**/mod.ts"
],
"references": [
{ "path": "../hw-ledger-transports/tsconfig.build.json" },
{ "path": "../util/tsconfig.build.json" }
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "..",
"outDir": "./build",
"rootDir": "./src",
"emitDeclarationOnly": false,
"noEmit": true
},
"include": [
"**/*.spec.ts"
],
"references": [
{ "path": "../hw-ledger/tsconfig.build.json" }
]
}
+6 -6
View File
@@ -18,15 +18,15 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"main": "index.js",
"dependencies": {
"@polkadot/util": "12.0.1",
"@polkadot/util-crypto": "12.0.1",
"tslib": "^2.5.0"
"@polkadot/util": "12.2.2",
"@polkadot/util-crypto": "12.2.2",
"tslib": "^2.5.3"
},
"peerDependencies": {
"@polkadot/util": "12.0.1",
"@polkadot/util-crypto": "12.0.1"
"@polkadot/util": "12.2.2",
"@polkadot/util-crypto": "12.2.2"
}
}
+6 -6
View File
@@ -1,16 +1,16 @@
// Copyright 2017-2023 @polkadot/keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Keyring } from './keyring.js';
// all external
// eslint-disable-next-line deprecation/deprecation
export { decodeAddress, encodeAddress, setSS58Format } from '@polkadot/util-crypto';
export * from './defaults.js';
export { createPair } from './pair/index.js';
// all named
export { Keyring } from './keyring.js';
export { packageInfo } from './packageInfo.js';
export { createPair } from './pair/index.js';
export { createTestKeyring } from './testing.js';
export { createTestPairs } from './testingPairs.js';
export { Keyring };
// all starred
export * from './defaults.js';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '12.0.1' };
export const packageInfo = { name: '@polkadot/keyring', path: 'auto', type: 'auto', version: '12.2.2' };
+1 -1
View File
@@ -95,7 +95,7 @@ describe('keyring.addFromUri', (): void => {
for (const [type, tests] of Object.entries(TESTS)) {
const keyring = new Keyring({ type: type as KeypairType });
describe(type, (): void => {
describe(`${type}`, (): void => {
tests.forEach(({ pk, ss, uri }): void => {
it(`creates ${uri}`, (): void => {
const pair = keyring.addFromUri(uri, {}, type as KeypairType);
+13 -6
View File
@@ -47,7 +47,7 @@ describe('testingPairs', (): void => {
).toEqual(TEST_ADD);
});
it('checks eth test addresses', (): void => {
describe('checks eth test addresses', (): void => {
const ring = createTestPairs({ type: 'ethereum' });
const keyring = new Keyring({ type: 'ethereum' });
// priv keys generated by ganache-cli --mnemonic "bottom drive obey lake curtain smoke basket hold race lonely fit walk"
@@ -64,10 +64,17 @@ 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));
}
});
Object
.keys(ring)
.filter((_, i) => i < 6)
.forEach((testKeyring, i) => {
it(`checks #${i}`, (): void => {
expect(
u8aToHex(ring[testKeyring].publicKey)
).toEqual(
u8aToHex(keyring.createFromUri(privKeys[i]).publicKey)
);
});
});
});
});
+4
View File
@@ -5,6 +5,10 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/*.spec.ts",
"**/mod.ts"
],
"references": [
{ "path": "../util/tsconfig.build.json" },
{ "path": "../util-crypto/tsconfig.build.json" }
+18
View File
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "..",
"outDir": "./build",
"rootDir": "./src",
"emitDeclarationOnly": false,
"noEmit": true
},
"include": [
"**/*.spec.ts"
],
"references": [
{ "path": "../keyring/tsconfig.build.json" },
{ "path": "../util/tsconfig.build.json" },
{ "path": "../util-crypto/tsconfig.build.json" }
]
}
+5 -5
View File
@@ -15,14 +15,14 @@
},
"sideEffects": false,
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"main": "index.js",
"dependencies": {
"@polkadot/util": "12.0.1",
"@substrate/ss58-registry": "^1.39.0",
"tslib": "^2.5.0"
"@polkadot/util": "12.2.2",
"@substrate/ss58-registry": "^1.40.0",
"tslib": "^2.5.3"
},
"devDependencies": {
"@polkadot/hw-ledger": "12.0.1"
"@polkadot/hw-ledger": "12.2.2"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '12.0.1' };
export const packageInfo = { name: '@polkadot/networks', path: 'auto', type: 'auto', version: '12.2.2' };
+2 -2
View File
@@ -7,7 +7,7 @@ import known from '@substrate/ss58-registry';
import fs from 'node:fs';
import path from 'node:path';
const other = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'packages/networks/src/test/ss58registry.test.json'), 'utf-8')) as unknown;
const other = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'packages/networks/test/ss58registry.json'), 'utf-8')) as unknown;
describe('@substrate/ss58-registry', (): void => {
it('has known values', (): void => {
@@ -22,7 +22,7 @@ describe('@substrate/ss58-registry', (): void => {
throw error;
}
fs.writeFileSync(path.join(process.cwd(), 'packages/networks/src/test/ss58registry.test.json'), json, { flag: 'w' });
fs.writeFileSync(path.join(process.cwd(), 'packages/networks/test/ss58registry.json'), json, { flag: 'w' });
}
});
});
@@ -597,7 +597,7 @@
{
"prefix": 50,
"network": "composable",
"displayName": "Composable",
"displayName": "Composable Finance",
"symbols": [
"LAYR"
],
@@ -716,7 +716,7 @@
{
"prefix": 65,
"network": "aventus",
"displayName": "AvN Mainnet",
"displayName": "Aventus Mainnet",
"symbols": [
"AVT"
],
@@ -1337,6 +1337,19 @@
"standardAccount": "*25519",
"website": "https://explorer.mainnet.cloudwalk.io"
},
{
"prefix": 2021,
"network": "logion",
"displayName": "logion network",
"symbols": [
"LGNT"
],
"decimals": [
18
],
"standardAccount": "*25519",
"website": "https://logion.network"
},
{
"prefix": 2032,
"network": "interlay",
@@ -1640,6 +1653,19 @@
"standardAccount": "*25519",
"website": "https://ata.network"
},
{
"prefix": 12155,
"network": "impact",
"displayName": "Impact Protocol Network",
"symbols": [
"BSTY"
],
"decimals": [
18
],
"standardAccount": "*25519",
"website": "https://impactprotocol.network/"
},
{
"prefix": 12191,
"network": "nftmart",
+4 -3
View File
@@ -5,9 +5,10 @@
"outDir": "./build",
"rootDir": "./src"
},
"include": [
"**/src/**/*.ts",
"**/test/*.json"
"exclude": [
"**/*.spec.ts",
"**/test/*",
"**/mod.ts"
],
"references": [
{ "path": "../hw-ledger/tsconfig.build.json" },
+18
View File
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "..",
"outDir": "./build",
"rootDir": "./src",
"emitDeclarationOnly": false,
"noEmit": true
},
"include": [
"**/*.spec.ts"
],
"references": [
{ "path": "../hw-ledger/tsconfig.build.json" },
{ "path": "../networks/tsconfig.build.json" },
{ "path": "../util/tsconfig.build.json" }
]
}
+11 -11
View File
@@ -20,25 +20,25 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"browser": {
"crypto": false,
"stream": false
},
"main": "index.js",
"dependencies": {
"@noble/curves": "1.0.0",
"@noble/hashes": "1.3.0",
"@polkadot/networks": "12.0.1",
"@polkadot/util": "12.0.1",
"@polkadot/wasm-crypto": "^7.1.1",
"@polkadot/wasm-util": "^7.1.1",
"@polkadot/x-bigint": "12.0.1",
"@polkadot/x-randomvalues": "12.0.1",
"@noble/curves": "1.1.0",
"@noble/hashes": "1.3.1",
"@polkadot/networks": "12.2.2",
"@polkadot/util": "12.2.2",
"@polkadot/wasm-crypto": "^7.2.1",
"@polkadot/wasm-util": "^7.2.1",
"@polkadot/x-bigint": "12.2.2",
"@polkadot/x-randomvalues": "12.2.2",
"@scure/base": "1.1.1",
"tslib": "^2.5.0"
"tslib": "^2.5.3"
},
"peerDependencies": {
"@polkadot/util": "12.0.1"
"@polkadot/util": "12.2.2"
}
}
@@ -5,8 +5,10 @@
import { encodeAddress } from './index.js';
// eslint-disable-next-line jest/no-export
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]);
// eslint-disable-next-line jest/no-export
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 = [
+3 -3
View File
@@ -4,16 +4,16 @@
export { addressToEvm } from './addressToEvm.js';
export { checkAddress } from './check.js';
export { checkAddressChecksum } from './checksum.js';
export { createKeyMulti } from './keyMulti.js';
export { createKeyDerived } from './keyDerived.js';
export { decodeAddress } from './decode.js';
export { deriveAddress } from './derive.js';
export { encodeAddress } from './encode.js';
export { encodeDerivedAddress } from './encodeDerived.js';
export { encodeMultiAddress } from './encodeMulti.js';
export { evmToAddress } from './evmToAddress.js';
export { addressEq } from './eq.js';
export { evmToAddress } from './evmToAddress.js';
export { isAddress } from './is.js';
export { createKeyDerived } from './keyDerived.js';
export { createKeyMulti } from './keyMulti.js';
export { sortAddresses } from './sort.js';
export { validateAddress } from './validate.js';
+1 -1
View File
@@ -71,7 +71,7 @@ export function createValidate ({ chars, ipfs, type }: Config): ValidateFn {
throw new Error(`Expected ipfs-compatible ${type} to start with '${ipfs}'`);
}
for (let i = (ipfsCompat ? 1 : 0); i < value.length; i++) {
for (let i = (ipfsCompat ? 1 : 0), count = value.length; i < count; i++) {
if (!(chars.includes(value[i]) || (
value[i] === '=' && (
(i === value.length - 1) ||
+3 -2
View File
@@ -3,9 +3,10 @@
import './bundleInit.js';
// all named
export { packageInfo } from './packageInfo.js';
// all internal exports
// all starred
export * from './address/index.js';
export * from './base32/index.js';
export * from './base58/index.js';
@@ -20,8 +21,8 @@ export * from './json/index.js';
export * from './keccak/index.js';
export * from './key/index.js';
export * from './mnemonic/index.js';
export * from './networks.js';
export * from './nacl/index.js';
export * from './networks.js';
export * from './pbkdf2/index.js';
export * from './random/index.js';
export * from './scrypt/index.js';
-3
View File
@@ -3,9 +3,6 @@
/// <reference types="@polkadot/dev-test/globals.d.ts" />
// no TS, this is not meant to be a global...
export {};
describe('cryptoWaitReady', (): void => {
it('should return false when it cannot initialize', async (): Promise<void> => {
const old = global.WebAssembly;
+4 -4
View File
@@ -21,14 +21,14 @@ export function createAsHex <T extends (...args: never[]) => Uint8Array> (fn: T)
}
/** @internal */
export function createBitHasher (bitLength: 256 | 512, fn: (data: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512, onlyJs?: boolean) => Uint8Array): (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean) => Uint8Array {
return (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean): Uint8Array =>
export function createBitHasher (bitLength: 256 | 512, fn: (data: HexString | Uint8Array | string, bitLength: 256 | 512, onlyJs?: boolean) => Uint8Array): (data: HexString | Uint8Array | string, onlyJs?: boolean) => Uint8Array {
return (data: HexString | Uint8Array | string, onlyJs?: boolean): Uint8Array =>
fn(data, bitLength, onlyJs);
}
/** @internal */
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 => {
export function createDualHasher (wa: DualHash, js: DualHash): (value: HexString | Uint8Array | string, bitLength?: 256 | 512, onlyJs?: boolean) => Uint8Array {
return (value: HexString | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array => {
const u8a = u8aToU8a(value);
return !hasBigInt || (!onlyJs && isReady())
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { hmacShaAsU8a, hmacSha256AsU8a, hmacSha512AsU8a } from './shaAsU8a.js';
export { hmacSha256AsU8a, hmacSha512AsU8a, hmacShaAsU8a } from './shaAsU8a.js';
+1 -1
View File
@@ -5,4 +5,4 @@
* @summary Create Keccak256/512 values as hex & Uint8Array output
*/
export { keccakAsHex, keccakAsU8a, keccak256AsU8a, keccak512AsU8a } from './asU8a.js';
export { keccak256AsU8a, keccak512AsU8a, keccakAsHex, keccakAsU8a } from './asU8a.js';
@@ -37,13 +37,13 @@ describe('keyExtractPath', (): void => {
expect(test.path[1].chainCode).toEqual(Uint8Array.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
});
it('does not extract from invalid paths', (): void => {
it('does not extract from invalid paths (1)', (): void => {
expect(
(): ExtractResult => keyExtractPath('1/2')
).toThrow(/does not match input/);
});
it('does not extract from invalid paths', (): void => {
it('does not extract from invalid paths (2)', (): void => {
expect(
(): ExtractResult => keyExtractPath('hello')
).toThrow(/does not match input/);
+1 -1
View File
@@ -7,6 +7,6 @@
export { keyExtractPath } from './extractPath.js';
export { keyExtractSuri } from './extractSuri.js';
export { keyFromPath } from './fromPath.js';
export { keyHdkdEcdsa } from './hdkdEcdsa.js';
export { keyHdkdEd25519 } from './hdkdEd25519.js';
export { keyHdkdSr25519 } from './hdkdSr25519.js';
export { keyHdkdEcdsa } from './hdkdEcdsa.js';
@@ -28,7 +28,7 @@ for (const onlyJsMnemonic of [false, true]) {
// NOTE we cannot actually use the onlyJsMnemonic flag here
const mnemonic = mnemonicGenerate(12);
describe(mnemonic, (): void => {
describe(`${mnemonic}`, (): void => {
// do iterations to check and re-check that all matches
for (const count of arrayRange(NUM_CHECKS)) {
it(`check=${count + 1}`, (): void => {
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '12.0.1' };
export const packageInfo = { name: '@polkadot/util-crypto', path: 'auto', type: 'auto', version: '12.2.2' };
+1 -1
View File
@@ -17,7 +17,7 @@ interface Result {
salt: Uint8Array;
}
export function pbkdf2Encode (passphrase?: HexString | Buffer | Uint8Array | string, salt: Buffer | Uint8Array = randomAsU8a(), rounds = 2048, onlyJs?: boolean): Result {
export function pbkdf2Encode (passphrase?: HexString | Uint8Array | string, salt: Uint8Array = randomAsU8a(), rounds = 2048, onlyJs?: boolean): Result {
const u8aPass = u8aToU8a(passphrase);
const u8aSalt = u8aToU8a(salt);
@@ -9,10 +9,13 @@ import { perfWasm } from '../test/index.js';
import { DEFAULT_PARAMS } from './defaults.js';
import { scryptEncode } from './index.js';
// eslint-disable-next-line jest/no-export
export const KNOWN_TEST = 'testing, 123';
// eslint-disable-next-line jest/no-export
export const KNOWN_PASS = new Uint8Array([223, 185, 241, 135, 125, 17, 195, 27, 64, 64, 154, 69, 47, 82, 123, 38, 255, 230, 199, 200, 101, 115, 21, 116, 119, 59, 67, 43, 58, 220, 112, 70, 124, 139, 240, 206, 42, 148, 140, 132, 64, 226, 164, 25, 104, 80, 49, 92, 144, 132, 109, 178, 76, 225, 171, 116, 151, 181, 34, 243, 177, 235, 134, 76]);
// eslint-disable-next-line jest/no-export
export const KNOWN_SALT = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8]);
describe('scryptEncode', (): void => {
+1 -1
View File
@@ -5,4 +5,4 @@
* @summary Implements Sha-256/512 hashing functions for a variety of input and outputs
*/
export { shaAsU8a, sha256AsU8a, sha512AsU8a } from './asU8a.js';
export { sha256AsU8a, sha512AsU8a, shaAsU8a } from './asU8a.js';
@@ -153,6 +153,7 @@ const tests: Test[] = [
]
];
// eslint-disable-next-line jest/no-export
export default tests;
it('has a test', (): void => {
+2
View File
@@ -1,6 +1,8 @@
// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
// all external
export { perf, perfCmp } from '@polkadot/util/test';
// all local
export { perfWasm } from './performance.js';
+1 -1
View File
@@ -23,7 +23,7 @@ import { xxhash64 } from './xxhash64.js';
* xxhashAsU8a('abc'); // => 0x44bc2cf5ad770999
* ```
*/
export function xxhashAsU8a (data: HexString | Buffer | Uint8Array | string, bitLength: 64 | 128 | 192 | 256 | 320 | 384 | 448 | 512 = 64, onlyJs?: boolean): Uint8Array {
export function xxhashAsU8a (data: HexString | Uint8Array | string, bitLength: 64 | 128 | 192 | 256 | 320 | 384 | 448 | 512 = 64, onlyJs?: boolean): Uint8Array {
const rounds = Math.ceil(bitLength / 64);
const u8a = u8aToU8a(data);
+4
View File
@@ -5,6 +5,10 @@
"outDir": "./build",
"rootDir": "./src"
},
"exclude": [
"**/mod.ts",
"**/*.spec.ts"
],
"references": [
{ "path": "../networks/tsconfig.build.json" },
{ "path": "../util/tsconfig.build.json" },
+20
View File
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": "..",
"outDir": "./build",
"rootDir": "./src",
"emitDeclarationOnly": false,
"noEmit": true
},
"include": [
"**/*.spec.ts"
],
"references": [
{ "path": "../networks/tsconfig.build.json" },
{ "path": "../util/tsconfig.build.json" },
{ "path": "../util-crypto/tsconfig.build.json" },
{ "path": "../x-bigint/tsconfig.build.json" },
{ "path": "../x-randomvalues/tsconfig.build.json" }
]
}
+7 -7
View File
@@ -18,7 +18,7 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "12.0.1",
"version": "12.2.2",
"main": "index.js",
"exports": {
"./hex/toU8a": {
@@ -35,15 +35,15 @@
}
},
"dependencies": {
"@polkadot/x-bigint": "12.0.1",
"@polkadot/x-global": "12.0.1",
"@polkadot/x-textdecoder": "12.0.1",
"@polkadot/x-textencoder": "12.0.1",
"@polkadot/x-bigint": "12.2.2",
"@polkadot/x-global": "12.2.2",
"@polkadot/x-textdecoder": "12.2.2",
"@polkadot/x-textencoder": "12.2.2",
"@types/bn.js": "^5.1.1",
"bn.js": "^5.2.1",
"tslib": "^2.5.0"
"tslib": "^2.5.3"
},
"devDependencies": {
"@polkadot/x-randomvalues": "12.0.1"
"@polkadot/x-randomvalues": "12.2.2"
}
}
+1 -1
View File
@@ -18,7 +18,7 @@
export function arrayChunk <T> (array: T[], chunkSize: number): T[][] {
const outputSize = Math.ceil(array.length / chunkSize);
// noop for the single-split case
// shortcut for the single-split case
if (outputSize === 1) {
return [array];
}
+8 -6
View File
@@ -19,28 +19,30 @@
* ```
*/
export function arrayFlatten <T> (arrays: readonly T[][]): T[] {
// noop for the empty & single-entry case
if (arrays.length === 0) {
const num = arrays.length;
// shortcuts for the empty & single-entry case
if (num === 0) {
return [];
} else if (arrays.length === 1) {
} else if (num === 1) {
return arrays[0];
}
// pre-allocate based on the combined size
let size = 0;
for (let i = 0; i < arrays.length; i++) {
for (let i = 0; i < num; i++) {
size += arrays[i].length;
}
const output = new Array<T>(size);
let i = -1;
for (let j = 0; j < arrays.length; j++) {
for (let j = 0; j < num; j++) {
const a = arrays[j];
// instead of pushing, we just set the entries
for (let e = 0; e < a.length; e++) {
for (let e = 0, count = a.length; e < count; e++) {
output[++i] = a[e];
}
}
+2 -2
View File
@@ -12,13 +12,13 @@ describe('arrayRange', (): void => {
).toThrow(/Expected non-zero, positive number as a range size/);
});
it('it creates a range of the specified length', (): void => {
it('creates a range of the specified length', (): void => {
expect(
arrayRange(10)
).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
it('it creates a range of the specified length, with offset', (): void => {
it('creates a range of the specified length, with offset', (): void => {
expect(
arrayRange(7, 3)
).toEqual([3, 4, 5, 6, 7, 8, 9]);
+4 -3
View File
@@ -6,10 +6,11 @@
* @description Splits a single [K, V][] into [K[], V[]]
*/
export function arrayUnzip <K, V> (entries: readonly [K, V][]): [K[], V[]] {
const keys = new Array<K>(entries.length);
const values = new Array<V>(entries.length);
const count = entries.length;
const keys = new Array<K>(count);
const values = new Array<V>(count);
for (let i = 0; i < entries.length; i++) {
for (let i = 0; i < count; i++) {
[keys[i], values[i]] = entries[i];
}
+3 -2
View File
@@ -6,9 +6,10 @@
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
export function arrayZip <K, V> (keys: readonly K[], values: readonly V[]): [K, V][] {
const result = new Array<[K, V]>(keys.length);
const count = keys.length;
const result = new Array<[K, V]>(count);
for (let i = 0; i < keys.length; i++) {
for (let i = 0; i < count; i++) {
result[i] = [keys[i], values[i]];
}
+4 -2
View File
@@ -4,13 +4,15 @@
/** @internal */
export function createCmp <T> (cmp: (a: T, b: T) => boolean): (...items: T[]) => T {
return (...items: T[]): T => {
if (items.length === 0) {
const count = items.length;
if (count === 0) {
throw new Error('Must provide one or more arguments');
}
let result = items[0];
for (let i = 1; i < items.length; i++) {
for (let i = 1; i < count; i++) {
if (cmp(items[i], result)) {
result = items[i];
}
+5 -3
View File
@@ -5,10 +5,12 @@
* @summary Utility methods to convert to and from `bigint` objects
*/
export * from './consts.js';
// all named
export { nMax, nMin } from './min.js';
export { nSqrt } from './sqrt.js';
export { nToBigInt } from './toBigInt.js';
export { nMax, nMin } from './min.js';
export { nToHex } from './toHex.js';
export { nToU8a } from './toU8a.js';
// all starred
export * from './consts.js';
+2 -2
View File
@@ -6,13 +6,13 @@
import { nMax } from './index.js';
describe('nMax', (): void => {
it('finds maximum', (): void => {
it('finds maximum (sorted)', (): void => {
expect(
nMax(1n, 2n, 3n)
).toEqual(3n);
});
it('finds maximum', (): void => {
it('finds maximum (unsorted)', (): void => {
expect(
nMax(2n, 3n, 1n)
).toEqual(3n);
+1
View File
@@ -6,6 +6,7 @@
import { BN } from '../bn/index.js';
import { _sqrt2pow53n, nSqrt } from './index.js';
// eslint-disable-next-line jest/no-export
export const SQRT_TESTS: [string | number | BN | bigint, string | number][] = [
[0, 0],
[1, 1],
+4 -2
View File
@@ -5,8 +5,7 @@
* @summary Utility methods to convert to and from `BN` objects
*/
export * from './consts.js';
// all named
export { BN } from './bn.js';
export { bnFromHex } from './fromHex.js';
export { bnMax, bnMin } from './min.js';
@@ -14,3 +13,6 @@ export { bnSqrt } from './sqrt.js';
export { bnToBn } from './toBn.js';
export { bnToHex } from './toHex.js';
export { bnToU8a } from './toU8a.js';
// all starred
export * from './consts.js';
+2 -2
View File
@@ -6,13 +6,13 @@
import { BN, bnMax } from './index.js';
describe('bnMax', (): void => {
it('finds BN maximum', (): void => {
it('finds BN maximum (sorted)', (): void => {
expect(
bnMax(new BN(1), new BN(2), new BN(3))
).toEqual(new BN(3));
});
it('finds BN maximum', (): void => {
it('finds BN maximum (unsorted)', (): void => {
expect(
bnMax(new BN(2), new BN(3), new BN(1))
).toEqual(new BN(3));
+1 -1
View File
@@ -95,7 +95,7 @@ describe('bnToU8a', (): void => {
).toEqual(new Uint8Array([46, 251, 255, 255]));
});
it('converts negative numbers (LE, bitLength)', (): void => {
it('converts negative numbers (LE, bitLength, check)', (): void => {
expect(
bnToU8a(new BN(-123456), { bitLength: 32, isNegative: true })
).toEqual(new Uint8Array([192, 29, 254, 255]));
+1 -1
View File
@@ -15,6 +15,6 @@
* bufferToU8a(Buffer.from([1, 2, 3]));
* ```
*/
export function bufferToU8a (buffer?: Buffer | number[] | null): Uint8Array {
export function bufferToU8a (buffer?: Uint8Array | number[] | null): Uint8Array {
return new Uint8Array(buffer || []);
}
+4
View File
@@ -4,8 +4,11 @@
/**
* @summary Utility methods for this package are split into groups
*/
// all named
export { packageInfo } from './packageInfo.js';
// all starred
export * from './array/index.js';
export * from './assert.js';
export * from './bi/index.js';
@@ -22,6 +25,7 @@ export * from './lazy.js';
export * from './logger.js';
export * from './memoize.js';
export * from './nextTick.js';
export * from './noop.js';
export * from './number/index.js';
export * from './object/index.js';
export * from './promisify.js';
+2 -2
View File
@@ -31,7 +31,7 @@ describe('compactFromU8a', (): void => {
);
});
it('decodes from same u32 encoded value (short)', (): void => {
it('decodes from same u32 encoded value (short, max)', (): void => {
expect(
compactFromU8a(new Uint8Array([254, 255, 255, 255])).toString()
).toEqual(
@@ -67,7 +67,7 @@ describe('compactFromU8a', (): void => {
).toEqual([7, new BN('5af3107a4000', 16)]);
});
it('decodes an actual value', (): void => {
it('decodes an actual value (100000000)', (): void => {
expect(
compactFromU8a(
hexToU8a('0x0284d717')
+1 -1
View File
@@ -23,6 +23,6 @@
*/
export { compactAddLength } from './addLength.js';
export { compactStripLength } from './stripLength.js';
export { compactFromU8a, compactFromU8aLim } from './fromU8a.js';
export { compactStripLength } from './stripLength.js';
export { compactToU8a } from './toU8a.js';
+13 -1
View File
@@ -6,6 +6,9 @@
import { u8aToHex } from '../u8a/index.js';
import { floatToU8a } from './index.js';
// NOTE Hex value outputs created via online conversion tool:
// https://www.h-schmidt.net/FloatConverter/IEEE754.html
describe('floatToU8a', (): void => {
it('throws on invalid bitLength', (): void => {
expect(
@@ -56,11 +59,20 @@ describe('floatToU8a', (): void => {
foo = 'bar';
}
// https://www.h-schmidt.net/FloatConverter/IEEE754.html
expect(
u8aToHex(floatToU8a(new Test(123.456)))
).toEqual('0x79e9f642');
});
it('encodes String 123.456', (): void => {
class Test extends String {
foo = 'bar';
}
expect(
u8aToHex(floatToU8a(new Test('123.456')))
).toEqual('0x79e9f642');
});
});
});
+2 -4
View File
@@ -1,9 +1,6 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
// eslint-disable-next-line @typescript-eslint/ban-types
type AnyFloat = number | Number;
interface Options {
bitLength?: 32 | 64;
isLe?: boolean;
@@ -14,7 +11,8 @@ interface Options {
* @description Converts a float into a U8a representation (While we don't use BE in SCALE
* we still allow for either representation, although, as elsewhere, isLe is default)
*/
export function floatToU8a (value: string | AnyFloat = 0.0, { bitLength = 32, isLe = true }: Options = {}): Uint8Array {
// eslint-disable-next-line @typescript-eslint/ban-types
export function floatToU8a (value: String | string | number | Number = 0.0, { bitLength = 32, isLe = true }: Options = {}): Uint8Array {
if (bitLength !== 32 && bitLength !== 64) {
throw new Error('Invalid bitLength provided, expected 32 or 64');
}
+1 -1
View File
@@ -31,7 +31,7 @@ export const SI: SiDef[] = [
/** @internal */
export function findSi (type: string): SiDef {
// use a loop here, better RN support (which doesn't have [].find)
for (let i = 0; i < SI.length; i++) {
for (let i = 0, count = SI.length; i < count; i++) {
if (SI[i].value === type) {
return SI[i];
}
+3 -5
View File
@@ -1,6 +1,8 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BufferObjConstructor } from './types.js';
import { BigInt } from '@polkadot/x-bigint';
import { xglobal } from '@polkadot/x-global';
@@ -11,10 +13,6 @@ declare const __dirname: unknown;
declare const module: unknown;
declare const require: unknown;
// We define a scappy low-level interface to mock Buffer
// (this removes the need for the node typings in built bundles)
interface BufTyp extends Function { isBuffer: (value: unknown) => boolean; }
/** true if the environment has proper BigInt support */
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
@@ -34,7 +32,7 @@ export const hasWasm = typeof WebAssembly !== 'undefined';
// that some bundlers such as parcel would add (this is a check, not a use)
/** true if the environment has support for Buffer (typically Node.js) */
export const hasBuffer = typeof xglobal.Buffer === 'function' && typeof (xglobal.Buffer as BufTyp).isBuffer === 'function';
export const hasBuffer = typeof xglobal.Buffer === 'function' && typeof (xglobal.Buffer as unknown as BufferObjConstructor).isBuffer === 'function';
/** true if the environment has process available (typically Node.js) */
export const hasProcess = typeof xglobal.process === 'object';
-6
View File
@@ -68,12 +68,6 @@ describe('hexToU8a', (): void => {
).toEqual(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64]));
});
it.skip('fails when non-hex value provided', (): void => {
expect(
() => hexToU8a('notahex')
).toThrow(/hex value to convert/);
});
perfCmp('hexToU8a', ['hexToU8aBuffer', 'hexToU8a'], 40, [[ptest]], (s: string, isSecond) =>
isSecond
? hexToU8a(s)
+1 -1
View File
@@ -7,7 +7,7 @@ const CHR = '0123456789abcdef';
const U8 = new Uint8Array(256);
const U16 = new Uint8Array(256 * 256);
for (let i = 0; i < CHR.length; i++) {
for (let i = 0, count = CHR.length; i < count; i++) {
U8[CHR[i].charCodeAt(0) | 0] = i | 0;
if (i > 9) {
@@ -35,10 +35,4 @@ describe('hexToU8a', (): void => {
new Uint8Array([128, 0])
);
});
it.skip('fails when non-hex value provided', (): void => {
expect(
() => hexToU8a('notahex')
).toThrow(/hex value to convert/);
});
});
+3 -7
View File
@@ -9,9 +9,7 @@ import { isString } from './string.js';
/** @internal */
function isAsciiStr (str: AnyString): boolean {
const count = str.length | 0;
for (let i = 0; i < count; i++) {
for (let i = 0, count = str.length; i < count; i++) {
const b = str.charCodeAt(i);
// check is inlined here, it is faster than making a call
@@ -24,10 +22,8 @@ function isAsciiStr (str: AnyString): boolean {
}
/** @internal */
function isAsciiBytes (u8a: Uint8Array | Buffer | number[]): boolean {
const count = u8a.length | 0;
for (let i = 0; i < count; i++) {
function isAsciiBytes (u8a: Uint8Array | number[]): boolean {
for (let i = 0, count = u8a.length; i < count; i++) {
const b = u8a[i] | 0;
// check is inlined here, it is faster than making a call
+2 -2
View File
@@ -6,13 +6,13 @@
import { isBigInt } from './index.js';
describe('isBigInt', (): void => {
it('returns true when a BigInt value', (): void => {
it('returns true with a ...n value', (): void => {
expect(
isBigInt(123456n)
).toEqual(true);
});
it('returns true when a BigInt value', (): void => {
it('returns true with a BigInt(...) value', (): void => {
expect(
isBigInt(BigInt(123456))
).toEqual(true);
+3 -6
View File
@@ -1,16 +1,13 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BufferObj, BufferObjConstructor } from '../types.js';
import { xglobal } from '@polkadot/x-global';
import { hasBuffer } from '../has.js';
import { isFunction } from './function.js';
// We define a scappy low-level interface to mock Buffer
// (this removes the need for the node typings in built bundles)
interface BufTyp extends Function { isBuffer: (value: unknown) => boolean }
interface BufObj { readDoubleLE: (...args: unknown[]) => unknown }
/**
* @name isBuffer
* @summary Tests for a `Buffer` object instance.
@@ -27,5 +24,5 @@ interface BufObj { readDoubleLE: (...args: unknown[]) => unknown }
*/
export function isBuffer (value: unknown): value is Buffer {
// we do check a function first, since it is slightly faster than isBuffer itself
return hasBuffer && isFunction(value && (value as unknown as BufObj).readDoubleLE) && (xglobal.Buffer as BufTyp).isBuffer(value);
return hasBuffer && !!value && isFunction((value as unknown as BufferObj).readDoubleLE) && (xglobal.Buffer as unknown as BufferObjConstructor).isBuffer(value);
}
+4 -5
View File
@@ -28,10 +28,9 @@ describe('isChildClass', (): void => {
it('does TS magic, determining type', (): void => {
const T = (class extends BN {}) as unknown;
if (isChildClass(BN, T)) {
expect(new T(12345).toNumber()).toEqual(12345);
} else {
throw new Error('Not a child class');
}
expect(
isChildClass(BN, T) &&
new T(12345).toNumber()
).toEqual(12345);
});
});
+1 -1
View File
@@ -20,7 +20,7 @@ import { isClass } from './class.js';
* console.log('isChildClass', isChildClass(BN, Uint8Array); // => false
* ```
*/
export function isChildClass <P extends Constructor> (Parent: P, Child?: Constructor | null | unknown): Child is P {
export function isChildClass <P extends Constructor> (Parent: P, Child?: unknown): Child is P {
// https://stackoverflow.com/questions/30993434/check-if-a-constructor-inherits-another-in-es6/30993664
return isClass(Child) && isClass(Parent)
// eslint-disable-next-line no-prototype-builtins
+1 -1
View File
@@ -7,6 +7,6 @@ import { isOnFunction } from './helpers.js';
/**
* @name isClass
* Tests if the supplied agrument is a Class
* Tests if the supplied argument is a Class
*/
export const isClass: <T extends Constructor> (value?: unknown) => value is T = /*#__PURE__*/ isOnFunction('isPrototypeOf', 'hasOwnProperty');
+1 -1
View File
@@ -8,8 +8,8 @@ export { isArray } from './array.js';
export { isAscii } from './ascii.js';
export { isBigInt } from './bigInt.js';
export { isBn } from './bn.js';
export { isBuffer } from './buffer.js';
export { isBoolean } from './boolean.js';
export { isBuffer } from './buffer.js';
export { isChildClass } from './childClass.js';
export { isClass } from './class.js';
export { isCodec } from './codec.js';
+1 -1
View File
@@ -26,7 +26,7 @@ describe('isUtf8', (): void => {
expect(isUtf8()).toEqual(false);
});
it('it is valid for ru', (): void => {
it('is valid for ru', (): void => {
expect(isUtf8('Приветствую, ми')).toEqual(true);
});
+1 -1
View File
@@ -14,7 +14,7 @@ import { isString } from './string.js';
* @description
* Checks to see if the input string or Uint8Array is valid Utf8
*/
export function isUtf8 (value?: HexString | number[] | Buffer | Uint8Array | string | null): boolean {
export function isUtf8 (value?: HexString | number[] | Uint8Array | string | null): boolean {
if (!value) {
return isString(value);
}
+1 -1
View File
@@ -55,7 +55,7 @@ export function lazyMethod <T, K, S> (result: Record<string, T> | AnyFn, item: K
* Creates lazy, on-demand getters for the specific values.
*/
export function lazyMethods <T, K, S> (result: Record<string, T>, items: readonly K[], creator: (item: K, index: number, self: S) => T, getName?: (item: K, index: number) => string): Record<string, T> {
for (let i = 0; i < items.length; i++) {
for (let i = 0, count = items.length; i < count; i++) {
lazyMethod(result, items[i], creator, getName, i);
}
+10 -13
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Logger, Logger$Data } from './types.js';
import type { Logger } from './types.js';
import { xglobal } from '@polkadot/x-global';
@@ -14,6 +14,7 @@ import { isU8a } from './is/u8a.js';
import { u8aToHex } from './u8a/toHex.js';
import { u8aToU8a } from './u8a/toU8a.js';
import { hasProcess } from './has.js';
import { noop } from './noop.js';
type ConsoleType = 'error' | 'log' | 'warn';
type LogType = ConsoleType | 'debug';
@@ -65,7 +66,7 @@ function formatWithLength (maxLength: number): (v: unknown) => unknown {
};
}
function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1): void {
function apply (log: LogType, type: string, values: unknown[], maxSize = -1): void {
if (values.length === 1 && isFunction(values[0])) {
const fnResult = values[0]() as unknown;
@@ -81,10 +82,6 @@ function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1):
);
}
function noop (): void {
// noop
}
function isDebugOn (e: string, type: string): boolean {
return !!e && (
e === '*' ||
@@ -149,17 +146,17 @@ function parseEnv (type: string): [boolean, number] {
* const l = logger('test');
* ```
*/
export function logger (_type: string): Logger {
const type = `${_type.toUpperCase()}:`.padStart(16);
const [isDebug, maxSize] = parseEnv(_type.toLowerCase());
export function logger (origin: string): Logger {
const type = `${origin.toUpperCase()}:`.padStart(16);
const [isDebug, maxSize] = parseEnv(origin.toLowerCase());
return {
debug: isDebug
? (...values: Logger$Data) => apply('debug', type, values, maxSize)
? (...values: unknown[]) => apply('debug', type, values, maxSize)
: noop,
error: (...values: Logger$Data) => apply('error', type, values),
log: (...values: Logger$Data) => apply('log', type, values),
error: (...values: unknown[]) => apply('error', type, values),
log: (...values: unknown[]) => apply('log', type, values),
noop,
warn: (...values: Logger$Data) => apply('warn', type, values)
warn: (...values: unknown[]) => apply('warn', type, values)
};
}
+16
View File
@@ -0,0 +1,16 @@
// Copyright 2017-2023 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
/**
* A sharable identity function. Returns the input as-is with no transformation applied.
*/
export function identity <T> (value: T): T {
return value;
}
/**
* A sharable noop function. As the name suggests, does nothing
*/
export function noop (): void {
// noop
}
+1 -1
View File
@@ -8,7 +8,7 @@
export function objectClear <T> (value: Record<string, T>): Record<string, T> {
const keys = Object.keys(value);
for (let i = 0; i < keys.length; i++) {
for (let i = 0, count = keys.length; i < count; i++) {
delete value[keys[i]];
}
+1 -1
View File
@@ -5,6 +5,6 @@ export { objectClear } from './clear.js';
export { objectCopy } from './copy.js';
export { objectEntries } from './entries.js';
export { objectKeys } from './keys.js';
export { objectProperty, objectProperties } from './property.js';
export { objectProperties, objectProperty } from './property.js';
export { objectSpread } from './spread.js';
export { objectValues } from './values.js';
+1 -1
View File
@@ -33,7 +33,7 @@ export function objectProperty <S> (that: object, key: string, getter: (key: str
* @summary Assign get properties on the input object
*/
export function objectProperties <S> (that: object, keys: string[], getter: (key: string, index: number, self: S) => unknown, getName?: (key: string, index: number) => string): void {
for (let i = 0; i < keys.length; i++) {
for (let i = 0, count = keys.length; i < count; i++) {
objectProperty(that, keys[i], getter, getName, i);
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
* @summary Concats all sources into the destination
*/
export function objectSpread <T extends object> (dest: object, ...sources: (object | undefined | null)[]): T {
for (let i = 0; i < sources.length; i++) {
for (let i = 0, count = sources.length; i < count; i++) {
const src = sources[i];
if (src) {
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/util', path: 'auto', type: 'auto', version: '12.0.1' };
export const packageInfo = { name: '@polkadot/util', path: 'auto', type: 'auto', version: '12.2.2' };
+2
View File
@@ -24,6 +24,7 @@ describe('promisify', (): void => {
throw new Error('Received unexpected result');
})
.catch((error: Error): void => {
// eslint-disable-next-line jest/no-conditional-expect
expect(error.message).toEqual('test reject');
});
});
@@ -42,6 +43,7 @@ describe('promisify', (): void => {
cb(new Error(`test reject: ${a},${b.toString()},${c}`));
return promisify(null, fn, 3, 'string', true).catch((error: Error): void => {
// eslint-disable-next-line jest/no-conditional-expect
expect(error.message).toEqual('test reject: 3,string,true');
});
});
+1 -1
View File
@@ -17,7 +17,7 @@
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function promisify <R = any> (self: unknown, fn: (...params: any) => any, ...params: any[]): Promise<R> {
export function promisify <R = any> (self: unknown, fn: (...params: any[]) => any, ...params: any[]): Promise<R> {
return new Promise((resolve, reject): void => {
fn.apply(self, params.concat((error: Error | null, result?: R): void => {
if (error) {
+2 -3
View File
@@ -6,7 +6,7 @@ import type { AnyString } from '../types.js';
export const CC_TO_UP = new Array<string>(256);
export const CC_TO_LO = new Array<string>(256);
for (let i = 0; i < CC_TO_UP.length; i++) {
for (let i = 0, count = CC_TO_UP.length; i < count; i++) {
CC_TO_LO[i] = String.fromCharCode(i).toLowerCase();
CC_TO_UP[i] = String.fromCharCode(i).toUpperCase();
}
@@ -39,10 +39,9 @@ function converter (format: (w: string, i: number) => string): (value: AnyString
.trim()
// split into words
.split(' ');
const count = parts.length;
let result = '';
for (let i = 0; i < count; i++) {
for (let i = 0, count = parts.length; i < count; i++) {
const w = parts[i];
// apply the formatting
+2
View File
@@ -3,6 +3,8 @@
/// <reference types="@polkadot/dev-test/globals.d.ts" />
/* global it, expect */
import { formatDecimal, formatNumber } from '../index.js';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
+21 -36
View File
@@ -5,12 +5,12 @@ import type { BN } from './bn/bn.js';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface Constructor<T = any> {
prototype: T;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new(...value: any[]): T;
new (...args: any[]): T;
hasOwnProperty (prop: string): boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
isPrototypeOf (other: any): boolean;
isPrototypeOf (other: unknown): boolean;
}
export interface ToBigInt {
@@ -27,15 +27,12 @@ export interface SiDef {
value: string;
}
type Logger$Data$Fn = () => unknown[];
export type Logger$Data = (unknown | Logger$Data$Fn)[];
export interface Logger {
debug: (...values: Logger$Data) => void;
error: (...values: Logger$Data) => void;
log: (...values: Logger$Data) => void;
noop: (...values: Logger$Data) => void;
warn: (...values: Logger$Data) => void;
debug: (...values: unknown[]) => void;
error: (...values: unknown[]) => void;
log: (...values: unknown[]) => void;
noop: (...values: unknown[]) => void;
warn: (...values: unknown[]) => void;
}
export interface ToBnOptions {
@@ -56,11 +53,6 @@ export interface NumberOptions extends ToBnOptions {
bitLength?: number;
}
export type BnList = {
0: BN;
1: BN;
} & BN[];
export interface Time {
days: number;
hours: number;
@@ -81,28 +73,21 @@ export type HexDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
// One day when template strings support regex, we can improve this
export type HexString = `0x${string}`;
export type U8aLike = HexString | number[] | Buffer | Uint8Array | AnyString;
export interface IBigIntConstructor {
new (value: string | number | bigint | boolean): bigint;
/**
* Interprets the low bits of a BigInt as a 2's-complement signed integer.
* All higher bits are discarded.
* @param bits The number of low bits to use
* @param int The BigInt whose bits to extract
*/
asIntN (bits: number, int: bigint): bigint;
/**
* Interprets the low bits of a BigInt as an unsigned integer.
* All higher bits are discarded.
* @param bits The number of low bits to use
* @param int The BigInt whose bits to extract
*/
asUintN (bits: number, int: bigint): bigint;
// BufferObj interface compatible with Buffer since we don't want to require
// references to the Buffer types from the node typings
export interface BufferObj extends Uint8Array {
equals: (otherBuffer: Uint8Array) => boolean;
readDoubleLE: (offset?: number) => number;
}
// We define a scappy low-level interface to mock Buffer
// (this removes the need for the node typings in built bundles)
export interface BufferObjConstructor extends Constructor<BufferObj> {
isBuffer: (value: unknown) => boolean;
}
export type U8aLike = HexString | number[] | Uint8Array | AnyString;
export interface Observable {
next: (...params: unknown[]) => unknown;
}
+1 -1
View File
@@ -10,7 +10,7 @@ const ltest = new Uint8Array(32768);
const stest = new Uint8Array(256);
const ztest = new Uint8Array(64);
for (let i = 0; i < ltest.length; i++) {
for (let i = 0, count = ltest.length; i < count; i++) {
if (i < ztest.length) {
ztest[i] = i % 256;
}
+6 -4
View File
@@ -23,10 +23,11 @@ import { u8aToU8a } from './toU8a.js';
* ```
*/
export function u8aConcat (...list: readonly U8aLike[]): Uint8Array {
const u8as = new Array<Uint8Array>(list.length);
const count = list.length;
const u8as = new Array<Uint8Array>(count);
let length = 0;
for (let i = 0; i < list.length; i++) {
for (let i = 0; i < count; i++) {
u8as[i] = u8aToU8a(list[i]);
length += u8as[i].length;
}
@@ -39,17 +40,18 @@ export function u8aConcat (...list: readonly U8aLike[]): Uint8Array {
* @description A strict version of [[u8aConcat]], accepting only Uint8Array inputs
*/
export function u8aConcatStrict (u8as: readonly Uint8Array[], length = 0): Uint8Array {
const count = u8as.length;
let offset = 0;
if (!length) {
for (let i = 0; i < u8as.length; i++) {
for (let i = 0; i < count; i++) {
length += u8as[i].length;
}
}
const result = new Uint8Array(length);
for (let i = 0; i < u8as.length; i++) {
for (let i = 0; i < count; i++) {
result.set(u8as[i], offset);
offset += u8as[i].length;
}
+3 -2
View File
@@ -23,9 +23,10 @@ import { u8aToU8a } from './toU8a.js';
* ```
*/
export function u8aConcat (...list: readonly U8aLike[]): Uint8Array {
const u8as = new Array<Uint8Array>(list.length);
const count = list.length;
const u8as = new Array<Uint8Array>(count);
for (let i = 0; i < list.length; i++) {
for (let i = 0; i < count; i++) {
u8as[i] = u8aToU8a(list[i]);
}

Some files were not shown because too many files have changed in this diff Show More