Bump dev (incl. lint fixes) (#579)

* Bump dev (incl. lint fixes)

* Fix failures
This commit is contained in:
Jaco Greeff
2020-04-01 21:20:50 +02:00
committed by GitHub
parent 6429cc307c
commit cbec4add88
24 changed files with 374 additions and 283 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ export default class Keyring implements KeyringInstance {
const suri = _suri.startsWith('//')
? `${DEV_PHRASE}${_suri}`
: _suri;
const { password, phrase, path } = keyExtractSuri(suri);
const { password, path, phrase } = keyExtractSuri(suri);
let seed;
if (isHex(phrase, 256)) {
+7 -5
View File
@@ -62,7 +62,8 @@ function verify (type: KeypairType, message: Uint8Array, signature: Uint8Array,
: naclVerify(message, signature, publicKey);
}
function isLocked (secretKey?: Uint8Array): secretKey is Uint8Array {
// Not 100% correct, since it can be a Uint8Array, but an invalid one - just say "undefined" is anything non-valid
function isLocked (secretKey?: Uint8Array): secretKey is undefined {
return !secretKey || secretKey.length === 0 || isEmpty(secretKey);
}
@@ -102,18 +103,19 @@ export default function createPair ({ toSS58, type }: Setup, { publicKey, secret
get address (): string {
return toSS58(publicKey);
},
get meta (): KeyringPair$Meta {
return meta;
},
get isLocked (): boolean {
return isLocked(secretKey);
},
get meta (): KeyringPair$Meta {
return meta;
},
get publicKey (): Uint8Array {
return publicKey;
},
get type (): KeypairType {
return type;
},
// eslint-disable-next-line sort-keys
decodePkcs8: (passphrase?: string, _encoded?: Uint8Array | null): void => {
const decoded = decode(passphrase, _encoded || encoded);
@@ -131,7 +133,7 @@ export default function createPair ({ toSS58, type }: Setup, { publicKey, secret
assert(!isLocked(secretKey), 'Cannot derive on a locked keypair');
const { path } = keyExtractPath(suri);
const derived = keyFromPath({ publicKey, secretKey: secretKey! }, path, type);
const derived = keyFromPath({ publicKey, secretKey }, path, type);
return createPair({ toSS58, type }, derived, meta, null);
},
+2 -2
View File
@@ -25,7 +25,6 @@ const json: KeyringPair$Json = {
export default function everybody (): KeyringPair {
const pair: KeyringPair = {
type: 'ed25519',
address,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
decodePkcs8: (passphrase?: string, encoded?: Uint8Array): void =>
@@ -36,11 +35,11 @@ export default function everybody (): KeyringPair {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
encodePkcs8: (passphrase?: string): Uint8Array =>
new Uint8Array(0),
meta,
isLocked: true,
lock: (): void => {
// no locking, it is always locked
},
meta,
publicKey,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
setMeta: (meta: KeyringPair$Meta): void =>
@@ -51,6 +50,7 @@ export default function everybody (): KeyringPair {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toJson: (passphrase?: string): KeyringPair$Json =>
json,
type: 'ed25519',
// eslint-disable-next-line @typescript-eslint/no-unused-vars
verify: (message: Uint8Array, signature: Uint8Array): boolean =>
false
+2 -2
View File
@@ -19,8 +19,8 @@ describe('toJson', (): void => {
version: '2'
},
meta: {
name: 'alice',
isTesting: true
isTesting: true,
name: 'alice'
}
});
});
+1 -1
View File
@@ -12,7 +12,7 @@ type PairStateJson = KeyringPair$Meta & {
publicKey: Uint8Array;
};
export default function toJson (type: KeypairType, { publicKey, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
export default function toJson (type: KeypairType, { meta, publicKey }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json {
return {
address: encodeAddress(publicKey),
encoded: u8aToHex(encoded),
+16 -16
View File
@@ -23,44 +23,44 @@ interface PairDef {
// adding the keys when only the keyring is used.
export const PAIRS: PairDef[] = [
{
seed: 'Alice',
publicKey: hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d'),
secretKey: hexToU8a('0x98319d4ff8a9508c4bb0cf0b5a78d760a0b2082c02775e6e82370816fedfff48925a225d97aa00682d6a59b95b18780c10d7032336e88f3442b42361f4a66011'),
publicKey: hexToU8a('0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d')
seed: 'Alice'
},
{
seed: 'Alice//stash',
publicKey: hexToU8a('0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f'),
secretKey: hexToU8a('0xe8da6c9d810e020f5e3c7f5af2dea314cbeaa0d72bc6421e92c0808a0c584a6046ab28e97c3ffc77fe12b5a4d37e8cd4afbfebbf2391ffc7cb07c0f38c023efd'),
publicKey: hexToU8a('0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f')
seed: 'Alice//stash'
},
{
seed: 'Bob',
publicKey: hexToU8a('0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48'),
secretKey: hexToU8a('0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325'),
publicKey: hexToU8a('0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48')
seed: 'Bob'
},
{
seed: 'Bob//stash',
publicKey: hexToU8a('0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e'),
secretKey: hexToU8a('0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde'),
publicKey: hexToU8a('0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e')
seed: 'Bob//stash'
},
{
seed: 'Charlie',
publicKey: hexToU8a('0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22'),
secretKey: hexToU8a('0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c'),
publicKey: hexToU8a('0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22')
seed: 'Charlie'
},
{
seed: 'Dave',
publicKey: hexToU8a('0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20'),
secretKey: hexToU8a('0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568'),
publicKey: hexToU8a('0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20')
seed: 'Dave'
},
{
seed: 'Eve',
publicKey: hexToU8a('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e'),
secretKey: hexToU8a('0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587'),
publicKey: hexToU8a('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e')
seed: 'Eve'
},
{
seed: 'Ferdie',
publicKey: hexToU8a('0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c'),
secretKey: hexToU8a('0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426'),
publicKey: hexToU8a('0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c')
seed: 'Ferdie'
}
];
+2 -2
View File
@@ -14,7 +14,7 @@ describe('naclOpen', (): void => {
const senderBox = naclBoxKeypairFromSecret(sender.secretKey);
const receiverBox = naclBoxKeypairFromSecret(receiver.secretKey);
const { sealed, nonce } = naclSeal(message, senderBox.secretKey, receiverBox.publicKey);
const { nonce, sealed } = naclSeal(message, senderBox.secretKey, receiverBox.publicKey);
expect(
naclOpen(sealed, nonce, senderBox.publicKey, receiverBox.secretKey)
).toEqual(
@@ -37,7 +37,7 @@ describe('naclOpen', (): void => {
// Sender encrypts message to send with the public key the receiver sent and send it to receiver
const senderIdBoxKey = naclBoxKeypairFromSecret(senderIdKey.secretKey);
const message = new Uint8Array([1, 2, 3, 4, 5, 4, 3, 2, 1]);
const { sealed, nonce } = naclSeal(message, senderIdBoxKey.secretKey, receiverIdBoxKey.publicKey);
const { nonce, sealed } = naclSeal(message, senderIdBoxKey.secretKey, receiverIdBoxKey.publicKey);
console.log(`Sender sends encrypted message to receiver ${sealed}, ${nonce}`);
// Receiver opens encrypted message from the sender
+2 -2
View File
@@ -16,8 +16,8 @@ describe('naclSeal', (): void => {
expect(
naclSeal(message, senderBoxSecret, receiverBoxPublic, new Uint8Array(24))
).toEqual({
sealed: new Uint8Array([137, 195, 104, 255, 67, 199, 40, 235, 148, 177, 180, 73, 239, 131, 215, 80, 61, 191, 167, 213, 152, 138, 5, 47, 135]),
nonce: new Uint8Array(24)
nonce: new Uint8Array(24),
sealed: new Uint8Array([137, 195, 104, 255, 67, 199, 40, 235, 148, 177, 180, 73, 239, 131, 215, 80, 61, 191, 167, 213, 152, 138, 5, 47, 135])
});
});
});
+2 -2
View File
@@ -27,7 +27,7 @@ interface Sealed {
*/
export default function naclSeal (message: Uint8Array, senderBoxSecret: Uint8Array, receiverBoxPublic: Uint8Array, nonce: Uint8Array = randomAsU8a(24)): Sealed {
return {
sealed: nacl.box(message, nonce, receiverBoxPublic, senderBoxSecret),
nonce
nonce,
sealed: nacl.box(message, nonce, receiverBoxPublic, senderBoxSecret)
};
}
+2 -2
View File
@@ -46,8 +46,8 @@ describe('bnToBn', (): void => {
it('converts Compact to BN', (): void => {
expect(
bnToBn({
toBn: (): BN => new BN(1234),
something: 'test'
something: 'test',
toBn: (): BN => new BN(1234)
}).toNumber()
).toEqual(1234);
});
+2 -2
View File
@@ -45,13 +45,13 @@ describe('bnToU8a', (): void => {
it('converts negative numbers (BE)', (): void => {
expect(
bnToU8a(new BN(-1234), { isNegative: true, isLe: false })
bnToU8a(new BN(-1234), { isLe: false, isNegative: true })
).toEqual(new Uint8Array([251, 46]));
});
it('converts negative numbers (bitLength)', (): void => {
expect(
bnToU8a(new BN(-1234), { isNegative: true, bitLength: 32 })
bnToU8a(new BN(-1234), { bitLength: 32, isNegative: true })
).toEqual(new Uint8Array([46, 251, 255, 255]));
});
+1 -1
View File
@@ -30,9 +30,9 @@ function bnToU8a (value: BN | BigInt | number | null, options?: Options): Uint8A
function bnToU8a (value: BN | BigInt | number | null, bitLength?: number, isLe?: boolean): Uint8Array;
function bnToU8a (value: BN | BigInt | number | null, arg1: number | Options = { bitLength: -1, isLe: true, isNegative: false }, arg2?: boolean): Uint8Array {
const _options: Options = {
bitLength: -1,
isLe: true,
isNegative: false,
bitLength: -1,
...isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1
};
+15 -15
View File
@@ -76,20 +76,20 @@ describe('encode', (): void => {
describe('from Rust', (): void => {
// Copied from https://github.com/paritytech/parity-codec/blob/master/src/codec.rs
const testCases = [
{ value: new BN('0'), expected: '00' },
{ value: new BN('63'), expected: 'fc' },
{ value: new BN('64'), expected: '01 01' },
{ value: new BN('16383'), expected: 'fd ff' },
{ value: new BN('16384'), expected: '02 00 01 00' },
{ value: new BN('1073741823'), expected: 'fe ff ff ff' },
{ value: new BN('1073741824'), expected: '03 00 00 00 40' },
{ value: new BN(`${1}${'0'.repeat(32)}`, 2).subn(1), expected: '03 ff ff ff ff' },
{ value: new BN(`${1}${'0'.repeat(32)}`, 2), expected: '07 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(40)}`, 2), expected: '0b 00 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(48)}`, 2), expected: '0f 00 00 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(56)}`, 2).subn(1), expected: '0f ff ff ff ff ff ff ff' },
{ value: new BN(`${1}${'0'.repeat(56)}`, 2), expected: '13 00 00 00 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(64)}`, 2).subn(1), expected: '13 ff ff ff ff ff ff ff ff' }
{ expected: '00', value: new BN('0') },
{ expected: 'fc', value: new BN('63') },
{ expected: '01 01', value: new BN('64') },
{ expected: 'fd ff', value: new BN('16383') },
{ expected: '02 00 01 00', value: new BN('16384') },
{ expected: 'fe ff ff ff', value: new BN('1073741823') },
{ expected: '03 00 00 00 40', value: new BN('1073741824') },
{ expected: '03 ff ff ff ff', value: new BN(`${1}${'0'.repeat(32)}`, 2).subn(1) },
{ expected: '07 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(32)}`, 2) },
{ expected: '0b 00 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(40)}`, 2) },
{ expected: '0f 00 00 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(48)}`, 2) },
{ expected: '0f ff ff ff ff ff ff ff', value: new BN(`${1}${'0'.repeat(56)}`, 2).subn(1) },
{ expected: '13 00 00 00 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(56)}`, 2) },
{ expected: '13 ff ff ff ff ff ff ff ff', value: new BN(`${1}${'0'.repeat(64)}`, 2).subn(1) }
];
function testEncode (value: BN, expected: string): void {
@@ -104,6 +104,6 @@ describe('encode', (): void => {
});
}
testCases.forEach(({ value, expected }): void => testEncode(value, expected));
testCases.forEach(({ expected, value }): void => testEncode(value, expected));
});
});
+18 -18
View File
@@ -17,13 +17,13 @@ describe('formatBalance', (): void => {
it('formats 123,456,789,000 (decimals=15)', (): void => {
expect(
formatBalance(TESTVAL, { withSi: true, decimals: 15 })
formatBalance(TESTVAL, { decimals: 15, withSi: true })
).toEqual('123.456µ Unit');
});
it('formats BigInt numbers', (): void => {
expect(
formatBalance(123_456_789_000n, { withSi: true, decimals: 15 })
formatBalance(123_456_789_000n, { decimals: 15, withSi: true })
).toEqual('123.456µ Unit');
});
@@ -35,24 +35,24 @@ describe('formatBalance', (): void => {
it('formats 123,456,789,000 (decimals=36, option)', (): void => {
expect(
formatBalance(TESTVAL, { withSi: true, decimals: 36 })
formatBalance(TESTVAL, { decimals: 36, withSi: true })
).toEqual('0.123y Unit');
});
it('formats 123,456,789,000 (decimals=15, Compact)', (): void => {
const compact = {
something: 'else',
toBn: (): BN => TESTVAL,
unwrap: (): BN => TESTVAL,
something: 'else'
unwrap: (): BN => TESTVAL
};
expect(
formatBalance(compact, { withSi: true, decimals: 15 })
formatBalance(compact, { decimals: 15, withSi: true })
).toEqual('123.456µ Unit');
});
it('formats 123,456,789,000 (decimals=12)', (): void => {
expect(
formatBalance(TESTVAL, { withSi: true, decimals: 12 })
formatBalance(TESTVAL, { decimals: 12, withSi: true })
).toEqual('123.456m Unit');
});
@@ -173,13 +173,13 @@ describe('formatBalance', (): void => {
it('finds the SI value', (): void => {
expect(
formatBalance.findSi('k')
).toEqual({ power: 3, value: 'k', text: 'Kilo' });
).toEqual({ power: 3, text: 'Kilo', value: 'k' });
});
it('returns default on not found', (): void => {
expect(
formatBalance.findSi('blah')
).toEqual({ power: 0, value: '-', text: 'Unit' });
).toEqual({ power: 0, text: 'Unit', value: '-' });
});
});
@@ -214,15 +214,15 @@ describe('formatBalance', (): void => {
expect(
formatBalance.getOptions()
).toEqual([
{ power: 0, value: '-', text: 'TEST' },
{ power: 3, value: 'k', text: 'Kilo' },
{ power: 6, value: 'M', text: 'Mega' },
{ power: 9, value: 'G', text: 'Giga' },
{ power: 12, value: 'T', text: 'Tera' },
{ power: 15, value: 'P', text: 'Peta' },
{ power: 18, value: 'E', text: 'Exa' },
{ power: 21, value: 'Z', text: 'Zeta' },
{ power: 24, value: 'Y', text: 'Yotta' }
{ power: 0, text: 'TEST', value: '-' },
{ power: 3, text: 'Kilo', value: 'k' },
{ power: 6, text: 'Mega', value: 'M' },
{ power: 9, text: 'Giga', value: 'G' },
{ power: 12, text: 'Tera', value: 'T' },
{ power: 15, text: 'Peta', value: 'P' },
{ power: 18, text: 'Exa', value: 'E' },
{ power: 21, text: 'Zeta', value: 'Z' },
{ power: 24, text: 'Yotta', value: 'Y' }
]);
});
});
+17 -17
View File
@@ -7,23 +7,23 @@ import { SiDef } from '../types';
export const SI_MID = 8;
export const SI: SiDef[] = [
{ power: -24, value: 'y', text: 'yocto' },
{ power: -21, value: 'z', text: 'zepto' },
{ power: -18, value: 'a', text: 'atto' },
{ power: -15, value: 'f', text: 'femto' },
{ power: -12, value: 'p', text: 'pico' },
{ power: -9, value: 'n', text: 'nano' },
{ power: -6, value: 'µ', text: 'micro' },
{ power: -3, value: 'm', text: 'milli' },
{ power: 0, value: '-', text: 'Unit' }, // position 8
{ power: 3, value: 'k', text: 'Kilo' },
{ power: 6, value: 'M', text: 'Mega' },
{ power: 9, value: 'G', text: 'Giga' },
{ power: 12, value: 'T', text: 'Tera' },
{ power: 15, value: 'P', text: 'Peta' },
{ power: 18, value: 'E', text: 'Exa' },
{ power: 21, value: 'Z', text: 'Zeta' },
{ power: 24, value: 'Y', text: 'Yotta' }
{ power: -24, text: 'yocto', value: 'y' },
{ power: -21, text: 'zepto', value: 'z' },
{ power: -18, text: 'atto', value: 'a' },
{ power: -15, text: 'femto', value: 'f' },
{ power: -12, text: 'pico', value: 'p' },
{ power: -9, text: 'nano', value: 'n' },
{ power: -6, text: 'micro', value: 'µ' },
{ power: -3, text: 'milli', value: 'm' },
{ power: 0, text: 'Unit', value: '-' }, // position 8
{ power: 3, text: 'Kilo', value: 'k' },
{ power: 6, text: 'Mega', value: 'M' },
{ power: 9, text: 'Giga', value: 'G' },
{ power: 12, text: 'Tera', value: 'T' },
{ power: 15, text: 'Peta', value: 'P' },
{ power: 18, text: 'Exa', value: 'E' },
{ power: 21, text: 'Zeta', value: 'Z' },
{ power: 24, text: 'Yotta', value: 'Y' }
];
// Given a SI type (e.g. k, m, Y) find the SI definition