Add tslint (#151)
This commit is contained in:
+2
-2
@@ -10,13 +10,13 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-ts",
|
||||
"check": "tsc --noEmit",
|
||||
"check": "tslint --project . && tsc --noEmit",
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.20.7",
|
||||
"@polkadot/dev": "^0.20.8",
|
||||
"@polkadot/ts": "^0.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import bnToBn from '@polkadot/util/bn/toBn';
|
||||
|
||||
import extrinsicsRawRoot from './extrinsic/rootRaw';
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
export default function header ({ digest: { logs = [] } = {}, extrinsicsRoot, number, parentHash = new Uint8Array(32), stateRoot = new Uint8Array(32) }: HeaderIncomplete, extrinsics?: Array<UncheckedRaw>): Header {
|
||||
return {
|
||||
digest: {
|
||||
|
||||
@@ -11,6 +11,7 @@ import hashDecode from '../hash/decode';
|
||||
import bnDecode from '../bn/decode';
|
||||
import bytesDecode from '../bytes/decode';
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
export default function headerDecode ({ digest, extrinsicsRoot, number, parentHash, stateRoot }: JsonHeader): Header {
|
||||
return headerBuilder({
|
||||
digest: {
|
||||
|
||||
@@ -9,6 +9,7 @@ import bnEncode from '../bn/encode';
|
||||
import bytesEncode from '../bytes/encode';
|
||||
import hashEncode from '../hash/encode';
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
export default function headerEncode ({ parentHash, number, stateRoot, extrinsicsRoot, digest }: Header): JsonHeader {
|
||||
return {
|
||||
digest: {
|
||||
|
||||
@@ -17,11 +17,13 @@ type RawData = {
|
||||
};
|
||||
|
||||
export default function decodeRaw (u8a: Uint8Array): RawData {
|
||||
// tslint:disable-next-line:variable-name
|
||||
const { body, header, number } = decodeHeader(u8a);
|
||||
const length = u8aToBn(body.subarray(0, 4), true).toNumber();
|
||||
const extrinsics = [];
|
||||
let offset = 4;
|
||||
|
||||
for (let index = 0, offset = 4; index < length; index++) {
|
||||
for (let index = 0; index < length; index++) {
|
||||
const extrinsic = decodeExtrinsic(
|
||||
body.subarray(offset)
|
||||
);
|
||||
|
||||
@@ -10,6 +10,7 @@ import decodeRaw from './decodeRaw';
|
||||
import { OFF_PARENT_HASH, OFF_STATE_ROOT, OFF_TX_ROOT } from './offsets';
|
||||
|
||||
export default function decodeHeader (u8a: Uint8Array): Header {
|
||||
// tslint:disable-next-line:variable-name
|
||||
const { number, logs } = decodeRaw(u8a);
|
||||
|
||||
return createHeader({
|
||||
|
||||
@@ -13,6 +13,7 @@ import u8aToU8a from '@polkadot/util/u8a/toU8a';
|
||||
import encodeArray from '../encoder/array';
|
||||
import encodeU8a from '../encoder/u8a';
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
export default function encodeHeader ({ digest: { logs }, extrinsicsRoot, parentHash, number, stateRoot }: Header, extrinsics?: Array<UncheckedRaw>): Uint8Array {
|
||||
return u8aConcat(
|
||||
u8aToU8a(parentHash),
|
||||
|
||||
@@ -304,7 +304,7 @@ export default class BaseTrie {
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
_findValueNodes (onFound, cb) {
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
this._walkTrie(this.root, (nodeRef, node, key, walkController) => {
|
||||
this._walkTrie(this.root, (nodeRef, node, key, walkController) => { // tslint:disable-line
|
||||
let fullKey = key;
|
||||
|
||||
if (node.key) {
|
||||
@@ -331,7 +331,7 @@ export default class BaseTrie {
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
_findDbNodes (onFound, cb) {
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
this._walkTrie(this.root, (nodeRef, node, key, walkController) => {
|
||||
this._walkTrie(this.root, (nodeRef, node, key, walkController) => { // tslint:disable-line
|
||||
if (isRawNode(nodeRef)) {
|
||||
walkController.next();
|
||||
} else {
|
||||
@@ -509,6 +509,7 @@ export default class BaseTrie {
|
||||
const childKey = key.concat(keyExtension);
|
||||
const priority = childKey.length;
|
||||
|
||||
// tslint:disable-next-line
|
||||
taskExecutor(priority, async (taskCallback) => {
|
||||
const childNode = await self._lookupNode(childRef);
|
||||
|
||||
@@ -527,6 +528,7 @@ export default class BaseTrie {
|
||||
|
||||
const priority = childKey.length;
|
||||
|
||||
// tslint:disable-next-line
|
||||
taskExecutor(priority, async (taskCallback) => {
|
||||
const childNode = await self._lookupNode(childRef);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export default class CheckpointTrie extends BaseTrie {
|
||||
_checkpoints: Array<Uint8Array>;
|
||||
_scratch: any; // FIXME
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
__putDBs: any[]; // FIXME
|
||||
__putDBs: any[]; // tslint:disable-line
|
||||
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
constructor (db, root: Uint8Array) {
|
||||
|
||||
@@ -106,7 +106,7 @@ export default class TrieNode {
|
||||
}
|
||||
}
|
||||
|
||||
getKey () {
|
||||
getKey () {
|
||||
if (this.type !== 'branch') {
|
||||
return removeHexPrefix(
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
@@ -153,7 +153,9 @@ export default class TrieNode {
|
||||
children.push([this.key, this.getValue()]);
|
||||
break;
|
||||
case 'branch':
|
||||
for (let index = 0, end = 16; index < end; index++) {
|
||||
let end = 16;
|
||||
|
||||
for (let index = 0; index < end; index++) {
|
||||
const value = this.getValue(index);
|
||||
|
||||
if (value) {
|
||||
|
||||
@@ -5,10 +5,8 @@
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
import { LevelUp$AbstractStorage } from 'levelup';
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
import { EncoderBufferOptions, EncodingBuffer } from 'encoding-down';
|
||||
import encodingDown, { EncoderBufferOptions, EncodingBuffer } from 'encoding-down';
|
||||
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
import encodingDown from 'encoding-down';
|
||||
import logger from '@polkadot/util/logger';
|
||||
|
||||
import decode from './decode';
|
||||
|
||||
@@ -46,14 +46,14 @@ export default async function verifyProof (rootHash, _key, proofs) {
|
||||
|
||||
if (cld.length === 2) {
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
const embeddedNode = nodeFactory.fromRaw(cld);
|
||||
const embeddedNode = nodeFactory.fromRaw(cld);
|
||||
|
||||
assert(i === lastIndex, 'Additional nodes at end of proof (embeddedNode)');
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
assert(nibblesMatchingLength(embeddedNode.key, key) === embeddedNode.key.length, 'Key length does not match with the proof one (embeddedNode)');
|
||||
assert(nibblesMatchingLength(embeddedNode.key, key) === embeddedNode.key.length, 'Key length does not match with the proof one (embeddedNode)');
|
||||
|
||||
// @ts-ignore FIXME, we need to properly check the full file
|
||||
key = key.slice(embeddedNode.key.length);
|
||||
key = key.slice(embeddedNode.key.length);
|
||||
|
||||
assert(key.length === 0, 'Key does not match with the proof one (embeddedNode)');
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ type Task = {
|
||||
fn: Task$Fn,
|
||||
priority: number,
|
||||
reject: (error: Error) => void,
|
||||
resolve: (value: any) => void,
|
||||
}
|
||||
resolve: (value: any) => void
|
||||
};
|
||||
|
||||
// https://github.com/ethereumjs/merkle-patricia-tree/pull/38
|
||||
export default function taskExecutor (maxPoolSize: number) {
|
||||
|
||||
@@ -6,8 +6,8 @@ import trieRoot from './root';
|
||||
import trieRootOrdered from './rootOrdered';
|
||||
|
||||
/**
|
||||
@summary Utility methods to create [Ethereum Trie hashes](https://github.com/ethereum/wiki/wiki/Patricia-Tree)
|
||||
*/
|
||||
* @summary Utility methods to create [Ethereum Trie hashes](https://github.com/ethereum/wiki/wiki/Patricia-Tree)
|
||||
*/
|
||||
export {
|
||||
trieRoot,
|
||||
trieRootOrdered
|
||||
|
||||
@@ -9,20 +9,20 @@ import genRoot from './util/genRoot';
|
||||
import pairsUniq from './util/pairsUniq';
|
||||
|
||||
/**
|
||||
@name trieRoot
|
||||
@signature trieRoot (pairs: Trie$Pairs): Uint8Array
|
||||
@summary Creates a trie hash from the supplied pairs.
|
||||
@description
|
||||
From an `Array<{k: Uint8Array, v: Uint8Array}>` input, calculate the triehash and return the result as a `Uint8Array`.
|
||||
@example
|
||||
import { u8aFromString } from '@polkadot/util';
|
||||
import { trieRoot } from '@polkadot/trie-hash';
|
||||
|
||||
trieRoot([{
|
||||
k: u8aFromString('A'),
|
||||
v: u8aFromString('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
||||
}]) // => 0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab
|
||||
*/
|
||||
* @name trieRoot
|
||||
* @signature trieRoot (pairs: Trie$Pairs): Uint8Array
|
||||
* @summary Creates a trie hash from the supplied pairs.
|
||||
* @description
|
||||
* From an `Array<{k: Uint8Array, v: Uint8Array}>` input, calculate the triehash and return the result as a `Uint8Array`.
|
||||
* @example
|
||||
* import { u8aFromString } from '@polkadot/util';
|
||||
* import { trieRoot } from '@polkadot/trie-hash';
|
||||
*
|
||||
* trieRoot([{
|
||||
* k: u8aFromString('A'),
|
||||
* v: u8aFromString('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
||||
* }]) // => 0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab
|
||||
*/
|
||||
export default function trieRoot (pairs: Trie$Pairs): Uint8Array {
|
||||
return genRoot(
|
||||
pairsUniq(pairs).map(({ k, v }) => ({
|
||||
|
||||
@@ -8,20 +8,20 @@ import genRoot from './util/genRoot';
|
||||
import pairsUniq from './util/pairsUniq';
|
||||
|
||||
/**
|
||||
@name trieRootOrdered
|
||||
@signature trieRootOrdered (values: Array<Uint8Array>): Uint8Array
|
||||
@summary Creates a trie hash from the supplied values.
|
||||
@description
|
||||
From an `Array<Uint8Array>` input, calculate the ordered triehash and return the result as a `Uint8Array`.
|
||||
@example
|
||||
import { u8aFromString } from '@polkadot/util';
|
||||
import { trieRootOrdered } from '@polkadot/trie-hash';
|
||||
|
||||
trieRootOrdered([
|
||||
u8aFromString('doe'),
|
||||
u8aFromString('reindeer')
|
||||
]) // => 0xe766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3
|
||||
*/
|
||||
* @name trieRootOrdered
|
||||
* @signature trieRootOrdered (values: Array<Uint8Array>): Uint8Array
|
||||
* @summary Creates a trie hash from the supplied values.
|
||||
* @description
|
||||
* From an `Array<Uint8Array>` input, calculate the ordered triehash and return the result as a `Uint8Array`.
|
||||
* @example
|
||||
* import { u8aFromString } from '@polkadot/util';
|
||||
* import { trieRootOrdered } from '@polkadot/trie-hash';
|
||||
*
|
||||
* trieRootOrdered([
|
||||
* u8aFromString('doe'),
|
||||
* u8aFromString('reindeer')
|
||||
* ]) // => 0xe766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3
|
||||
*/
|
||||
export default function trieRootOrdered (values: Array<Uint8Array>): Uint8Array {
|
||||
return genRoot(
|
||||
pairsUniq(
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name asNibbles
|
||||
@signature asNibbles (pairs: Trie$Pairs): Uint8Array
|
||||
@summary Converts the input to Nibbles.
|
||||
@description
|
||||
From an `Uint8Array` input, calculate and return a list of nibbles that makes up the input.
|
||||
@example
|
||||
import { asNibbles } from '@polkadot/trie-hash/util';
|
||||
|
||||
asNibbles(new Uint8Array([0x41, 0x20]) // => Uint8Array([4, 1, 2, 0])
|
||||
*/
|
||||
* @name asNibbles
|
||||
* @signature asNibbles (pairs: Trie$Pairs): Uint8Array
|
||||
* @summary Converts the input to Nibbles.
|
||||
* @description
|
||||
* From an `Uint8Array` input, calculate and return a list of nibbles that makes up the input.
|
||||
* @example
|
||||
* import { asNibbles } from '@polkadot/trie-hash/util';
|
||||
*
|
||||
* asNibbles(new Uint8Array([0x41, 0x20]) // => Uint8Array([4, 1, 2, 0])
|
||||
*/
|
||||
export default function asNibbles (bytes: Uint8Array | Array<number>): Uint8Array {
|
||||
// HACK TypeScript gets a little bit confused as to what to apply, hence casting here although the reduces function for both types does exactly the same
|
||||
return (bytes as number[]).reduce((result, byte, index) => {
|
||||
|
||||
@@ -18,8 +18,8 @@ const submitExtrinsic: CreateItemOptions = {
|
||||
};
|
||||
|
||||
/**
|
||||
@summary Methods to work with authors & contributors.
|
||||
*/
|
||||
* @summary Methods to work with authors & contributors.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Authoring of network items',
|
||||
|
||||
@@ -30,8 +30,8 @@ const newHead: CreateItemOptions = {
|
||||
};
|
||||
|
||||
/**
|
||||
@summary Methods to retrieve chain data.
|
||||
*/
|
||||
* @summary Methods to retrieve chain data.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Retrieval of chain data',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { Interfaces, Interface$Sections } from './types';
|
||||
import { Interfaces } from './types';
|
||||
|
||||
import author from './author';
|
||||
import chain from './chain';
|
||||
|
||||
@@ -79,8 +79,8 @@ const getStorageSizeAt: CreateItemOptions = {
|
||||
};
|
||||
|
||||
/**
|
||||
@summary Query the state and state storage.
|
||||
*/
|
||||
* @summary Query the state and state storage.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Query of state',
|
||||
|
||||
@@ -26,8 +26,8 @@ const version: CreateItemOptions = {
|
||||
};
|
||||
|
||||
/**
|
||||
@summary Methods to retrieve system info.
|
||||
*/
|
||||
* @summary Methods to retrieve system info.
|
||||
*/
|
||||
export default (sname: Interface$Sections): Section<Interfaces> =>
|
||||
createSection(sname)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Methods to retrieve system info',
|
||||
|
||||
@@ -49,9 +49,9 @@ export default function decode (type: Param$Types, input: Uint8Array, version: E
|
||||
if (Array.isArray(type)) {
|
||||
// Arrays have single entries, Tuples will have multiple types
|
||||
if (type.length === 1) {
|
||||
return decodeArray((type as Param$Type$Array), input, version);
|
||||
return decodeArray(type, input, version);
|
||||
} else {
|
||||
return decodeTuple((type as Param$Type$Array), input, version);
|
||||
return decodeTuple(type, input, version);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,8 @@ export default function decodeValue (decode: Decoder, type: Param$Type, input: U
|
||||
return byte(input);
|
||||
|
||||
default:
|
||||
(type as never); // eslint-disable-line no-unused-expressions
|
||||
// tslint:disable-next-line
|
||||
(type as never);
|
||||
throw new Error(`No value decoder for type='${type}'`);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -90,7 +90,8 @@ export default function encodeType (type: Param$Type, value: any, version: Encod
|
||||
return bnToU8a(value || 0, 8, true);
|
||||
|
||||
default:
|
||||
(type as never); // eslint-disable-line no-unused-expressions
|
||||
// tslint:disable-next-line
|
||||
(type as never);
|
||||
throw new Error(`No formatter for ${type}`);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -7,16 +7,16 @@ import { SectionItem } from './types';
|
||||
import typeToString from './typeToString';
|
||||
|
||||
/**
|
||||
@name signature
|
||||
@signature jsonrpcSignature (method: InterfaceMethodDefinition): string
|
||||
@summary Returns a string representation of the method with inputs and outputs.
|
||||
@description
|
||||
Formats the name, inputs and outputs into a human-readable string. This contains the input parameter names, input types and output type.
|
||||
@example
|
||||
import signature from '@polkadot/params/signature';
|
||||
|
||||
console.log(signature({ name: 'test_method', params: [ { name: 'dest', type: 'Address' } ], type: 'Address' })); // => test_method (dest: Address): Address
|
||||
*/
|
||||
* @name signature
|
||||
* @signature jsonrpcSignature (method: InterfaceMethodDefinition): string
|
||||
* @summary Returns a string representation of the method with inputs and outputs.
|
||||
* @description
|
||||
* Formats the name, inputs and outputs into a human-readable string. This contains the input parameter names input types and output type.
|
||||
* @example
|
||||
* import signature from '@polkadot/params/signature';
|
||||
*
|
||||
* signature({ name: 'test_method', params: [ { name: 'dest', type: 'Address' } ], type: 'Address' }); // => test_method (dest: Address): Address
|
||||
*/
|
||||
export default function signature<T> ({ name, params, type }: SectionItem<T>): string {
|
||||
const inputs = params.map(({ name, type }) =>
|
||||
`${name}: ${typeToString(type)}`
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { SizeType } from '@polkadot/primitives/sizes';
|
||||
import sizes, { SizeType } from '@polkadot/primitives/sizes';
|
||||
import { EncodingVersions } from './types';
|
||||
|
||||
import sizes from '@polkadot/primitives/sizes';
|
||||
|
||||
const Balance: Map<EncodingVersions, SizeType> = new Map([
|
||||
['latest' as EncodingVersions, sizes.Balance],
|
||||
['poc-1' as EncodingVersions, 64 as SizeType]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CreateItems, CreateItemOptions, Section } from '@polkadot/params/types';
|
||||
import { Storages, Storage$Sections } from './types';
|
||||
import { Storages } from './types';
|
||||
|
||||
import param from '@polkadot/params/param';
|
||||
import createSection from '@polkadot/params/section';
|
||||
|
||||
@@ -73,7 +73,8 @@ export default function formatParams (params: Params, values: Storage$Key$Value[
|
||||
return bnToU8a((value as Date).getTime(), 64, true);
|
||||
|
||||
default:
|
||||
(type as never); // eslint-disable-line
|
||||
// tslint:disable-next-line
|
||||
(type as never);
|
||||
throw new Error('Unable to find handler');
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { CreateItems, CreateItemOptions, Param$Type, Section } from '@polkadot/params/types';
|
||||
import { CreateItems, CreateItemOptions, Section } from '@polkadot/params/types';
|
||||
import { Storages, Storage$Sections } from './types';
|
||||
|
||||
import param from '@polkadot/params/param';
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import blake2bAsHex from './blake2b/asHex';
|
||||
|
||||
/**
|
||||
@name blake2AsHex
|
||||
@signature blake2AsHex (data: Uint8Array, bitLenght: number = 256): string
|
||||
@summary Creates a blake2b hex from the input.
|
||||
@description
|
||||
From a `Uint8Array` input, create the blake2b and return the result as a hex string with the specified `bitLength`.
|
||||
@example
|
||||
import { blake2AsHex } from '@polkadot/util-crypto';
|
||||
|
||||
blake2AsHex('abc') // => 0xba80a53f981c4d0d
|
||||
*/
|
||||
* @name blake2AsHex
|
||||
* @signature blake2AsHex (data: Uint8Array, bitLenght: number = 256): string
|
||||
* @summary Creates a blake2b hex from the input.
|
||||
* @description
|
||||
* From a `Uint8Array` input, create the blake2b and return the result as a hex string with the specified `bitLength`.
|
||||
* @example
|
||||
* import { blake2AsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* blake2AsHex('abc') // => 0xba80a53f981c4d0d
|
||||
*/
|
||||
export default function blake2AsHex (data: Uint8Array, bitLength: number = 256): string {
|
||||
return blake2bAsHex(data, bitLength);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import blake2bAsU8a from './blake2b/asU8a';
|
||||
|
||||
/**
|
||||
@name blake2AsU8a
|
||||
@signature blake2AsU8a (data: Uint8Array, bitLenght: number = 256): Uint8Array
|
||||
@summary Creates a blake2b u8a from the input.
|
||||
@description
|
||||
From a `Uint8Array` input, create the blake2b and return the result as a u8a with the specified `bitLength`.
|
||||
@example
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
blake2AsU8a('abc') // => [0xba, 0x80, 0xa53, 0xf98, 0x1c, 0x4d, 0x0d]
|
||||
*/
|
||||
* @name blake2AsU8a
|
||||
* @signature blake2AsU8a (data: Uint8Array, bitLenght: number = 256): Uint8Array
|
||||
* @summary Creates a blake2b u8a from the input.
|
||||
* @description
|
||||
* From a `Uint8Array` input, create the blake2b and return the result as a u8a with the specified `bitLength`.
|
||||
* @example
|
||||
* import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* blake2AsU8a('abc') // => [0xba, 0x80, 0xa53, 0xf98, 0x1c, 0x4d, 0x0d]
|
||||
*/
|
||||
export default function blake2AsU8a (data: Uint8Array, bitLength: number = 256, key?: Uint8Array): Uint8Array {
|
||||
return blake2bAsU8a(data, bitLength, key);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import blake2bAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@name blake2bAsHex
|
||||
@signature blake2bAsHex (value: Uint8Array): string
|
||||
@summary Creates a blake2b hex string from the input.
|
||||
@description
|
||||
From a `Uint8Array` input, create the blake2b and return the result as a hex string.
|
||||
@example
|
||||
import { blake2bAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
blake2bAsHex('abc') // => '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923'
|
||||
*/
|
||||
* @name blake2bAsHex
|
||||
* @signature blake2bAsHex (value: Uint8Array): string
|
||||
* @summary Creates a blake2b hex string from the input.
|
||||
* @description
|
||||
* From a `Uint8Array` input, create the blake2b and return the result as a hex string.
|
||||
* @example
|
||||
* import { blake2bAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* blake2bAsHex('abc') // => '0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923'
|
||||
*/
|
||||
export default function blake2bAsHex (data: Uint8Array, bitLength: number = 512): string {
|
||||
return u8aToHex(
|
||||
blake2bAsU8a(data, bitLength)
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
import blakejs from 'blakejs';
|
||||
|
||||
/**
|
||||
@name blake2bAsU8a
|
||||
@signature blake2bAsU8a (value: Uint8Array): Uint8Array
|
||||
@summary Creates a blake2b Uint8Array from the input.
|
||||
@description
|
||||
From a `Uint8Array` input, create the blake2b and return the result as a `Uint8Array`.
|
||||
@example
|
||||
import { blake2bAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
blake2bAsU8a('abc') // => Uint8Array('508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982')
|
||||
*/
|
||||
* @name blake2bAsU8a
|
||||
* @signature blake2bAsU8a (value: Uint8Array): Uint8Array
|
||||
* @summary Creates a blake2b Uint8Array from the input.
|
||||
* @description
|
||||
* From a `Uint8Array` input, create the blake2b and return the result as a `Uint8Array`.
|
||||
* @example
|
||||
* import { blake2bAsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* blake2bAsU8a('abc') // => Uint8Array('508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982')
|
||||
*/
|
||||
export default function blake2bAsU8a (data: Uint8Array, bitLength: number = 512, key: Uint8Array | null = null): Uint8Array {
|
||||
return blakejs.blake2b(data, key, bitLength / 8);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import blake2bAsHex from './asHex';
|
||||
import blake2bAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@summary Create [Blake2b](https://blake2.net/) values as hex & Uint8Array output
|
||||
*/
|
||||
* @summary Create [Blake2b](https://blake2.net/) values as hex & Uint8Array output
|
||||
*/
|
||||
export {
|
||||
blake2bAsHex,
|
||||
blake2bAsU8a
|
||||
|
||||
@@ -6,8 +6,8 @@ import blake2AsHex from './asHex';
|
||||
import blake2AsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@summary Create blake2b values with specified bitlengths
|
||||
*/
|
||||
* @summary Create blake2b values with specified bitlengths
|
||||
*/
|
||||
export {
|
||||
blake2AsHex,
|
||||
blake2AsU8a
|
||||
|
||||
@@ -7,16 +7,16 @@ import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import keccakAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@name keccakAsHex
|
||||
@signature keccakAsHex (value: Buffer | Uint8Array | string): string
|
||||
@summary Creates a keccak hex string from the input.
|
||||
@description
|
||||
From either a `string` or a `Buffer` input, create the keccak and return the result as a `0x` prefixed hex string.
|
||||
@example
|
||||
import { keccakAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
keccakAsHex('123') // => 0x...
|
||||
*/
|
||||
* @name keccakAsHex
|
||||
* @signature keccakAsHex (value: Buffer | Uint8Array | string): string
|
||||
* @summary Creates a keccak hex string from the input.
|
||||
* @description
|
||||
* From either a `string` or a `Buffer` input, create the keccak and return the result as a `0x` prefixed hex string.
|
||||
* @example
|
||||
* import { keccakAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* keccakAsHex('123') // => 0x...
|
||||
*/
|
||||
export default function keccakAsHex (value: Buffer | Uint8Array | string): string {
|
||||
return u8aToHex(
|
||||
keccakAsU8a(value)
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import { keccak256 } from 'js-sha3';
|
||||
|
||||
/**
|
||||
@name keccakAsU8a
|
||||
@signature keccakAsU8a (value: Buffer | Uint8Array | string): Uint8Array
|
||||
@summary Creates a keccak Uint8Array from the input.
|
||||
@description
|
||||
From either a `string` or a `Buffer` input, create the keccak and return the result as a `Uint8Array`.
|
||||
@example
|
||||
import { keccakAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
keccakAsU8a('123') // => Uint8Array
|
||||
*/
|
||||
* @name keccakAsU8a
|
||||
* @signature keccakAsU8a (value: Buffer | Uint8Array | string): Uint8Array
|
||||
* @summary Creates a keccak Uint8Array from the input.
|
||||
* @description
|
||||
* From either a `string` or a `Buffer` input, create the keccak and return the result as a `Uint8Array`.
|
||||
* @example
|
||||
* import { keccakAsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* keccakAsU8a('123') // => Uint8Array
|
||||
*/
|
||||
export default function keccakAsU8a (value: Buffer | Uint8Array | string): Uint8Array {
|
||||
return new Uint8Array(
|
||||
keccak256.update(value).arrayBuffer()
|
||||
|
||||
@@ -6,8 +6,8 @@ import keccakAsHex from './asHex';
|
||||
import keccakAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@summary Create Keccak256 values as hex & Uint8Array output
|
||||
*/
|
||||
* @summary Create Keccak256 values as hex & Uint8Array output
|
||||
*/
|
||||
export {
|
||||
keccakAsHex,
|
||||
keccakAsU8a
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name naclDecrypt
|
||||
@signature naclDecrypt (message: Uint8Array, nonce: Uint8Array, secret: Uint8Array): Uint8Array
|
||||
@summary Decrypts a message using the supplied secretKey and nonce
|
||||
@description
|
||||
Returns an decrypted message, using the `secret` and `nonce`.
|
||||
@example
|
||||
import { naclDecrypt } from '@polkadot/util-crypto';
|
||||
|
||||
naclDecrypt([...], [...], [...]) // => [...]
|
||||
*/
|
||||
* @name naclDecrypt
|
||||
* @signature naclDecrypt (message: Uint8Array, nonce: Uint8Array, secret: Uint8Array): Uint8Array
|
||||
* @summary Decrypts a message using the supplied secretKey and nonce
|
||||
* @description
|
||||
* Returns an decrypted message, using the `secret` and `nonce`.
|
||||
* @example
|
||||
* import { naclDecrypt } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclDecrypt([...], [...], [...]) // => [...]
|
||||
*/
|
||||
export default function naclDecrypt (encrypted: Uint8Array, nonce: Uint8Array, secret: Uint8Array): Uint8Array | null {
|
||||
return nacl.secretbox.open(encrypted, nonce, secret);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ type Encrypted = {
|
||||
};
|
||||
|
||||
/**
|
||||
@name naclEncrypt
|
||||
@signature naclEncrypt (message: Uint8Array, secret: Uint8Array, nonce?: Uint8Array): { encrypted: Uint8Array, nonce: Uint8Array }
|
||||
@summary Encrypts a message using the supplied secretKey and nonce
|
||||
@description
|
||||
Returns an encrypted message, using the `secretKey` and `nonce`. If the `nonce` was not supplied, a random value is generated.
|
||||
@example
|
||||
import { naclEncrypt } from '@polkadot/util-crypto';
|
||||
|
||||
naclSign([...], [...]) // => [...]
|
||||
*/
|
||||
* @name naclEncrypt
|
||||
* @signature naclEncrypt (message: Uint8Array, secret: Uint8Array, nonce?: Uint8Array): { encrypted: Uint8Array, nonce: Uint8Array }
|
||||
* @summary Encrypts a message using the supplied secretKey and nonce
|
||||
* @description
|
||||
* Returns an encrypted message, using the `secretKey` and `nonce`. If the `nonce` was not supplied, a random value is generated.
|
||||
* @example
|
||||
* import { naclEncrypt } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclSign([...], [...]) // => [...]
|
||||
*/
|
||||
export default function naclEncrypt (message: Uint8Array, secret: Uint8Array, nonce: Uint8Array = randomAsU8a(24)): Encrypted {
|
||||
return {
|
||||
encrypted: nacl.secretbox(message, nonce, secret),
|
||||
|
||||
@@ -12,8 +12,8 @@ import naclSign from './sign';
|
||||
import naclVerify from './verify';
|
||||
|
||||
/**
|
||||
@summary Implements [NaCl](http://nacl.cr.yp.to/) secret-key authenticated encryption, public-key authenticated encryption, hashing, and public-key signatures
|
||||
*/
|
||||
* @summary Implements [NaCl](http://nacl.cr.yp.to/) secret-key authenticated encryption, public-key authenticated encryption, hashing, and public-key signatures
|
||||
*/
|
||||
export {
|
||||
naclDecrypt,
|
||||
naclEncrypt,
|
||||
|
||||
@@ -7,16 +7,16 @@ import { KeypairType } from '../../types';
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name naclKeypair
|
||||
@signature naclKeypairFromRandom (): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
@summary Creates a new public/secret keypair.
|
||||
@description
|
||||
Returns a new generate object containing a `publicKey` & `secretKey`.
|
||||
@example
|
||||
import { naclKeypair } from '@polkadot/util-crypto';
|
||||
|
||||
naclKeypair() // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
* @name naclKeypair
|
||||
* @signature naclKeypairFromRandom (): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
* @summary Creates a new public/secret keypair.
|
||||
* @description
|
||||
* Returns a new generate object containing a `publicKey` & `secretKey`.
|
||||
* @example
|
||||
* import { naclKeypair } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclKeypair() // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
export default function naclKeypairFromRandom (): KeypairType {
|
||||
return nacl.sign.keyPair();
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@ import { KeypairType } from '../../types';
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name naclKeypairFromSecret
|
||||
@signature naclKeypairFromSecret (secret: Uint8Array): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
@summary Creates a new public/secret keypair from a secret.
|
||||
@description
|
||||
Returns a object containing a `publicKey` & `secretKey` generated from the supplied secret.
|
||||
@example
|
||||
import { naclKeypairFromSecret } from '@polkadot/util-crypto';
|
||||
|
||||
naclKeypairFromSecret(...) // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
* @name naclKeypairFromSecret
|
||||
* @signature naclKeypairFromSecret (secret: Uint8Array): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
* @summary Creates a new public/secret keypair from a secret.
|
||||
* @description
|
||||
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied secret.
|
||||
* @example
|
||||
* import { naclKeypairFromSecret } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclKeypairFromSecret(...) // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
export default function naclKeypairFromSecret (secret: Uint8Array): KeypairType {
|
||||
return nacl.sign.keyPair.fromSecretKey(secret);
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@ import { KeypairType } from '../../types';
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name naclKeypairFromSeed
|
||||
@signature naclKeypairFromSeed (seed: Uint8Array): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
@summary Creates a new public/secret keypair from a seed.
|
||||
@description
|
||||
Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
|
||||
@example
|
||||
import { naclKeypairFromSeed } from '@polkadot/util-crypto';
|
||||
|
||||
naclKeypairFromSeed(...) // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
* @name naclKeypairFromSeed
|
||||
* @signature naclKeypairFromSeed (seed: Uint8Array): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
* @summary Creates a new public/secret keypair from a seed.
|
||||
* @description
|
||||
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
|
||||
* @example
|
||||
* import { naclKeypairFromSeed } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclKeypairFromSeed(...) // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
export default function naclKeypairFromSeed (seed: Uint8Array): KeypairType {
|
||||
return nacl.sign.keyPair.fromSeed(seed);
|
||||
}
|
||||
|
||||
@@ -10,16 +10,16 @@ import blake2AsU8a from '../../blake2/asU8a';
|
||||
import fromSeed from './fromSeed';
|
||||
|
||||
/**
|
||||
@name naclKeypairFromString
|
||||
@signature naclKeypairFromString (value: string): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
@summary Creates a new public/secret keypair from a string.
|
||||
@description
|
||||
Returns a object containing a `publicKey` & `secretKey` generated from the supplied string. The string is hashed and the value used as the input seed.
|
||||
@example
|
||||
import { naclKeypairFromString } from '@polkadot/util-crypto';
|
||||
|
||||
naclKeypairFromString('test') // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
* @name naclKeypairFromString
|
||||
* @signature naclKeypairFromString (value: string): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
* @summary Creates a new public/secret keypair from a string.
|
||||
* @description
|
||||
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied string. The string is hashed and the value used as the input seed.
|
||||
* @example
|
||||
* import { naclKeypairFromString } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclKeypairFromString('test') // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
export default function naclKeypairFromString (value: string): KeypairType {
|
||||
return fromSeed(
|
||||
blake2AsU8a(
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name naclSign
|
||||
@signature naclSign (message: Uint8Array, secretKey: Uint8Array): Uint8Array
|
||||
@summary Signs a message using the supplied secretKey
|
||||
@description
|
||||
Returns message signature of `message`, using the `secretKey`.
|
||||
@example
|
||||
import { naclSign } from '@polkadot/util-crypto';
|
||||
|
||||
naclSign([...], [...]) // => [...]
|
||||
*/
|
||||
* @name naclSign
|
||||
* @signature naclSign (message: Uint8Array, secretKey: Uint8Array): Uint8Array
|
||||
* @summary Signs a message using the supplied secretKey
|
||||
* @description
|
||||
* Returns message signature of `message`, using the `secretKey`.
|
||||
* @example
|
||||
* import { naclSign } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclSign([...], [...]) // => [...]
|
||||
*/
|
||||
export default function naclSign (message: Uint8Array, secretKey: Uint8Array): Uint8Array {
|
||||
return nacl.sign.detached(message, secretKey);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name naclSign
|
||||
@signature naclVerify (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean
|
||||
@summary Verifies the signature on the supplied message.
|
||||
@description
|
||||
Verifies the `signature` on `message` with the supplied `plublicKey`. Returns `true` on sucess, `false` otherwise.
|
||||
@example
|
||||
import { naclVerify } from '@polkadot/util-crypto';
|
||||
|
||||
naclVerify([...], [...], [...]) // => true/false
|
||||
*/
|
||||
* @name naclSign
|
||||
* @signature naclVerify (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean
|
||||
* @summary Verifies the signature on the supplied message.
|
||||
* @description
|
||||
* Verifies the `signature` on `message` with the supplied `plublicKey`. Returns `true` on sucess, `false` otherwise.
|
||||
* @example
|
||||
* import { naclVerify } from '@polkadot/util-crypto';
|
||||
*
|
||||
* naclVerify([...], [...], [...]) // => true/false
|
||||
*/
|
||||
export default function naclVerify (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array): boolean {
|
||||
return nacl.sign.detached.verify(message, signature, publicKey);
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@ import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import randomAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@name randomAsHex
|
||||
@signature randomAsHex (length?: number = 32): string
|
||||
@summary Creates a hex string filled with random bytes.
|
||||
@description
|
||||
Returns a hex string with the specified (optional) length filled with random bytes.
|
||||
@example
|
||||
import { randomAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
randomAsHex() // => 0x...
|
||||
*/
|
||||
* @name randomAsHex
|
||||
* @signature randomAsHex (length?: number = 32): string
|
||||
* @summary Creates a hex string filled with random bytes.
|
||||
* @description
|
||||
* Returns a hex string with the specified (optional) length filled with random bytes.
|
||||
* @example
|
||||
* import { randomAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* randomAsHex() // => 0x...
|
||||
*/
|
||||
export default function randomAsHex (length: number = 32): string {
|
||||
return u8aToHex(
|
||||
randomAsU8a(length)
|
||||
|
||||
@@ -10,16 +10,16 @@ import randomAsHex from './asHex';
|
||||
const BN_53 = new BN(0b11111111111111111111111111111111111111111111111111111);
|
||||
|
||||
/**
|
||||
@name randomAsNumber
|
||||
@signature randomAsNumber (): number
|
||||
@summary Creates a random number from random bytes.
|
||||
@description
|
||||
Returns a random number generated from the secure bytes.
|
||||
@example
|
||||
import { randomAsNumber } from '@polkadot/util-crypto';
|
||||
|
||||
randomAsNumber() // => <random number>
|
||||
*/
|
||||
* @name randomAsNumber
|
||||
* @signature randomAsNumber (): number
|
||||
* @summary Creates a random number from random bytes.
|
||||
* @description
|
||||
* Returns a random number generated from the secure bytes.
|
||||
* @example
|
||||
* import { randomAsNumber } from '@polkadot/util-crypto';
|
||||
*
|
||||
* randomAsNumber() // => <random number>
|
||||
*/
|
||||
export default function randomAsNumber (): number {
|
||||
return hexToBn(
|
||||
randomAsHex(8)
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name randomAsU8a
|
||||
@signature randomAsU8a (length?: number = 32): Uint8Array
|
||||
@summary Creates a Uint8Array filled with random bytes.
|
||||
@description
|
||||
Returns a `Uint8Array` with the specified (optional) length filled with random bytes.
|
||||
@example
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
randomAsU8s() // => Uint8Array([...])
|
||||
*/
|
||||
* @name randomAsU8a
|
||||
* @signature randomAsU8a (length?: number = 32): Uint8Array
|
||||
* @summary Creates a Uint8Array filled with random bytes.
|
||||
* @description
|
||||
* Returns a `Uint8Array` with the specified (optional) length filled with random bytes.
|
||||
* @example
|
||||
* import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* randomAsU8s() // => Uint8Array([...])
|
||||
*/
|
||||
export default function randomAsU8a (length: number = 32): Uint8Array {
|
||||
return nacl.randomBytes(length);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import randomAsNumber from './asNumber';
|
||||
import randomAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@summary Returns a sequence of secure random bytes in a variety of formats
|
||||
*/
|
||||
* @summary Returns a sequence of secure random bytes in a variety of formats
|
||||
*/
|
||||
export {
|
||||
randomAsHex,
|
||||
randomAsNumber,
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
/**
|
||||
@name sha512AsU8a
|
||||
@signature sha512AsU8a (data: Uint8Array): Uint8Array
|
||||
@summary Creates sha-512 hash of the input.
|
||||
@description
|
||||
Returns a sha-512 `Uint8Array` from the supplied data.
|
||||
@example
|
||||
import { sha512AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
sha512AsU8a(Uint8Array.from([...])) // => Uint8Array([...])
|
||||
*/
|
||||
* @name sha512AsU8a
|
||||
* @signature sha512AsU8a (data: Uint8Array): Uint8Array
|
||||
* @summary Creates sha-512 hash of the input.
|
||||
* @description
|
||||
* Returns a sha-512 `Uint8Array` from the supplied data.
|
||||
* @example
|
||||
* import { sha512AsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* sha512AsU8a(Uint8Array.from([...])) // => Uint8Array([...])
|
||||
*/
|
||||
export default function sha512AsU8a (data: Uint8Array): Uint8Array {
|
||||
return nacl.hash(data);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import sha512AsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@summary Implements Sha-512 hashing functions for a variety of input and outputs
|
||||
*/
|
||||
* @summary Implements Sha-512 hashing functions for a variety of input and outputs
|
||||
*/
|
||||
export {
|
||||
sha512AsU8a
|
||||
};
|
||||
|
||||
@@ -7,16 +7,16 @@ import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import xxhashAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@name xxhashAsHex
|
||||
@signature xxhashAsHex (data: Buffer | Uint8Array | string, bitLenght: number = 64): string
|
||||
@summary Creates a xxhash64 hex from the input.
|
||||
@description
|
||||
From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with the specified `bitLength`.
|
||||
@example
|
||||
import { xxhashAsHex } from '@polkadot/util-crypto';
|
||||
|
||||
xxhashAsHex('abc') // => 0x44bc2cf5ad770999
|
||||
*/
|
||||
* @name xxhashAsHex
|
||||
* @signature xxhashAsHex (data: Buffer | Uint8Array | string, bitLenght: number = 64): string
|
||||
* @summary Creates a xxhash64 hex from the input.
|
||||
* @description
|
||||
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with the specified `bitLength`.
|
||||
* @example
|
||||
* import { xxhashAsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* xxhashAsHex('abc') // => 0x44bc2cf5ad770999
|
||||
*/
|
||||
export default function xxhashAsHex (data: Buffer | Uint8Array | string, bitLength: number = 64): string {
|
||||
return u8aToHex(
|
||||
xxhashAsU8a(data, bitLength)
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import xxhash64AsBn from './xxhash64/asBn';
|
||||
|
||||
/**
|
||||
@name xxhashAsU8a
|
||||
@signature xxhashAsU8a (data: Buffer | Uint8Array | string, bitLenght: number = 64): Uint8Array
|
||||
@summary Creates a xxhash64 u8a from the input.
|
||||
@description
|
||||
From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a `Uint8Array` with the specified `bitLength`.
|
||||
@example
|
||||
import { xxhashAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
xxhashAsU8a('abc') // => 0x44bc2cf5ad770999
|
||||
*/
|
||||
* @name xxhashAsU8a
|
||||
* @signature xxhashAsU8a (data: Buffer | Uint8Array | string, bitLenght: number = 64): Uint8Array
|
||||
* @summary Creates a xxhash64 u8a from the input.
|
||||
* @description
|
||||
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a `Uint8Array` with the specified `bitLength`.
|
||||
* @example
|
||||
* import { xxhashAsU8a } from '@polkadot/util-crypto';
|
||||
*
|
||||
* xxhashAsU8a('abc') // => 0x44bc2cf5ad770999
|
||||
*/
|
||||
export default function xxhashAsU8a (data: Buffer | Uint8Array | string, bitLength: number = 64): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
const iterations = Math.ceil(bitLength / 64);
|
||||
|
||||
@@ -6,8 +6,8 @@ import xxhashAsHex from './asHex';
|
||||
import xxhashAsU8a from './asU8a';
|
||||
|
||||
/**
|
||||
@summary Create xxhash64 values with specified bitlengths
|
||||
*/
|
||||
* @summary Create xxhash64 values with specified bitlengths
|
||||
*/
|
||||
export {
|
||||
xxhashAsHex,
|
||||
xxhashAsU8a
|
||||
|
||||
@@ -7,16 +7,16 @@ import BN from 'bn.js';
|
||||
import xxhash64AsRaw from './asRaw';
|
||||
|
||||
/**
|
||||
@name xxhash64AsBn
|
||||
@signature xxhash64AsBn (data: Buffer | Uint8Array | string, seed: number): BN
|
||||
@summary Creates a xxhash BN from the input.
|
||||
@description
|
||||
From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash and return the result as a BN.
|
||||
@example
|
||||
import { xxhash64AsNumber } from '@polkadot/util-crypto';
|
||||
|
||||
xxhash64AsBn('abcd', 0xabcd)) // => new BN(0xe29f70f8b8c96df7)
|
||||
*/
|
||||
* @name xxhash64AsBn
|
||||
* @signature xxhash64AsBn (data: Buffer | Uint8Array | string, seed: number): BN
|
||||
* @summary Creates a xxhash BN from the input.
|
||||
* @description
|
||||
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash and return the result as a BN.
|
||||
* @example
|
||||
* import { xxhash64AsNumber } from '@polkadot/util-crypto';
|
||||
*
|
||||
* xxhash64AsBn('abcd', 0xabcd)) // => new BN(0xe29f70f8b8c96df7)
|
||||
*/
|
||||
export default function xxhash64AsBn (data: Buffer | Uint8Array | string, seed: number): BN {
|
||||
return new BN(
|
||||
xxhash64AsRaw(data, seed),
|
||||
|
||||
@@ -7,16 +7,16 @@ import hexAddPrefix from '@polkadot/util/hex/addPrefix';
|
||||
import xxhash64AsRaw from './asRaw';
|
||||
|
||||
/**
|
||||
@name xxhash64AsHex
|
||||
@signature xxhash64AsHex (data: Buffer | Uint8Array | string, seed: number): string
|
||||
@summary Creates a xxhash hex from the input.
|
||||
@description
|
||||
From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash and return the result as a hex string.
|
||||
@example
|
||||
import { xxhash64AsHex } from '@polkadot/util-crypto';
|
||||
|
||||
xxhash64AsHex('abcd', 0xabcd)) // => 0xe29f70f8b8c96df7
|
||||
*/
|
||||
* @name xxhash64AsHex
|
||||
* @signature xxhash64AsHex (data: Buffer | Uint8Array | string, seed: number): string
|
||||
* @summary Creates a xxhash hex from the input.
|
||||
* @description
|
||||
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash and return the result as a hex string.
|
||||
* @example
|
||||
* import { xxhash64AsHex } from '@polkadot/util-crypto';
|
||||
*
|
||||
* xxhash64AsHex('abcd', 0xabcd)) // => 0xe29f70f8b8c96df7
|
||||
*/
|
||||
export default function xxhash64AsHex (data: Buffer | Uint8Array | string, seed: number): string {
|
||||
return hexAddPrefix(
|
||||
xxhash64AsRaw(data, seed)
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import xxhash64AsValue from './asValue';
|
||||
|
||||
/**
|
||||
@name xxhash64AsRaw
|
||||
@signature xxhash64AsRaw (data: Buffer | Uint8Array | string, seed: number): string
|
||||
@summary Creates a xxhash non-prefixed hex from the input.
|
||||
@description
|
||||
From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash and return the result as a non-prefixed hex string.
|
||||
@example
|
||||
import { xxhash64AsRaw } from '@polkadot/util-crypto';
|
||||
|
||||
xxhash64AsRaw('abcd', 0xabcd)) // => e29f70f8b8c96df7
|
||||
*/
|
||||
* @name xxhash64AsRaw
|
||||
* @signature xxhash64AsRaw (data: Buffer | Uint8Array | string, seed: number): string
|
||||
* @summary Creates a xxhash non-prefixed hex from the input.
|
||||
* @description
|
||||
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash and return the result as a non-prefixed hex string.
|
||||
* @example
|
||||
* import { xxhash64AsRaw } from '@polkadot/util-crypto';
|
||||
*
|
||||
* xxhash64AsRaw('abcd', 0xabcd)) // => e29f70f8b8c96df7
|
||||
*/
|
||||
export default function xxhash64AsRaw (data: Buffer | Uint8Array | string, seed: number): string {
|
||||
return xxhash64AsValue(data, seed).toString(16);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import xxhash64AsHex from './asHex';
|
||||
import xxhash64AsRaw from './asRaw';
|
||||
|
||||
/**
|
||||
@summary Create [XXHash](http://cyan4973.github.io/xxHash/) values as BN, hex & number output
|
||||
*/
|
||||
* @summary Create [XXHash](http://cyan4973.github.io/xxHash/) values as BN, hex & number output
|
||||
*/
|
||||
export {
|
||||
xxhash64AsBn,
|
||||
xxhash64AsHex,
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function pairs (): KeyringPairs {
|
||||
return pair;
|
||||
},
|
||||
all: (): Array<KeyringPair> =>
|
||||
(Object.values(self) as Array<KeyringPair>),
|
||||
Object.values(self),
|
||||
get: (address: string | Uint8Array): KeyringPair => {
|
||||
// @ts-ignore we use coercion :(
|
||||
const pair = self[addressDecode(address)];
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
import decoder from './decoder';
|
||||
|
||||
/**
|
||||
@name decode
|
||||
@signature decoder (input?: Uint8Array): Uint8Array | Array<*>
|
||||
@summary Decodes the input RLP.
|
||||
@description
|
||||
From an input, decod the RLP and return the result as a `Uint8Array` or `Array`.
|
||||
@example
|
||||
import { decode } from '@polkadot/util-rlp';
|
||||
|
||||
encode(new Uint8Array([0x83, 0x64, 0x6f, 0x67])) // => 'dog' as Uint8Array
|
||||
*/
|
||||
* @name decode
|
||||
* @signature decoder (input?: Uint8Array): Uint8Array | Array<*>
|
||||
* @summary Decodes the input RLP.
|
||||
* @description
|
||||
* From an input, decod the RLP and return the result as a `Uint8Array` or `Array`.
|
||||
* @example
|
||||
* import { decode } from '@polkadot/util-rlp';
|
||||
*
|
||||
* encode(new Uint8Array([0x83, 0x64, 0x6f, 0x67])) // => 'dog' as Uint8Array
|
||||
*/
|
||||
export default decoder;
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
import encoder from './encoder';
|
||||
|
||||
/**
|
||||
@name encode
|
||||
@signature encode (input: any): Uint8Array
|
||||
@summary Encodes the input value into RLP.
|
||||
@description
|
||||
From an input, calculate the RLP and return the result as a `Uint8Array`.
|
||||
@example
|
||||
import { encode } from '@polkadot/util-rlp';
|
||||
|
||||
encode('dog') // => [0x83, 0x64, 0x6f, 0x67]
|
||||
*/
|
||||
* @name encode
|
||||
* @signature encode (input: any): Uint8Array
|
||||
* @summary Encodes the input value into RLP.
|
||||
* @description
|
||||
* From an input, calculate the RLP and return the result as a `Uint8Array`.
|
||||
* @example
|
||||
* import { encode } from '@polkadot/util-rlp';
|
||||
*
|
||||
* encode('dog') // => [0x83, 0x64, 0x6f, 0x67]
|
||||
*/
|
||||
export default encoder;
|
||||
|
||||
@@ -6,8 +6,8 @@ import decode from './decode';
|
||||
import encode from './encode';
|
||||
|
||||
/**
|
||||
@summary Utility methods to encode and decode [Ethereum RLP](https://github.com/ethereum/wiki/wiki/RLP). Adapted from the [EthereumJS implementation](https://github.com/ethereumjs/rlp/blob/0ce09db81fc303fcee593f7cc094ba44015f9b92/index.js)
|
||||
*/
|
||||
* @summary Utility methods to encode and decode [Ethereum RLP](https://github.com/ethereum/wiki/wiki/RLP). Adapted from the [EthereumJS implementation](https://github.com/ethereumjs/rlp/blob/0ce09db81fc303fcee593f7cc094ba44015f9b92/index.js)
|
||||
*/
|
||||
export {
|
||||
decode,
|
||||
encode
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
import { TrieDbState } from './types';
|
||||
|
||||
export default function clear (self: TrieDbState): void {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
import { TrieDbState } from './types';
|
||||
|
||||
export default function commit (self: TrieDbState): void {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@@ -6,17 +6,17 @@ import isNull from '../is/null';
|
||||
import isUndefined from '../is/undefined';
|
||||
|
||||
/**
|
||||
@name arrayFilter
|
||||
@signature arrayFilter (array: Array<any>, allowNulls: boolean = true): Array<any>
|
||||
@summary Filters undefined and (optionally) null values from an array
|
||||
@description
|
||||
Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
|
||||
@example
|
||||
import { arrayFilter } from '@polkadot/util';
|
||||
|
||||
arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
|
||||
arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
|
||||
*/
|
||||
* @name arrayFilter
|
||||
* @signature arrayFilter (array: Array<any>, allowNulls: boolean = true): Array<any>
|
||||
* @summary Filters undefined and (optionally) null values from an array
|
||||
* @description
|
||||
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
|
||||
* @example
|
||||
* import { arrayFilter } from '@polkadot/util';
|
||||
*
|
||||
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
|
||||
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
|
||||
*/
|
||||
export default function arrayFilter (array: Array<any>, allowNulls: boolean = true): Array<any> {
|
||||
return array.filter((value) => {
|
||||
return !isUndefined(value) && (allowNulls || !isNull(value));
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import arrayFilter from './filter';
|
||||
|
||||
/**
|
||||
@summary Utility methods that operates on arrays
|
||||
*/
|
||||
* @summary Utility methods that operates on arrays
|
||||
*/
|
||||
export {
|
||||
arrayFilter
|
||||
};
|
||||
|
||||
+12
-12
@@ -8,18 +8,18 @@ import isFunction from './is/function';
|
||||
type MessageFn = () => string;
|
||||
|
||||
/**
|
||||
@name assert
|
||||
@signature assert (test: any, message: string | () => string, code: number = ExtError.CODES.ASSERT, data: any): void
|
||||
@summary Checks for a valid test, if not ExtError is thrown.
|
||||
@description
|
||||
Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned.
|
||||
@example
|
||||
const assert from '@polkadot/util/assert');
|
||||
|
||||
assert(true, 'True should be true'); // true returned
|
||||
assert(false, 'False should not be true'); // ExtError thrown
|
||||
assert(false, () => 'message'); // ExtError with 'message'
|
||||
*/
|
||||
* @name assert
|
||||
* @signature assert (test: any, message: string | () => string, code: number = ExtError.CODES.ASSERT, data: any): void
|
||||
* @summary Checks for a valid test, if not ExtError is thrown.
|
||||
* @description
|
||||
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned.
|
||||
* @example
|
||||
* const assert from '@polkadot/util/assert');
|
||||
*
|
||||
* assert(true, 'True should be true'); // true returned
|
||||
* assert(false, 'False should not be true'); // ExtError thrown
|
||||
* assert(false, () => 'message'); // ExtError with 'message'
|
||||
*/
|
||||
export default function assert (test: any, message: string | MessageFn, code: number = ExtError.CODES.ASSERT, data?: any): boolean {
|
||||
if (test) {
|
||||
return true;
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import bnFromHex from '../hex/toBn';
|
||||
|
||||
/**
|
||||
@name bnFromHex
|
||||
@signature bnFromHex (value?: string): BN
|
||||
@summary Creates a BN.js bignumber object from a hex string.
|
||||
@alias hex/toBn
|
||||
*/
|
||||
* @name bnFromHex
|
||||
* @signature bnFromHex (value?: string): BN
|
||||
* @summary Creates a BN.js bignumber object from a hex string.
|
||||
* @alias hex/toBn
|
||||
*/
|
||||
export default bnFromHex;
|
||||
|
||||
@@ -8,8 +8,8 @@ import bnToHex from './toHex';
|
||||
import bnToU8a from './toU8a';
|
||||
|
||||
/**
|
||||
@summary Utility methods to convert to and from `BN` objects
|
||||
*/
|
||||
* @summary Utility methods to convert to and from `BN` objects
|
||||
*/
|
||||
export {
|
||||
bnFromHex,
|
||||
bnToBn,
|
||||
|
||||
@@ -5,18 +5,18 @@
|
||||
import BN from 'bn.js';
|
||||
|
||||
/**
|
||||
@name bnToBn
|
||||
@signature bnToBn (value?: BN : number): BN
|
||||
@summary Creates a BN value from a BN.js bignumber or number input.
|
||||
@description
|
||||
`null` inputs returns a `0x0` result, BN values returns the value, numnbers returns a BN representation.
|
||||
@example
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn } from '@polkadot/util';
|
||||
|
||||
bnToBn(0x1234); // => BN(0x1234)
|
||||
bnToBn(new BN(0x1234)); // => BN(0x1234)
|
||||
*/
|
||||
* @name bnToBn
|
||||
* @signature bnToBn (value?: BN : number): BN
|
||||
* @summary Creates a BN value from a BN.js bignumber or number input.
|
||||
* @description
|
||||
* `null` inputs returns a `0x0` result, BN values returns the value, numnbers returns a BN representation.
|
||||
* @example
|
||||
* import BN from 'bn.js';
|
||||
* import { bnToBn } from '@polkadot/util';
|
||||
*
|
||||
* bnToBn(0x1234); // => BN(0x1234)
|
||||
* bnToBn(new BN(0x1234)); // => BN(0x1234)
|
||||
*/
|
||||
export default function bnToBn (value?: BN | number): BN {
|
||||
if (!value) {
|
||||
return new BN(0);
|
||||
|
||||
@@ -10,17 +10,17 @@ import bnToBn from './toBn';
|
||||
const ZERO_STR = '0x00';
|
||||
|
||||
/**
|
||||
@name bnToHex
|
||||
@signature bnToHex (value?: BN, bitLength: number = -1): string
|
||||
@summary Creates a hex value from a BN.js bignumber object.
|
||||
@description
|
||||
`null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
|
||||
@example
|
||||
import BN from 'bn.js';
|
||||
import { bnToHex } from '@polkadot/util';
|
||||
|
||||
bnToHex(new BN(0x123456)); // => '0x123456'
|
||||
*/
|
||||
* @name bnToHex
|
||||
* @signature bnToHex (value?: BN, bitLength: number = -1): string
|
||||
* @summary Creates a hex value from a BN.js bignumber object.
|
||||
* @description
|
||||
* `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
|
||||
* @example
|
||||
* import BN from 'bn.js';
|
||||
* import { bnToHex } from '@polkadot/util';
|
||||
*
|
||||
* bnToHex(new BN(0x123456)); // => '0x123456'
|
||||
*/
|
||||
export default function bnToHex (value?: BN | number, bitLength: number = -1): string {
|
||||
if (!value) {
|
||||
return ZERO_STR;
|
||||
|
||||
@@ -9,16 +9,16 @@ import bnToBn from './toBn';
|
||||
import bnToHex from './toHex';
|
||||
|
||||
/**
|
||||
@name bnToU8a
|
||||
@signature bnToU8a (value?: BN | number, bitLength: number = -1, isLE: boolean = false): Uint8Array
|
||||
@summary Creates a Uint8Array object from a BN.
|
||||
@description
|
||||
`null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
|
||||
@example
|
||||
import { bnToU8a } from '@polkadot/util';
|
||||
|
||||
bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
*/
|
||||
* @name bnToU8a
|
||||
* @signature bnToU8a (value?: BN | number, bitLength: number = -1, isLE: boolean = false): Uint8Array
|
||||
* @summary Creates a Uint8Array object from a BN.
|
||||
* @description
|
||||
* `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
|
||||
* @example
|
||||
* import { bnToU8a } from '@polkadot/util';
|
||||
*
|
||||
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
*/
|
||||
export default function bnToU8a (value?: BN | number, bitLength: number = -1, isLe: boolean = false): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import bufferFromU8a from '../u8a/toBuffer';
|
||||
|
||||
/**
|
||||
@name bufferFromU8a
|
||||
@signature bufferFromU8a (value?: string): Buffer
|
||||
@summary Creates a Buffer object from a Uint8Array.
|
||||
@alias u8a/toBuffer
|
||||
*/
|
||||
* @name bufferFromU8a
|
||||
* @signature bufferFromU8a (value?: string): Buffer
|
||||
* @summary Creates a Buffer object from a Uint8Array.
|
||||
* @alias u8a/toBuffer
|
||||
*/
|
||||
export default bufferFromU8a;
|
||||
|
||||
@@ -6,8 +6,8 @@ import bufferFromU8a from './fromU8a';
|
||||
import bufferToU8a from './toU8a';
|
||||
|
||||
/**
|
||||
@summary Utility methods to convert to and from `Buffer` objects
|
||||
*/
|
||||
* @summary Utility methods to convert to and from `Buffer` objects
|
||||
*/
|
||||
export {
|
||||
bufferFromU8a,
|
||||
bufferToU8a
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name bufferToU8a
|
||||
@signature bufferToU8a (value?: Buffer): string
|
||||
@summary Creates a Uint8Array value from a Buffer object.
|
||||
@description
|
||||
`null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
|
||||
@example
|
||||
import { bufferToU8a } from '@polkadot/util';
|
||||
|
||||
bufferToU8a(Buffer.from([1, 2, 3]));
|
||||
*/
|
||||
* @name bufferToU8a
|
||||
* @signature bufferToU8a (value?: Buffer): string
|
||||
* @summary Creates a Uint8Array value from a Buffer object.
|
||||
* @description
|
||||
* `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
|
||||
* @example
|
||||
* import { bufferToU8a } from '@polkadot/util';
|
||||
*
|
||||
* bufferToU8a(Buffer.from([1, 2, 3]));
|
||||
*/
|
||||
export default function bufferToU8a (buffer?: Buffer | number[]): Uint8Array {
|
||||
if (!buffer) {
|
||||
return new Uint8Array([]);
|
||||
|
||||
@@ -17,16 +17,16 @@ function extend (that: any, name: string, value: any): void {
|
||||
}
|
||||
|
||||
/**
|
||||
@name ExtError
|
||||
@signature ExtError (message: string = '', code: number = UNKNOWN_ERROR, value: any)
|
||||
@summary Extension to the basic JS Error.
|
||||
@description
|
||||
The built-in JavaScript Error class is extended by adding a code to allow for Error categorization. In addition to the normal `stack`, `message`, the numeric `code` and `data` (any types) parameters are available on the object.
|
||||
@example
|
||||
const { ExtError } from '@polkadot/util');
|
||||
|
||||
throw new ExtError('some message', ExtError.CODES.METHOD_NOT_FOUND); // => error.code = -32601
|
||||
*/
|
||||
* @name ExtError
|
||||
* @signature ExtError (message: string = '', code: number = UNKNOWN_ERROR, value: any)
|
||||
* @summary Extension to the basic JS Error.
|
||||
* @description
|
||||
* The built-in JavaScript Error class is extended by adding a code to allow for Error categorization. In addition to the normal `stack`, `message`, the numeric `code` and `data` (any types) parameters are available on the object.
|
||||
* @example
|
||||
* const { ExtError } from '@polkadot/util');
|
||||
*
|
||||
* throw new ExtError('some message', ExtError.CODES.METHOD_NOT_FOUND); // => error.code = -32601
|
||||
*/
|
||||
export default class ExtError extends Error implements ExtErrorInterface {
|
||||
// @ts-ignore we are assigning it via extend
|
||||
code: number;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import ExtError from './error';
|
||||
|
||||
/**
|
||||
@summary Extensions to basic classes
|
||||
*/
|
||||
* @summary Extensions to basic classes
|
||||
*/
|
||||
export {
|
||||
ExtError
|
||||
};
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import hasPrefix from './hasPrefix';
|
||||
|
||||
/**
|
||||
@name hexAddPrefix
|
||||
@signature hexAddPrefix (value: ?string): string
|
||||
@summary Adds the `0x` prefix to string values.
|
||||
@description
|
||||
Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged.
|
||||
@example
|
||||
import { hexAddPrefix } from '@polkadot/util';
|
||||
|
||||
console.log('With prefix', hexAddPrefix('0a0b12')) // => 0x0a0b12
|
||||
*/
|
||||
* @name hexAddPrefix
|
||||
* @signature hexAddPrefix (value: ?string): string
|
||||
* @summary Adds the `0x` prefix to string values.
|
||||
* @description
|
||||
* Returns a `0x` prefixed string from the input value. If the input is already prefixed, it is returned unchanged.
|
||||
* @example
|
||||
* import { hexAddPrefix } from '@polkadot/util';
|
||||
*
|
||||
* console.log('With prefix', hexAddPrefix('0a0b12')) // => 0x0a0b12
|
||||
*/
|
||||
export default function hexAddPrefix (value: string | null | undefined): string {
|
||||
if (value && hasPrefix(value)) {
|
||||
return value;
|
||||
|
||||
@@ -6,18 +6,18 @@ import hexAddPrefix from './addPrefix';
|
||||
import hexStripPrefix from './stripPrefix';
|
||||
|
||||
/**
|
||||
@name hexFixLength
|
||||
@signature hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string
|
||||
@summary Shifts a hex string to a specific bitLength
|
||||
@description
|
||||
Returns a `0x` prefixed string with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length. Input values with less bits are returned as-is by default. When `withPadding` is set, shorter values are padded with `0`.
|
||||
@example
|
||||
import { hexFixLength } from '@polkadot/util';
|
||||
|
||||
console.log('fixed', hexFixLength('0x12', 16)) // => 0x12
|
||||
console.log('fixed', hexFixLength('0x12', 16, true)) // => 0x0012
|
||||
console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
|
||||
*/
|
||||
* @name hexFixLength
|
||||
* @signature hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string
|
||||
* @summary Shifts a hex string to a specific bitLength
|
||||
* @description
|
||||
* Returns a `0x` prefixed string with the specified number of bits contained in the return value. (If bitLength is -1, length checking is not done). Values with more bits are trimmed to the specified length. Input values with less bits are returned as-is by default. When `withPadding` is set, shorter values are padded with `0`.
|
||||
* @example
|
||||
* import { hexFixLength } from '@polkadot/util';
|
||||
*
|
||||
* console.log('fixed', hexFixLength('0x12', 16)) // => 0x12
|
||||
* console.log('fixed', hexFixLength('0x12', 16, true)) // => 0x0012
|
||||
* console.log('fixed', hexFixLength('0x0012', 8)) // => 0x12
|
||||
*/
|
||||
export default function hexFixLength (value: string, bitLength: number = -1, withPadding: boolean = false): string {
|
||||
const strLength = Math.ceil(bitLength / 4);
|
||||
const hexLength = strLength + 2;
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import hexFromBn from '../bn/toHex';
|
||||
|
||||
/**
|
||||
@name hexFromBn
|
||||
@signature hexFromBn (value?: BN): string
|
||||
@summary Creates a hex value from a BN.js bignumber object.
|
||||
@alias bn/toHex
|
||||
*/
|
||||
* @name hexFromBn
|
||||
* @signature hexFromBn (value?: BN): string
|
||||
* @summary Creates a hex value from a BN.js bignumber object.
|
||||
* @alias bn/toHex
|
||||
*/
|
||||
export default hexFromBn;
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import hexFromNumber from '../number/toHex';
|
||||
|
||||
/**
|
||||
@name hexFromNumber
|
||||
@signature hexFromNumber (value?: number): string
|
||||
@summary Creates a hex value from a number.
|
||||
@alias number/toHex
|
||||
*/
|
||||
* @name hexFromNumber
|
||||
* @signature hexFromNumber (value?: number): string
|
||||
* @summary Creates a hex value from a number.
|
||||
* @alias number/toHex
|
||||
*/
|
||||
export default hexFromNumber;
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import isHex from '../is/hex';
|
||||
|
||||
/**
|
||||
@name hexHasPrefix
|
||||
@signature hexHasPrefix (value: ?string): boolean
|
||||
@summary Tests for the existence of a `0x` prefix.
|
||||
@description
|
||||
Checks for a valid hex input value and if the start matched `0x`
|
||||
@example
|
||||
import { hexHasPrefix } from '@polkadot/util';
|
||||
|
||||
console.log('has prefix', hexHasPrefix('0x1234')); // => true
|
||||
*/
|
||||
* @name hexHasPrefix
|
||||
* @signature hexHasPrefix (value: ?string): boolean
|
||||
* @summary Tests for the existence of a `0x` prefix.
|
||||
* @description
|
||||
* Checks for a valid hex input value and if the start matched `0x`
|
||||
* @example
|
||||
* import { hexHasPrefix } from '@polkadot/util';
|
||||
*
|
||||
* console.log('has prefix', hexHasPrefix('0x1234')); // => true
|
||||
*/
|
||||
export default function hexHasPrefix (value: string | null | undefined): boolean {
|
||||
return !!(value && isHex(value, -1, true) && value.substr(0, 2) === '0x');
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import hexToNumber from './toNumber';
|
||||
import hexToU8a from './toU8a';
|
||||
|
||||
/**
|
||||
@summary Internal utilities to create and test for hex values
|
||||
*/
|
||||
* @summary Internal utilities to create and test for hex values
|
||||
*/
|
||||
export {
|
||||
hexAddPrefix,
|
||||
hexFixLength,
|
||||
|
||||
@@ -7,16 +7,16 @@ import hasPrefix from './hasPrefix';
|
||||
const UNPREFIX_HEX_REGEX = /^[a-fA-F0-9]+$/;
|
||||
|
||||
/**
|
||||
@name hexStripPrefix
|
||||
@signature hexStripPrefix (value: ?string): string
|
||||
@summary Strips any leading `0x` prefix.
|
||||
@description
|
||||
Tests for the existence of a `0x` prefix, and returns the value without the prefix. Un-prefixed values are returned as-is.
|
||||
@example
|
||||
import { hexStripPrefix } from '@polkadot/util';
|
||||
|
||||
console.log('stripped', hexStripPrefix('0x1234')); // => 1234
|
||||
*/
|
||||
* @name hexStripPrefix
|
||||
* @signature hexStripPrefix (value: ?string): string
|
||||
* @summary Strips any leading `0x` prefix.
|
||||
* @description
|
||||
* Tests for the existence of a `0x` prefix, and returns the value without the prefix. Un-prefixed values are returned as-is.
|
||||
* @example
|
||||
* import { hexStripPrefix } from '@polkadot/util';
|
||||
*
|
||||
* console.log('stripped', hexStripPrefix('0x1234')); // => 1234
|
||||
*/
|
||||
export default function hexStripPrefix (value: string | null | undefined): string {
|
||||
if (!value) {
|
||||
return '';
|
||||
|
||||
@@ -13,16 +13,16 @@ function reverse (value: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
@name hexToBn
|
||||
@signature hexToBn (value?: string, isLe: boolean = false): BN
|
||||
@summary Creates a BN.js bignumber object from a hex string.
|
||||
@description
|
||||
`null` inputs returns a `BN(0)` result. Hex input values return the actual value converted to a BN. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||
@example
|
||||
import { hexToBn } from '@polkadot/util';
|
||||
|
||||
hexToBn('0x123480001f'); // => BN(0x123480001f)
|
||||
*/
|
||||
* @name hexToBn
|
||||
* @signature hexToBn (value?: string, isLe: boolean = false): BN
|
||||
* @summary Creates a BN.js bignumber object from a hex string.
|
||||
* @description
|
||||
* `null` inputs returns a `BN(0)` result. Hex input values return the actual value converted to a BN. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||
* @example
|
||||
* import { hexToBn } from '@polkadot/util';
|
||||
*
|
||||
* hexToBn('0x123480001f'); // => BN(0x123480001f)
|
||||
*/
|
||||
export default function hexToBn (_value?: string, isLe: boolean = false): BN {
|
||||
if (!_value) {
|
||||
return new BN(0);
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import hexToBn from './toBn';
|
||||
|
||||
/**
|
||||
@name hexToNumber
|
||||
@signature hexToNumber (value?: string): number
|
||||
@summary Creates a Number value from a Buffer object.
|
||||
@description
|
||||
`null` inputs returns an NaN result, `hex` values return the actual value as a `Number`.
|
||||
@example
|
||||
import { hexToNumber } from '@polkadot/util';
|
||||
|
||||
hexToNumber('0x1234'); // => 0x1234
|
||||
*/
|
||||
* @name hexToNumber
|
||||
* @signature hexToNumber (value?: string): number
|
||||
* @summary Creates a Number value from a Buffer object.
|
||||
* @description
|
||||
* `null` inputs returns an NaN result, `hex` values return the actual value as a `Number`.
|
||||
* @example
|
||||
* import { hexToNumber } from '@polkadot/util';
|
||||
*
|
||||
* hexToNumber('0x1234'); // => 0x1234
|
||||
*/
|
||||
export default function hexToNumber (value?: string): number {
|
||||
if (!value) {
|
||||
return NaN;
|
||||
|
||||
@@ -7,17 +7,17 @@ import isHex from '../is/hex';
|
||||
import hexStripPrefix from './stripPrefix';
|
||||
|
||||
/**
|
||||
@name hexToU8a
|
||||
@signature hexToU8a (value?: string, bitLength: number = -1): Uint8Array
|
||||
@summary Creates a Buffer object from a hex string.
|
||||
@description
|
||||
`null` inputs returns an empty `Uint8Array` result. Hex input values return the actual bytes value converted to a Uint8Array. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||
@example
|
||||
import { hexToU8a } from '@polkadot/util';
|
||||
|
||||
hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
|
||||
hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
|
||||
*/
|
||||
* @name hexToU8a
|
||||
* @signature hexToU8a (value?: string, bitLength: number = -1): Uint8Array
|
||||
* @summary Creates a Buffer object from a hex string.
|
||||
* @description
|
||||
* `null` inputs returns an empty `Uint8Array` result. Hex input values return the actual bytes value converted to a Uint8Array. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||
* @example
|
||||
* import { hexToU8a } from '@polkadot/util';
|
||||
*
|
||||
* hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
|
||||
* hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
|
||||
*/
|
||||
export default function hexToU8a (_value?: string | null, bitLength: number = -1): Uint8Array {
|
||||
if (!_value) {
|
||||
return new Uint8Array([]);
|
||||
|
||||
@@ -17,8 +17,8 @@ export * from './string';
|
||||
export * from './u8a';
|
||||
|
||||
/**
|
||||
@summary Utility methods for this package are split into groups
|
||||
*/
|
||||
* @summary Utility methods for this package are split into groups
|
||||
*/
|
||||
export {
|
||||
assert,
|
||||
logger,
|
||||
|
||||
+11
-11
@@ -5,17 +5,17 @@
|
||||
import BN from 'bn.js';
|
||||
|
||||
/**
|
||||
@name isBn
|
||||
@signature isBN (value: any): boolean
|
||||
@summary Tests for a `BN` object instance.
|
||||
@description
|
||||
Checks to see if the input object is an instance of `BN` (bn.js).
|
||||
@example
|
||||
import BN from 'bn.js';
|
||||
import { isBn } from '@polkadot/util';
|
||||
|
||||
console.log('isBn', isBn(new BN(1))); // => true
|
||||
*/
|
||||
* @name isBn
|
||||
* @signature isBN (value: any): boolean
|
||||
* @summary Tests for a `BN` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `BN` (bn.js).
|
||||
* @example
|
||||
* import BN from 'bn.js';
|
||||
* import { isBn } from '@polkadot/util';
|
||||
*
|
||||
* console.log('isBn', isBn(new BN(1))); // => true
|
||||
*/
|
||||
export default function isBn (value: any): value is BN {
|
||||
return BN.isBN(value);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name isBoolean
|
||||
@signature isBoolean (value: any): boolean
|
||||
@summary Tests for a boolean value.
|
||||
@description
|
||||
Checks to see if the input value is a JavaScript boolean.
|
||||
@example
|
||||
import { isBoolean } from '@polkadot/util';
|
||||
|
||||
isBoolean(false); // => true
|
||||
*/
|
||||
* @name isBoolean
|
||||
* @signature isBoolean (value: any): boolean
|
||||
* @summary Tests for a boolean value.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript boolean.
|
||||
* @example
|
||||
* import { isBoolean } from '@polkadot/util';
|
||||
*
|
||||
* isBoolean(false); // => true
|
||||
*/
|
||||
export default function isBoolean (value: any): value is boolean {
|
||||
return typeof value === 'boolean';
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import isInstanceOf from './instanceOf';
|
||||
|
||||
/**
|
||||
@name isBuffer
|
||||
@signature isBuffer (value: any): boolean
|
||||
@summary Tests for a `Buffer` object instance.
|
||||
@description
|
||||
Checks to see if the input object is an instance of `Buffer`.
|
||||
@example
|
||||
import { isBuffer } from '@polkadot/util';
|
||||
|
||||
console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
|
||||
*/
|
||||
* @name isBuffer
|
||||
* @signature isBuffer (value: any): boolean
|
||||
* @summary Tests for a `Buffer` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Buffer`.
|
||||
* @example
|
||||
* import { isBuffer } from '@polkadot/util';
|
||||
*
|
||||
* console.log('isBuffer', isBuffer(Buffer.from([]))); // => true
|
||||
*/
|
||||
export default function isBuffer (value: any): value is Buffer {
|
||||
return isInstanceOf(value, Buffer);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
import isInstanceOf from './instanceOf';
|
||||
|
||||
/**
|
||||
@name isError
|
||||
@signature isError (value: any): boolean
|
||||
@summary Tests for a `Error` object instance.
|
||||
@description
|
||||
Checks to see if the input object is an instance of `Error`.
|
||||
@example
|
||||
import { isError } from '@polkadot/util';
|
||||
|
||||
console.log('isError', isError(new Error('message'))); // => true
|
||||
*/
|
||||
* @name isError
|
||||
* @signature isError (value: any): boolean
|
||||
* @summary Tests for a `Error` object instance.
|
||||
* @description
|
||||
* Checks to see if the input object is an instance of `Error`.
|
||||
* @example
|
||||
* import { isError } from '@polkadot/util';
|
||||
*
|
||||
* console.log('isError', isError(new Error('message'))); // => true
|
||||
*/
|
||||
export default function isError (value: any): value is Error {
|
||||
return isInstanceOf(value, Error);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name isFunction
|
||||
@signature isFunction (value: any): boolean
|
||||
@summary Tests for a `function`.
|
||||
@description
|
||||
Checks to see if the input value is a JavaScript function.
|
||||
@example
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
console.log('isFunction', isFunction(() => false)); // => true
|
||||
*/
|
||||
* @name isFunction
|
||||
* @signature isFunction (value: any): boolean
|
||||
* @summary Tests for a `function`.
|
||||
* @description
|
||||
* Checks to see if the input value is a JavaScript function.
|
||||
* @example
|
||||
* import { isFunction } from '@polkadot/util';
|
||||
*
|
||||
* isFunction(() => false); // => true
|
||||
*/
|
||||
export default function isFunction (value: any): value is Function {
|
||||
return typeof value === 'function';
|
||||
}
|
||||
|
||||
+11
-11
@@ -7,17 +7,17 @@ import isString from './string';
|
||||
const HEX_REGEX = /^0x[a-fA-F0-9]+$/;
|
||||
|
||||
/**
|
||||
@name isHex
|
||||
@signature isHex (value: any, bitLength: number = -1): boolean
|
||||
@summary Tests for a hex string.
|
||||
@description
|
||||
Checks to see if the input value is a `0x` prefixed hex string. Optionally (`bitLength` !== -1) checks to see if the bitLength is correct.
|
||||
@example
|
||||
import { isHex } from '@polkadot/util';
|
||||
|
||||
isHex('0x1234'); // => true
|
||||
isHex('0x1234', 8); // => false
|
||||
*/
|
||||
* @name isHex
|
||||
* @signature isHex (value: any, bitLength: number = -1): boolean
|
||||
* @summary Tests for a hex string.
|
||||
* @description
|
||||
* Checks to see if the input value is a `0x` prefixed hex string. Optionally (`bitLength` !== -1) checks to see if the bitLength is correct.
|
||||
* @example
|
||||
* import { isHex } from '@polkadot/util';
|
||||
*
|
||||
* isHex('0x1234'); // => true
|
||||
* isHex('0x1234', 8); // => false
|
||||
*/
|
||||
export default function isHex (_value: any, bitLength: number = -1, ignoreLength: boolean = false): _value is string {
|
||||
const value = (_value as string);
|
||||
const isValidHex = value === '0x' || (isString(value) && HEX_REGEX.test(value));
|
||||
|
||||
@@ -19,8 +19,8 @@ import isU8a from './u8a';
|
||||
import isUndefined from './undefined';
|
||||
|
||||
/**
|
||||
@summary Type checking utilities
|
||||
*/
|
||||
* @summary Type checking utilities
|
||||
*/
|
||||
export {
|
||||
isBn,
|
||||
isBoolean,
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
/**
|
||||
@name isInstanceOf
|
||||
@signature isInstanceOf (value: any, clazz: Class<any>): boolean
|
||||
@summary Tests for a instance of a class.
|
||||
@description
|
||||
Checks to see if the input value is an instance of the test class.
|
||||
@example
|
||||
import { isInstanceOf } from '@polkadot/util';
|
||||
|
||||
console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
|
||||
*/
|
||||
* @name isInstanceOf
|
||||
* @signature isInstanceOf (value: any, clazz: Class<any>): boolean
|
||||
* @summary Tests for a instance of a class.
|
||||
* @description
|
||||
* Checks to see if the input value is an instance of the test class.
|
||||
* @example
|
||||
* import { isInstanceOf } from '@polkadot/util';
|
||||
*
|
||||
* console.log('isInstanceOf', isInstanceOf(new Array(0), Array)); // => true
|
||||
*/
|
||||
export default function isInstanceOf (value: any, clazz: any): boolean {
|
||||
return value instanceof clazz;
|
||||
}
|
||||
|
||||
+13
-13
@@ -7,19 +7,19 @@ import ipRegex from 'ip-regex';
|
||||
type IpTypes = 'v4' | 'v6';
|
||||
|
||||
/**
|
||||
@name isIp
|
||||
@signature isIp (value: string, type?: 'v4' | 'v6'): boolean
|
||||
@summary Tests if the value is a valid IP address
|
||||
@description
|
||||
Checks to see if the value is a valid IP address. Optionally check for either v4/v6
|
||||
@example
|
||||
import { isIp } from '@polkadot/util';
|
||||
|
||||
isIp('192.168.0.1')); // => true
|
||||
isIp('1:2:3:4:5:6:7:8'); // => true
|
||||
isIp('192.168.0.1', 'v6')); // => false
|
||||
isIp('1:2:3:4:5:6:7:8', 'v4'); // => false
|
||||
*/
|
||||
* @name isIp
|
||||
* @signature isIp (value: string, type?: 'v4' | 'v6'): boolean
|
||||
* @summary Tests if the value is a valid IP address
|
||||
* @description
|
||||
* Checks to see if the value is a valid IP address. Optionally check for either v4/v6
|
||||
* @example
|
||||
* import { isIp } from '@polkadot/util';
|
||||
*
|
||||
* isIp('192.168.0.1')); // => true
|
||||
* isIp('1:2:3:4:5:6:7:8'); // => true
|
||||
* isIp('192.168.0.1', 'v6')); // => false
|
||||
* isIp('1:2:3:4:5:6:7:8', 'v4'); // => false
|
||||
*/
|
||||
export default function isIp (value: string, type?: IpTypes): boolean {
|
||||
// FIXME @types/ip-regex defintions are outdated
|
||||
if (type === 'v4') {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user