Cleanup util-crypto & keyring imports (#314)
* Cleanup util-crypto & keyring imports * Adjust util imports for types * Bump deps
This commit is contained in:
@@ -4,12 +4,8 @@
|
||||
|
||||
import { AnyU8a } from './types';
|
||||
|
||||
import encodeAddress from '@polkadot/keyring/address/encode';
|
||||
import decodeAddress from '@polkadot/keyring/address/decode';
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aToU8a from '@polkadot/util/u8a/toU8a';
|
||||
import { decodeAddress, encodeAddress } from '@polkadot/keyring';
|
||||
import { hexToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import U8a from './codec/U8a';
|
||||
import U8aFixed from './codec/U8aFixed';
|
||||
|
||||
@@ -3,20 +3,11 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import decodeAddress from '@polkadot/keyring/address/decode';
|
||||
import encodeAddress from '@polkadot/keyring/address/encode';
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import { decodeAddress, encodeAddress } from '@polkadot/keyring';
|
||||
import { bnToBn, bnToU8a, hexToU8a, isBn, isNumber, isU8a, isHex, u8aConcat, u8aToBn } from '@polkadot/util';
|
||||
|
||||
import { AnyU8a } from './types';
|
||||
import U8a from './codec/U8a';
|
||||
import u8aToBn from '@polkadot/util/u8a/toBn';
|
||||
import bnToU8a from '@polkadot/util/bn/toU8a';
|
||||
import isNumber from '@polkadot/util/is/number';
|
||||
import isBn from '@polkadot/util/is/bn';
|
||||
import bnToBn from '@polkadot/util/bn/toBn';
|
||||
|
||||
export const ENUMSET_SIZE = new BN(64);
|
||||
|
||||
|
||||
@@ -2,12 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import decodeAddress from '@polkadot/keyring/address/decode';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import u8aToU8a from '@polkadot/util/u8a/toU8a';
|
||||
import { decodeAddress } from '@polkadot/keyring';
|
||||
import { isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { AnyU8a } from './types';
|
||||
|
||||
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import Extrinsics from './Extrinsics';
|
||||
@@ -32,7 +32,7 @@ export default class Block extends Struct {
|
||||
// convenience, encodes the header and returns the actual hash
|
||||
get hash (): Hash {
|
||||
return new Hash(
|
||||
blake2Asu8a(this.toU8a(), 256)
|
||||
blake2AsU8a(this.toU8a(), 256)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 isU8a from '@polkadot/util/is/u8a';
|
||||
import { isU8a } from '@polkadot/util';
|
||||
|
||||
import Base from './codec/Base';
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import { hexToU8a, isHex, isU8a, u8aConcat, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AnyU8a } from './types';
|
||||
import Compact, { DEFAULT_LENGTH_BITS } from './codec/Compact';
|
||||
@@ -29,6 +25,7 @@ export default class Bytes extends U8a {
|
||||
// Instead of the block below, it should simply be:
|
||||
// return Bytes.decodeBytes(hexToU8a(value as string));
|
||||
const u8a = hexToU8a(value as string);
|
||||
|
||||
return Bytes.decodeBytes(
|
||||
u8aConcat(
|
||||
Compact.encodeU8a(u8a.length, DEFAULT_LENGTH_BITS),
|
||||
@@ -37,9 +34,11 @@ export default class Bytes extends U8a {
|
||||
);
|
||||
} else if (isU8a(value)) {
|
||||
const [offset, length] = Compact.decodeU8a(value, DEFAULT_LENGTH_BITS);
|
||||
|
||||
return value.subarray(offset, offset + length.toNumber());
|
||||
}
|
||||
return Bytes.decodeBytes(toU8a(value));
|
||||
|
||||
return Bytes.decodeBytes(u8aToU8a(value));
|
||||
}
|
||||
|
||||
get length (): number {
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, AnyU8a } from './types';
|
||||
|
||||
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import { hexToU8a, isHex, isU8a, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact, { DEFAULT_LENGTH_BITS } from './codec/Compact';
|
||||
import Struct from './codec/Struct';
|
||||
@@ -17,7 +14,6 @@ import ExtrinsicSignature from './ExtrinsicSignature';
|
||||
import Hash from './Hash';
|
||||
import { FunctionMetadata } from './Metadata';
|
||||
import Method from './Method';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
|
||||
type ExtrinsicValue = {
|
||||
method?: Method
|
||||
@@ -81,7 +77,7 @@ export default class Extrinsic extends Struct {
|
||||
// convernience, encodes the extrinsic and returns the actual hash
|
||||
get hash (): Hash {
|
||||
return new Hash(
|
||||
blake2Asu8a(this.toU8a(), 256)
|
||||
blake2AsU8a(this.toU8a(), 256)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { AnyU8a } from './types';
|
||||
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import U8a from './codec/U8a';
|
||||
|
||||
@@ -19,7 +19,7 @@ export default class ExtrinsicEra extends U8a {
|
||||
if (value instanceof U8a) {
|
||||
return value.raw;
|
||||
} else if (value) {
|
||||
const u8a = toU8a(value);
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
// If we have a zero byte, it is immortal (1 byte in length), otherwise we have
|
||||
// the era details following as another byte
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, AnyU8a } from './types';
|
||||
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import { isU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import Address from './Address';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { AnyNumber, AnyU8a } from './types';
|
||||
|
||||
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import Vector from './codec/Vector';
|
||||
@@ -65,7 +65,7 @@ export default class Header extends Struct {
|
||||
// convenience, encodes the header and returns the actual hash
|
||||
get hash (): Hash {
|
||||
return new Hash(
|
||||
blake2Asu8a(this.toU8a(), 256)
|
||||
blake2AsU8a(this.toU8a(), 256)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
import { AnyNumber } from './types';
|
||||
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import { hexToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
|
||||
import Base from './codec/Base';
|
||||
import Compact, { DEFAULT_LENGTH_BITS } from './codec/Compact';
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
import assert from '@polkadot/util/assert';
|
||||
import { ExtrinsicFunction, Extrinsics } from '@polkadot/extrinsics/types';
|
||||
import isObject from '@polkadot/util/is/object';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import { isHex, isObject, isU8a } from '@polkadot/util';
|
||||
|
||||
import Base from './codec/Base';
|
||||
import { Constructor } from './types';
|
||||
@@ -13,7 +12,6 @@ import { FunctionMetadata, FunctionArgumentMetadata } from './Metadata';
|
||||
import { getTypeDef, getTypeClass } from './codec/createType';
|
||||
import MethodIndex from './MethodIndex';
|
||||
import Struct from './codec/Struct';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
|
||||
const FN_UNKNOWN = {
|
||||
method: 'unknown',
|
||||
|
||||
@@ -3,11 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import bnToBn from '@polkadot/util/bn/toBn';
|
||||
import bnToU8a from '@polkadot/util/bn/toU8a';
|
||||
import isString from '@polkadot/util/is/string';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aToBn from '@polkadot/util/u8a/toBn';
|
||||
import { bnToBn, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
|
||||
import { AnyNumber } from './types';
|
||||
import Base from './codec/Base';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { AnyU8a } from './types';
|
||||
|
||||
import isFunction from '@polkadot/util/is/function';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
import Bytes from './Bytes';
|
||||
import { StorageFunctionMetadata } from './Metadata';
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isFunction from '@polkadot/util/is/function';
|
||||
import isString from '@polkadot/util/is/string';
|
||||
import u8aFromUtf8 from '@polkadot/util/u8a/fromUtf8';
|
||||
import u8aToUtf8 from '@polkadot/util/u8a/toUtf8';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import { isFunction, isString, stringToU8a, u8aToString, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import { AnyU8a } from '@polkadot/types/types';
|
||||
import Base from './codec/Base';
|
||||
@@ -35,7 +31,7 @@ export default class Text extends Base<string> {
|
||||
return input.raw;
|
||||
} else if (input instanceof Uint8Array) {
|
||||
const [offset, length] = Compact.decodeU8a(input, DEFAULT_LENGTH_BITS);
|
||||
return u8aToUtf8(input.subarray(offset, offset + length.toNumber()));
|
||||
return u8aToString(input.subarray(offset, offset + length.toNumber()));
|
||||
} else if (input instanceof U8a) {
|
||||
return Text.decodeText(input.raw);
|
||||
} else if (isFunction(input.toString)) {
|
||||
@@ -62,7 +58,7 @@ export default class Text extends Base<string> {
|
||||
}
|
||||
|
||||
toU8a (isBare?: boolean): Uint8Array {
|
||||
const encoded = u8aFromUtf8(this.raw);
|
||||
const encoded = stringToU8a(this.raw);
|
||||
|
||||
return isBare
|
||||
? encoded
|
||||
|
||||
@@ -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 logger from '@polkadot/util/logger';
|
||||
import { logger } from '@polkadot/util';
|
||||
|
||||
export const l = logger('codec');
|
||||
|
||||
|
||||
@@ -3,12 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import bnToBn from '@polkadot/util/bn/toBn';
|
||||
import bnToU8a from '@polkadot/util/bn/toU8a';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import u8aToBn from '@polkadot/util/u8a/toBn';
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
import { bnToBn, bnToU8a, isU8a, u8aToBn, u8aConcat, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AnyNumber, AnyU8a } from '../types';
|
||||
import UInt, { UIntBitLength } from './UInt';
|
||||
@@ -61,7 +56,7 @@ export default class Compact extends UInt {
|
||||
}
|
||||
|
||||
static decodeU8a (_input: Uint8Array | string, bitLength: UIntBitLength): [number, BN] {
|
||||
const input = toU8a(_input);
|
||||
const input = u8aToU8a(_input);
|
||||
const flag = input[0] & 0b11;
|
||||
|
||||
if (flag === 0b00) {
|
||||
|
||||
@@ -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 isU8a from '@polkadot/util/is/u8a';
|
||||
import { isU8a } from '@polkadot/util';
|
||||
|
||||
import Base from './Base';
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isNumber from '@polkadot/util/is/number';
|
||||
import isObject from '@polkadot/util/is/object';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import isUndefined from '@polkadot/util/is/undefined';
|
||||
import { isNumber, isObject, isU8a, isUndefined } from '@polkadot/util';
|
||||
|
||||
import Base from './Base';
|
||||
import { Constructor } from '../types';
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isNull from '@polkadot/util/is/null';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import isUndefined from '@polkadot/util/is/undefined';
|
||||
import { isNull, isU8a, isUndefined } from '@polkadot/util';
|
||||
|
||||
import Base from './Base';
|
||||
import { Constructor } from '../types';
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isObject from '@polkadot/util/is/object';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import { hexToU8a, isHex, isObject, isU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import Base from './Base';
|
||||
import { Constructor } from '../types';
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
import { isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AnyU8a } from '../types';
|
||||
import Base from './Base';
|
||||
@@ -26,7 +24,7 @@ export default class U8a extends Base<Uint8Array> {
|
||||
} else if (value instanceof U8a) {
|
||||
return value.raw;
|
||||
} else {
|
||||
return toU8a(value);
|
||||
return u8aToU8a(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,7 @@
|
||||
import { AnyNumber } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isString from '@polkadot/util/is/string';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import bnToBn from '@polkadot/util/bn/toBn';
|
||||
import bnToHex from '@polkadot/util/bn/toHex';
|
||||
import bnToU8a from '@polkadot/util/bn/toU8a';
|
||||
import hexToBn from '@polkadot/util/hex/toBn';
|
||||
import u8aToBn from '@polkadot/util/u8a/toBn';
|
||||
import { bnToBn, bnToHex, bnToU8a, hexToBn, isHex, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
|
||||
import Base from './Base';
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
import { u8aConcat, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import Base from './Base';
|
||||
import Compact, { DEFAULT_LENGTH_BITS } from './Compact';
|
||||
@@ -36,7 +35,7 @@ export default class Vector<
|
||||
);
|
||||
}
|
||||
|
||||
const u8a = toU8a(value);
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
let [offset, _length] = Compact.decodeU8a(value, DEFAULT_LENGTH_BITS);
|
||||
const length = _length.toNumber();
|
||||
|
||||
@@ -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 assert from '@polkadot/util/assert';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import Text from '../Text';
|
||||
import Base from './Base';
|
||||
|
||||
Reference in New Issue
Block a user