Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e6d86b768 | ||
|
|
8aab41648e | ||
|
|
4a535c08c7 | ||
|
|
715486d54e | ||
|
|
1073dc14aa | ||
|
|
5cca95e855 | ||
|
|
942b623273 | ||
|
|
eea99656ad | ||
|
|
04b6df9ac5 | ||
|
|
d5132b56de | ||
|
|
1fdc2c8dae | ||
|
|
b6a2693e5f | ||
|
|
8b3687e062 | ||
|
|
3a8429b687 | ||
|
|
26e9b01198 | ||
|
|
76d71d946d | ||
|
|
0ebc7bd374 | ||
|
|
d94c126744 | ||
|
|
86597dcb17 | ||
|
|
1be682827b | ||
|
|
081b6b4f2b | ||
|
|
7dc38e78cf | ||
|
|
dcf214f250 | ||
|
|
2e82528e1b | ||
|
|
090b91910f | ||
|
|
058d197646 | ||
|
|
0fca8904e6 | ||
|
|
0bf7bc416a | ||
|
|
ea08763307 | ||
|
|
5272645abe | ||
|
|
e5373c35c8 | ||
|
|
b73b96e412 | ||
|
|
18d24bf509 | ||
|
|
fe230f143f | ||
|
|
6357c1e040 | ||
|
|
1876efe13e | ||
|
|
9de142b5f6 | ||
|
|
e5cb0ba2b4 | ||
|
|
dba5d3e7b3 | ||
|
|
8ccfecfff8 | ||
|
|
f2e79ffe67 | ||
|
|
e7f595a11f | ||
|
|
770471aef0 | ||
|
|
6b1ff0036e | ||
|
|
fee81b89ac | ||
|
|
c4d5b8e1ae | ||
|
|
5674b1df67 | ||
|
|
5ccb3e85f8 | ||
|
|
785a23433d |
@@ -1,2 +0,0 @@
|
||||
packages/x-noble-hashes/**/*.ts
|
||||
packages/x-noble-secp256k1/**/*.ts
|
||||
@@ -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'
|
||||
}
|
||||
};
|
||||
@@ -22,5 +22,5 @@ jobs:
|
||||
- name: ${{ matrix.step }}
|
||||
if: always()
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn install --immutable
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
@@ -27,5 +27,5 @@ jobs:
|
||||
node-version: 'lts/*'
|
||||
- name: ${{ matrix.step }}
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn install --immutable
|
||||
yarn ${{ matrix.step }}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,5 +1,52 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 12.3.1 Jun 11, 2023
|
||||
|
||||
Changes:
|
||||
|
||||
- Only allow padding characters in base64 strings
|
||||
- Expand typings for keyring meta with known keys
|
||||
- Adjust object index access for stricter tsconfig settings
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
1602 Jaco 12.0.1 (#1815)
|
||||
12 Carlo Sala feat(networks): support ledger for pendulum (#1739)
|
||||
1626 Jaco 12.3.1 (#1845)
|
||||
13 Carlo Sala feat(networks): add zeitgeist Ledger support (#1840)
|
||||
9 Antoine Estienne Add eth uri keyring test (#1291)
|
||||
6 Amaury Martiny Add tests from Rust (#283)
|
||||
5 Jakub Pánik Add HydraDX parachain to genesis (#1583)
|
||||
|
||||
@@ -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
@@ -14,10 +14,10 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"versions": {
|
||||
"git": "12.0.1",
|
||||
"npm": "12.0.1"
|
||||
"git": "12.3.1",
|
||||
"npm": "12.3.1"
|
||||
},
|
||||
"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.19",
|
||||
"@types/node": "^20.3.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,18 +14,18 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"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.3.1",
|
||||
"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.3.1' };
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/mod.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../util/tsconfig.build.json" }
|
||||
]
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/hw-ledger-transports": "12.0.1",
|
||||
"@polkadot/util": "12.0.1",
|
||||
"@polkadot/hw-ledger-transports": "12.3.1",
|
||||
"@polkadot/util": "12.3.1",
|
||||
"@zondax/ledger-substrate": "^0.40.7",
|
||||
"tslib": "^2.5.0"
|
||||
"tslib": "^2.5.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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> => {
|
||||
|
||||
@@ -38,5 +38,6 @@ export const ledgerApps: Record<string, string> = {
|
||||
ternoa: 'Ternoa',
|
||||
unique: 'Unique',
|
||||
vtb: 'VTB',
|
||||
xxnetwork: 'XXNetwork'
|
||||
xxnetwork: 'XXNetwork',
|
||||
zeitgeist: 'Zeitgeist'
|
||||
};
|
||||
|
||||
@@ -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.3.1' };
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
}
|
||||
@@ -18,15 +18,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/util": "12.0.1",
|
||||
"@polkadot/util-crypto": "12.0.1",
|
||||
"tslib": "^2.5.0"
|
||||
"@polkadot/util": "12.3.1",
|
||||
"@polkadot/util-crypto": "12.3.1",
|
||||
"tslib": "^2.5.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "12.0.1",
|
||||
"@polkadot/util-crypto": "12.0.1"
|
||||
"@polkadot/util": "12.3.1",
|
||||
"@polkadot/util-crypto": "12.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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.3.1' };
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
@@ -62,12 +62,20 @@ describe('testingPairs', (): void => {
|
||||
'0x4c42532034540267bf568198ccec4cb822a025da542861fcb146a5fab6433ff8',
|
||||
'0x94c49300a58d576011096bcb006aa06f5a91b34b4383891e8029c21dc39fbb8b'];
|
||||
|
||||
// @ts-expect-error We should not delete from the maps, however this is a test
|
||||
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)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,47 @@
|
||||
// Copyright 2017-2023 @polkadot/keyring authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import type { KeyringOptions, KeyringPair } from './types.js';
|
||||
|
||||
import { nobody } from './pair/nobody.js';
|
||||
import { createTestKeyring } from './testing.js';
|
||||
|
||||
export interface TestKeyringMap {
|
||||
nobody: KeyringPair;
|
||||
|
||||
[index: string]: KeyringPair;
|
||||
}
|
||||
|
||||
export function createTestPairs (options?: KeyringOptions, isDerived = true): TestKeyringMap {
|
||||
export interface TestKeyringMapSubstrate extends TestKeyringMap {
|
||||
alice: KeyringPair;
|
||||
bob: KeyringPair;
|
||||
charlie: KeyringPair;
|
||||
dave: KeyringPair;
|
||||
eve: KeyringPair;
|
||||
ferdie: KeyringPair;
|
||||
}
|
||||
|
||||
export interface TestKeyringMapEthereum extends TestKeyringMap {
|
||||
Alith: KeyringPair;
|
||||
Baltathar: KeyringPair;
|
||||
Charleth: KeyringPair;
|
||||
Dorothy: KeyringPair;
|
||||
Ethan: KeyringPair;
|
||||
Faith: KeyringPair;
|
||||
}
|
||||
|
||||
export type DetectMap<O extends KeyringOptions | undefined> = DetectPairType<O> extends 'ethereum'
|
||||
? TestKeyringMapEthereum
|
||||
: TestKeyringMapSubstrate;
|
||||
|
||||
export type DetectPairType<O extends KeyringOptions | undefined> = O extends KeyringOptions
|
||||
? O['type'] extends KeypairType
|
||||
? O['type']
|
||||
: 'sr25519'
|
||||
: 'sr25519';
|
||||
|
||||
export function createTestPairs <O extends KeyringOptions, M = DetectMap<O>> (options?: O, isDerived = true): M {
|
||||
const keyring = createTestKeyring(options, isDerived);
|
||||
const pairs = keyring.getPairs();
|
||||
const map: TestKeyringMap = { nobody: nobody() };
|
||||
@@ -19,5 +50,5 @@ export function createTestPairs (options?: KeyringOptions, isDerived = true): Te
|
||||
map[p.meta.name as string] = p;
|
||||
}
|
||||
|
||||
return map;
|
||||
return map as M;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,58 @@ export interface KeyringOptions {
|
||||
type?: KeypairType;
|
||||
}
|
||||
|
||||
export type KeyringPair$Meta = Record<string, unknown>;
|
||||
export interface KeyringPair$MetaHardware {
|
||||
accountIndex?: number;
|
||||
accountOffset?: number;
|
||||
addressOffset?: number;
|
||||
hardwareType?: 'ledger';
|
||||
}
|
||||
|
||||
export interface KeyringPair$MetaFlags {
|
||||
isDefaultAuthSelected?: boolean;
|
||||
isExternal?: boolean;
|
||||
isHardware?: boolean;
|
||||
isHidden?: boolean;
|
||||
isInjected?: boolean;
|
||||
isMultisig?: boolean;
|
||||
isProxied?: boolean;
|
||||
isRecent?: boolean;
|
||||
isTesting?: boolean;
|
||||
}
|
||||
|
||||
export interface KeyringPair$MetaContract {
|
||||
abi: string;
|
||||
genesisHash?: HexString | null;
|
||||
}
|
||||
|
||||
export interface KeyringPair$MetaExtension {
|
||||
source?: string;
|
||||
}
|
||||
|
||||
export interface KeyringPair$MetaMultisig {
|
||||
threshold?: number;
|
||||
who?: string[];
|
||||
}
|
||||
|
||||
export interface KeyringPair$MetaParent {
|
||||
parentAddress?: string;
|
||||
parentName?: string;
|
||||
}
|
||||
|
||||
export interface KeyringPair$Meta extends KeyringPair$MetaExtension, KeyringPair$MetaFlags, KeyringPair$MetaHardware, KeyringPair$MetaMultisig, KeyringPair$MetaParent {
|
||||
address?: string;
|
||||
contract?: KeyringPair$MetaContract;
|
||||
genesisHash?: HexString | null;
|
||||
name?: string;
|
||||
suri?: string;
|
||||
tags?: string[];
|
||||
type?: KeypairType;
|
||||
whenCreated?: number;
|
||||
whenEdited?: number;
|
||||
whenUsed?: number;
|
||||
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface KeyringPair$Json extends EncryptedJson {
|
||||
/** The ss58 encoded address or the hex-encoded version (the latter is for ETH-compat chains) */
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
}
|
||||
@@ -15,14 +15,14 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/util": "12.0.1",
|
||||
"@substrate/ss58-registry": "^1.39.0",
|
||||
"tslib": "^2.5.0"
|
||||
"@polkadot/util": "12.3.1",
|
||||
"@substrate/ss58-registry": "^1.40.0",
|
||||
"tslib": "^2.5.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/hw-ledger": "12.0.1"
|
||||
"@polkadot/hw-ledger": "12.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,5 +157,8 @@ export const knownGenesis: KnownGenesis = {
|
||||
],
|
||||
xxnetwork: [
|
||||
'0x50dd5d206917bf10502c68fb4d18a59fc8aa31586f4e8856b493e43544aa82aa'
|
||||
],
|
||||
zeitgeist: [
|
||||
'0x1bf2a2ecb4a868de66ea8610f2ce7c8c43706561b6476031315f6640fe38e060'
|
||||
]
|
||||
};
|
||||
|
||||
@@ -42,5 +42,6 @@ export const knownLedger: KnownLedger = {
|
||||
ternoa: 0x00003e3,
|
||||
unique: 0x00000162,
|
||||
vtb: 0x000002b6,
|
||||
xxnetwork: 0x000007a3
|
||||
xxnetwork: 0x000007a3,
|
||||
zeitgeist: 0x00000162
|
||||
};
|
||||
|
||||
@@ -115,6 +115,6 @@ describe('selectableNetworks', (): void => {
|
||||
|
||||
it('has a sorted list (first external, last external)', (): void => {
|
||||
expect(selectableNetworks[3].displayName).toEqual('3DP network');
|
||||
expect(selectableNetworks[selectableNetworks.length - 1].displayName).toEqual('xx network');
|
||||
expect(selectableNetworks[selectableNetworks.length - 1].displayName).toEqual('Zeitgeist');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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.3.1' };
|
||||
|
||||
@@ -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 => {
|
||||
@@ -16,13 +16,13 @@ describe('@substrate/ss58-registry', (): void => {
|
||||
try {
|
||||
expect(JSON.parse(json)).toEqual(other);
|
||||
} catch (error) {
|
||||
if (process.env.GITHUB_REPOSITORY) {
|
||||
if (process.env['GITHUB_REPOSITORY']) {
|
||||
console.error(json);
|
||||
|
||||
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' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { RegistryEntry } from '@substrate/ss58-registry';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
|
||||
export type Icon = 'beachball' | 'empty' | 'jdenticon' | 'polkadot' | 'substrate';
|
||||
|
||||
@@ -9,7 +10,7 @@ export type KnownIcon = Record<string, Icon>;
|
||||
|
||||
export type KnownLedger = Record<string, number>;
|
||||
|
||||
export type KnownGenesis = Record<string, string[]>;
|
||||
export type KnownGenesis = Record<string, HexString[]>;
|
||||
|
||||
export type KnownSubstrate = RegistryEntry;
|
||||
|
||||
|
||||
+28
-2
@@ -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",
|
||||
@@ -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" },
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
}
|
||||
@@ -20,25 +20,25 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"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.3.1",
|
||||
"@polkadot/util": "12.3.1",
|
||||
"@polkadot/wasm-crypto": "^7.2.1",
|
||||
"@polkadot/wasm-util": "^7.2.1",
|
||||
"@polkadot/x-bigint": "12.3.1",
|
||||
"@polkadot/x-randomvalues": "12.3.1",
|
||||
"@scure/base": "1.1.1",
|
||||
"tslib": "^2.5.0"
|
||||
"tslib": "^2.5.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "12.0.1"
|
||||
"@polkadot/util": "12.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ interface Config {
|
||||
ipfs?: string;
|
||||
regex?: RegExp;
|
||||
type: string;
|
||||
withPadding?: boolean;
|
||||
}
|
||||
|
||||
type DecodeFn = (value: string, ipfsCompat?: boolean) => Uint8Array;
|
||||
@@ -63,7 +64,7 @@ export function createIs (validate: ValidateFn): ValidateFn {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function createValidate ({ chars, ipfs, type }: Config): ValidateFn {
|
||||
export function createValidate ({ chars, ipfs, type, withPadding }: Config): ValidateFn {
|
||||
return (value?: unknown, ipfsCompat?: boolean): value is string => {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error(`Expected ${type} string input`);
|
||||
@@ -71,13 +72,18 @@ 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++) {
|
||||
if (!(chars.includes(value[i]) || (
|
||||
value[i] === '=' && (
|
||||
(i === value.length - 1) ||
|
||||
!chars.includes(value[i + 1])
|
||||
)
|
||||
))) {
|
||||
for (let i = (ipfsCompat ? 1 : 0), count = value.length; i < count; i++) {
|
||||
if (chars.includes(value[i])) {
|
||||
// all ok, character found
|
||||
} else if (withPadding && value[i] === '=') {
|
||||
if (i === count - 1) {
|
||||
// last character, everything ok
|
||||
} else if (value[i + 1] === '=') {
|
||||
// next one is also padding, sequence ok
|
||||
} else {
|
||||
throw new Error(`Invalid ${type} padding sequence "${value[i]}${value[i + 1]}" at index ${i}`);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Invalid ${type} character "${value[i]}" (0x${value.charCodeAt(i).toString(16)}) at index ${i}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
||||
|
||||
import { base58Validate } from './index.js';
|
||||
|
||||
describe('base58Validate', (): void => {
|
||||
it('validates encoded', (): void => {
|
||||
expect(
|
||||
base58Validate('a1UbyspTdnyZXLUQaQbciCxrCWWxz24kgSwGXSQnkbs', false)
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('fails on string with extra padding', (): void => {
|
||||
expect(
|
||||
() => base58Validate('a1UbyspTdnyZXLUQaQbciCxrCWWxz24kgSwGXSQnkbs=', false)
|
||||
).toThrow(/Invalid base58 character "="/);
|
||||
});
|
||||
});
|
||||
@@ -8,7 +8,8 @@ import { createDecode, createEncode, createIs, createValidate } from '../base32/
|
||||
const config = {
|
||||
chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
|
||||
coder: base64,
|
||||
type: 'base64'
|
||||
type: 'base64',
|
||||
withPadding: true
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,4 +11,22 @@ describe('base64Validate', (): void => {
|
||||
() => base64Validate('aGVsbG8gd29ybGQg0J/RgNC40LLQtd^GC0YHRgtCy0YPRjiDQvNC4IOS9oOWlvQ==')
|
||||
).toThrow(/Invalid base64 character "\^" \(0x5e\) at index 30/);
|
||||
});
|
||||
|
||||
it('validates with one extra padding character', (): void => {
|
||||
expect(
|
||||
base64Validate('bGlnaHQgd28=')
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('validates with two extra padding characters', (): void => {
|
||||
expect(
|
||||
base64Validate('bGlnaHQgdw==')
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
it('validates misplaced padding characters', (): void => {
|
||||
expect(
|
||||
() => base64Validate('bGlnaHQgdw=g=')
|
||||
).toThrow(/Invalid base64 padding sequence "=g"/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -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,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';
|
||||
|
||||
@@ -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/);
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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.3.1' };
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": [
|
||||
"**/mod.ts",
|
||||
"**/*.spec.ts"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../networks/tsconfig.build.json" },
|
||||
{ "path": "../util/tsconfig.build.json" },
|
||||
|
||||
@@ -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" }
|
||||
]
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "12.0.1",
|
||||
"version": "12.3.1",
|
||||
"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.3.1",
|
||||
"@polkadot/x-global": "12.3.1",
|
||||
"@polkadot/x-textdecoder": "12.3.1",
|
||||
"@polkadot/x-textencoder": "12.3.1",
|
||||
"@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.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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,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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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]));
|
||||
|
||||
@@ -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,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';
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BufferObjClass } 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 BufferObjClass).isBuffer === 'function';
|
||||
|
||||
/** true if the environment has process available (typically Node.js) */
|
||||
export const hasProcess = typeof xglobal.process === 'object';
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BufferObj, BufferObjClass } 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 BufferObjClass).isBuffer(value);
|
||||
}
|
||||
|
||||
@@ -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,7 +1,7 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor } from '../types.js';
|
||||
import type { Class } from '../types.js';
|
||||
|
||||
import { isClass } from './class.js';
|
||||
|
||||
@@ -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 Class> (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,12 +1,12 @@
|
||||
// Copyright 2017-2023 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor } from '../types.js';
|
||||
import type { Class } from '../types.js';
|
||||
|
||||
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');
|
||||
export const isClass: <T extends Class> (value?: unknown) => value is T = /*#__PURE__*/ isOnFunction('isPrototypeOf', 'hasOwnProperty');
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { lazyMethod, lazyMethods } from './index.js';
|
||||
|
||||
describe('lazyMethod', (): void => {
|
||||
it('adds a key on the object', (): void => {
|
||||
const test: Record<string, unknown> = {};
|
||||
const test: { a?: number } = {};
|
||||
|
||||
expect(test.a).not.toBeDefined();
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('lazyMethod', (): void => {
|
||||
});
|
||||
|
||||
it('allows the name to be retrieved', (): void => {
|
||||
const test: Record<string, unknown> = {};
|
||||
const test: { a?: number } = {};
|
||||
|
||||
expect(test.a).not.toBeDefined();
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('lazyMethod', (): void => {
|
||||
});
|
||||
|
||||
it('calls the getter lazily', (): void => {
|
||||
const test: Record<string, unknown> = {};
|
||||
const test: { a?: number } = {};
|
||||
const getter = jest.fn(() => 123);
|
||||
|
||||
expect(test.a).not.toBeDefined();
|
||||
@@ -41,7 +41,7 @@ describe('lazyMethod', (): void => {
|
||||
});
|
||||
|
||||
it('calls the getter a single time', (): void => {
|
||||
const test: Record<string, unknown> = {};
|
||||
const test: { a?: number } = {};
|
||||
const getter = jest.fn(() => 123);
|
||||
|
||||
lazyMethod(test, 'a', getter);
|
||||
@@ -56,15 +56,16 @@ describe('lazyMethod', (): void => {
|
||||
|
||||
describe('lazyMethods', (): void => {
|
||||
it('sets multiple properties', (): void => {
|
||||
const test: Record<string, unknown> = {};
|
||||
const test: { a?: string; b?: string; c?: string } = {};
|
||||
const getter = jest.fn((name: string) => name);
|
||||
const set = lazyMethods(test, ['a', 'b', 'c'], getter);
|
||||
|
||||
expect(set.a).toEqual('a');
|
||||
expect(set.b).toEqual('b');
|
||||
lazyMethods(test, ['a', 'b', 'c'], getter);
|
||||
|
||||
expect(test.a).toEqual('a');
|
||||
expect(test.b).toEqual('b');
|
||||
expect(getter).toHaveBeenCalledTimes(2);
|
||||
expect(set.a).toEqual('a');
|
||||
expect(set.b).toEqual('b');
|
||||
expect(test.a).toEqual('a');
|
||||
expect(test.b).toEqual('b');
|
||||
expect(getter).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ describe('logger', (): void => {
|
||||
|
||||
beforeEach((): void => {
|
||||
oldEnv = process.env;
|
||||
process.env.NODE_ENV = 'development';
|
||||
process.env['NODE_ENV'] = 'development';
|
||||
|
||||
ln = logger('notDebug');
|
||||
|
||||
process.env.DEBUG = 'test';
|
||||
process.env['DEBUG'] = 'test';
|
||||
|
||||
l = logger('test');
|
||||
|
||||
@@ -114,7 +114,7 @@ describe('logger', (): void => {
|
||||
});
|
||||
|
||||
it('does debug log when DEBUG partial specified', (): void => {
|
||||
process.env.DEBUG = 'test*';
|
||||
process.env['DEBUG'] = 'test*';
|
||||
|
||||
l = logger('testing');
|
||||
l.debug('test');
|
||||
@@ -127,7 +127,7 @@ describe('logger', (): void => {
|
||||
});
|
||||
|
||||
it('does not debug log when non-matching DEBUG specified', (): void => {
|
||||
process.env.DEBUG = 'blah';
|
||||
process.env['DEBUG'] = 'blah';
|
||||
|
||||
l = logger('test');
|
||||
l.debug('test');
|
||||
@@ -136,7 +136,7 @@ describe('logger', (): void => {
|
||||
});
|
||||
|
||||
it('does debug log when DEBUG=* specified', (): void => {
|
||||
process.env.DEBUG = '*';
|
||||
process.env['DEBUG'] = '*';
|
||||
|
||||
l = logger('test');
|
||||
l.debug('test');
|
||||
@@ -160,7 +160,7 @@ describe('logger', (): void => {
|
||||
});
|
||||
|
||||
it('does not debug log when explicitly excluded', (): void => {
|
||||
process.env.DEBUG = '*,-test';
|
||||
process.env['DEBUG'] = '*,-test';
|
||||
|
||||
l = logger('test');
|
||||
l.debug('test');
|
||||
@@ -169,7 +169,7 @@ describe('logger', (): void => {
|
||||
});
|
||||
|
||||
it('does not debug log when part of exclusion group', (): void => {
|
||||
process.env.DEBUG = '*,-test:*';
|
||||
process.env['DEBUG'] = '*,-test:*';
|
||||
|
||||
l = logger('test:sub');
|
||||
l.debug('test');
|
||||
@@ -178,7 +178,7 @@ describe('logger', (): void => {
|
||||
});
|
||||
|
||||
it('does debug log when not part of exclusion groups', (): void => {
|
||||
process.env.DEBUG = '*,-test:*,-tes,-a:*';
|
||||
process.env['DEBUG'] = '*,-test:*,-tes,-a:*';
|
||||
|
||||
l = logger('test');
|
||||
l.debug('test');
|
||||
|
||||
+12
-15
@@ -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 === '*' ||
|
||||
@@ -125,10 +122,10 @@ function getDebugFlag (env: readonly string[], type: string): boolean {
|
||||
|
||||
function parseEnv (type: string): [boolean, number] {
|
||||
const env = (hasProcess ? xglobal.process as { env: Record<string, string> } : {}).env || {};
|
||||
const maxSize = parseInt(env.DEBUG_MAX || '-1', 10);
|
||||
const maxSize = parseInt(env['DEBUG_MAX'] || '-1', 10);
|
||||
|
||||
return [
|
||||
getDebugFlag((env.DEBUG || '').toLowerCase().split(','), type),
|
||||
getDebugFlag((env['DEBUG'] || '').toLowerCase().split(','), type),
|
||||
isNaN(maxSize)
|
||||
? -1
|
||||
: maxSize
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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]];
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user