Cleanup exports (#903)
* Cleanup exports * No buffer conversion on base 58 * Buffer conversion
This commit is contained in:
@@ -7,7 +7,7 @@ import type { AccountOptions, LedgerAddress, LedgerSignature, LedgerTypes, Ledge
|
||||
import { newDockApp, newKusamaApp, newPolkadotApp, newPolymeshApp, ResponseBase, SubstrateApp } from '@zondax/ledger-polkadot';
|
||||
|
||||
import { transports } from '@polkadot/hw-ledger-transports';
|
||||
import { assert, bufferToU8a, u8aToBuffer, u8aToHex } from '@polkadot/util';
|
||||
import { assert, u8aToBuffer } from '@polkadot/util';
|
||||
|
||||
export const LEDGER_DEFAULT_ACCOUNT = 0x80000000;
|
||||
|
||||
@@ -77,7 +77,7 @@ export class Ledger {
|
||||
const { signature } = await this.#wrapError(app.sign(account + accountOffset, change, addressIndex + addressOffset, buffer));
|
||||
|
||||
return {
|
||||
signature: u8aToHex(bufferToU8a(signature))
|
||||
signature: `0x${signature.toString('hex')}`
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,12 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// default substrate dev phrase
|
||||
const DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
||||
export const DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
||||
|
||||
// seed from the above phrase
|
||||
const DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
|
||||
|
||||
export {
|
||||
DEV_PHRASE,
|
||||
DEV_SEED
|
||||
};
|
||||
export const DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
|
||||
|
||||
@@ -21,5 +21,3 @@ import { detectPackage } from '@polkadot/util';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
|
||||
@@ -3,24 +3,12 @@
|
||||
|
||||
import type { KeyringPair$JsonEncodingTypes } from '../types';
|
||||
|
||||
const ENCODING: KeyringPair$JsonEncodingTypes[] = ['scrypt', 'xsalsa20-poly1305'];
|
||||
const NONCE_LENGTH = 24;
|
||||
const PKCS8_DIVIDER = new Uint8Array([161, 35, 3, 33, 0]);
|
||||
const PKCS8_HEADER = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
||||
const PUB_LENGTH = 32;
|
||||
const SALT_LENGTH = 32;
|
||||
const SEC_LENGTH = 64;
|
||||
const SEED_LENGTH = 32;
|
||||
const SCRYPT_LENGTH = SALT_LENGTH + (3 * 4);
|
||||
|
||||
export {
|
||||
ENCODING,
|
||||
NONCE_LENGTH,
|
||||
PKCS8_DIVIDER,
|
||||
PKCS8_HEADER,
|
||||
PUB_LENGTH,
|
||||
SALT_LENGTH,
|
||||
SEC_LENGTH,
|
||||
SEED_LENGTH,
|
||||
SCRYPT_LENGTH
|
||||
};
|
||||
export const ENCODING: KeyringPair$JsonEncodingTypes[] = ['scrypt', 'xsalsa20-poly1305'];
|
||||
export const NONCE_LENGTH = 24;
|
||||
export const PKCS8_DIVIDER = new Uint8Array([161, 35, 3, 33, 0]);
|
||||
export const PKCS8_HEADER = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
||||
export const PUB_LENGTH = 32;
|
||||
export const SALT_LENGTH = 32;
|
||||
export const SEC_LENGTH = 64;
|
||||
export const SEED_LENGTH = 32;
|
||||
export const SCRYPT_LENGTH = SALT_LENGTH + (3 * 4);
|
||||
|
||||
@@ -27,7 +27,7 @@ const createReserved = (prefix: number, displayName: string, network: string | n
|
||||
website: null
|
||||
});
|
||||
|
||||
const all: NetworkFromSubstrate[] = [
|
||||
export const all: NetworkFromSubstrate[] = [
|
||||
{
|
||||
decimals: [10],
|
||||
displayName: 'Polkadot Relay Chain',
|
||||
@@ -490,7 +490,7 @@ const all: NetworkFromSubstrate[] = [
|
||||
// - we only include those where we have a standardAccount
|
||||
// - when no icon has been specified, default to substrate
|
||||
// - sort by name, however we keep 0, 2, 42 first in the list
|
||||
const available: Network[] = all
|
||||
export const available: Network[] = all
|
||||
.filter((n): n is NetworkFromSubstrateNamed => !n.isIgnored && !!n.network)
|
||||
.map((n) => ({ ...n, genesisHash: n.genesisHash || [], icon: n.icon || 'substrate' }))
|
||||
.sort((a, b) =>
|
||||
@@ -504,8 +504,4 @@ const available: Network[] = all
|
||||
);
|
||||
|
||||
// A filtered list of those chains we have details about (genesisHashes)
|
||||
const filtered: Network[] = available.filter((n) => n.genesisHash.length || n.prefix === 42);
|
||||
|
||||
export { all, available };
|
||||
|
||||
export default filtered;
|
||||
export default available.filter((n) => n.genesisHash.length || n.prefix === 42);
|
||||
|
||||
@@ -2,10 +2,5 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// https://github.com/multiformats/js-multibase/blob/master/src/constants.js
|
||||
const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
|
||||
const BITS_PER_CHAR = 5;
|
||||
|
||||
export {
|
||||
BASE32_ALPHABET,
|
||||
BITS_PER_CHAR
|
||||
};
|
||||
export const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
|
||||
export const BITS_PER_CHAR = 5;
|
||||
|
||||
@@ -4,11 +4,6 @@
|
||||
import baseX from 'base-x';
|
||||
|
||||
// https://github.com/cryptocoinjs/base-x#alphabets
|
||||
const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
||||
export const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
||||
|
||||
const bs58 = baseX(BASE58_ALPHABET);
|
||||
|
||||
export {
|
||||
BASE58_ALPHABET,
|
||||
bs58
|
||||
};
|
||||
export const bs58 = baseX(BASE58_ALPHABET);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { u8aToBuffer, u8aToU8a } from '@polkadot/util';
|
||||
import { u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { bs58 } from './bs58';
|
||||
|
||||
@@ -12,9 +12,7 @@ import { bs58 } from './bs58';
|
||||
* From the provided input, create the base58 and return the result as a string.
|
||||
*/
|
||||
export function base58Encode (value: Uint8Array | string | Buffer | number[], ipfsCompat?: boolean): string {
|
||||
const out = bs58.encode(
|
||||
u8aToBuffer(u8aToU8a(value))
|
||||
);
|
||||
const out = bs58.encode(u8aToU8a(value));
|
||||
|
||||
return ipfsCompat
|
||||
? `z${out}`
|
||||
|
||||
@@ -21,5 +21,3 @@ import { detectPackage } from '@polkadot/util';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const DEFAULT_PARAMS = {
|
||||
export const DEFAULT_PARAMS = {
|
||||
N: 1 << 15,
|
||||
p: 1,
|
||||
r: 8
|
||||
};
|
||||
|
||||
export { DEFAULT_PARAMS };
|
||||
|
||||
@@ -4,21 +4,19 @@
|
||||
/**
|
||||
* @summary Utility methods for this package are split into groups
|
||||
*/
|
||||
|
||||
export { assert, assertReturn } from './assert';
|
||||
export { detectPackage } from './detectPackage';
|
||||
export { extractTime } from './extractTime';
|
||||
export { logger } from './logger';
|
||||
export { memoize } from './memoize';
|
||||
export { promisify } from './promisify';
|
||||
|
||||
export * from './array';
|
||||
export * from './assert';
|
||||
export * from './bn';
|
||||
export * from './buffer';
|
||||
export * from './compact';
|
||||
export * from './detectPackage';
|
||||
export * from './extractTime';
|
||||
export * from './format';
|
||||
export * from './hex';
|
||||
export * from './is';
|
||||
export * from './logger';
|
||||
export * from './memoize';
|
||||
export * from './number';
|
||||
export * from './promisify';
|
||||
export * from './string';
|
||||
export * from './u8a';
|
||||
|
||||
@@ -5,8 +5,7 @@ import type { Logger } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { format } from './logger';
|
||||
import { logger } from '.';
|
||||
import { logger, loggerFormat } from '.';
|
||||
|
||||
describe('logger', (): void => {
|
||||
let dateMatch: unknown;
|
||||
@@ -44,13 +43,13 @@ describe('logger', (): void => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('format', (): void => {
|
||||
describe('loggerFormat', (): void => {
|
||||
it('returns null as-is', (): void => {
|
||||
expect(format(null)).toEqual(null);
|
||||
expect(loggerFormat(null)).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns undefined as-is', (): void => {
|
||||
expect(format(undefined)).toEqual(undefined);
|
||||
expect(loggerFormat(undefined)).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ const logTo = {
|
||||
function formatOther (value: unknown): unknown {
|
||||
if (value && isObject(value) && value.constructor === Object) {
|
||||
return Object.keys(value).reduce((result: Record<string, unknown>, key): Record<string, unknown> => {
|
||||
result[key] = format(value[key]);
|
||||
result[key] = loggerFormat(value[key]);
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
@@ -34,9 +34,9 @@ function formatOther (value: unknown): unknown {
|
||||
return value;
|
||||
}
|
||||
|
||||
export function format (value: unknown): unknown {
|
||||
export function loggerFormat (value: unknown): unknown {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(format);
|
||||
return value.map(loggerFormat);
|
||||
} else if (isBn(value)) {
|
||||
return value.toString();
|
||||
} else if (isU8a(value) || isBuffer(value)) {
|
||||
@@ -57,7 +57,7 @@ function apply (log: LogType, type: string, values: Logger$Data, maxSize = -1):
|
||||
formatDate(new Date()),
|
||||
type,
|
||||
...values
|
||||
.map(format)
|
||||
.map(loggerFormat)
|
||||
.map((v) => {
|
||||
if (maxSize <= 0) {
|
||||
return v;
|
||||
|
||||
Reference in New Issue
Block a user