Use #<varname> instead of private _<varname> (#545)
* Use #<varname> insead of private _<varname> * Update key extraction paths
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
- Add `isBigInt(value)` to allow `BigInt` checks. Also add support in `bnToBn`, and anything that uses this conversion for numbers
|
||||
- Add `isChildClass(Parent, Child?)` to check if a class extends the parent
|
||||
- (internal) Use `#<varname>` insead of `private _<varname>` for private class variables
|
||||
|
||||
# 2.4.1 Feb 18, 2020
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.8.4",
|
||||
"@polkadot/dev": "^0.40.22",
|
||||
"@polkadot/dev": "^0.41.1",
|
||||
"@polkadot/ts": "^0.2.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ import Pairs from './pairs';
|
||||
* an account may be obtained using `toJson` accompanied by the account passphrase.
|
||||
*/
|
||||
export default class Keyring implements KeyringInstance {
|
||||
private _pairs: Pairs;
|
||||
readonly #pairs: Pairs;
|
||||
|
||||
private _ss58?: number;
|
||||
readonly #type: KeypairType;
|
||||
|
||||
private _type: KeypairType;
|
||||
#ss58?: number;
|
||||
|
||||
public decodeAddress = decodeAddress;
|
||||
|
||||
@@ -42,9 +42,9 @@ export default class Keyring implements KeyringInstance {
|
||||
|
||||
assert(options && ['ed25519', 'sr25519'].includes(options.type || 'undefined'), `Expected a keyring type of either 'ed25519' or 'sr25519', found '${options.type}`);
|
||||
|
||||
this._pairs = new Pairs();
|
||||
this._ss58 = options.ss58Format;
|
||||
this._type = options.type;
|
||||
this.#pairs = new Pairs();
|
||||
this.#ss58 = options.ss58Format;
|
||||
this.#type = options.type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @description Returns the type of the keyring, either ed25519 of sr25519
|
||||
*/
|
||||
public get type (): KeypairType {
|
||||
return this._type;
|
||||
return this.#type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
*/
|
||||
public addPair (pair: KeyringPair): KeyringPair {
|
||||
return this._pairs.add(pair);
|
||||
return this.#pairs.add(pair);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +188,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @description Encodes the input into an ss58 representation
|
||||
*/
|
||||
public encodeAddress = (key: Uint8Array | string, ss58Format?: number): string => {
|
||||
return encodeAddress(key, ss58Format || this._ss58);
|
||||
return encodeAddress(key, ss58Format || this.#ss58);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +198,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* a key lookup using the provided account address or public key (after decoding it).
|
||||
*/
|
||||
public getPair (address: string | Uint8Array): KeyringPair {
|
||||
return this._pairs.get(address);
|
||||
return this.#pairs.get(address);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +207,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
public getPairs (): KeyringPair[] {
|
||||
return this._pairs.all();
|
||||
return this.#pairs.all();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +216,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
public getPublicKeys (): Uint8Array[] {
|
||||
return this._pairs
|
||||
return this.#pairs
|
||||
.all()
|
||||
.map(({ publicKey }): Uint8Array =>
|
||||
publicKey
|
||||
@@ -228,7 +228,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
||||
*/
|
||||
public removePair (address: string | Uint8Array): void {
|
||||
this._pairs.remove(address);
|
||||
this.#pairs.remove(address);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +236,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* @description Sets the ss58 format for the keyring
|
||||
*/
|
||||
public setSS58Format (ss58: number): void {
|
||||
this._ss58 = ss58;
|
||||
this.#ss58 = ss58;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,6 +248,6 @@ export default class Keyring implements KeyringInstance {
|
||||
* may backup their account to a JSON file that contains this information.
|
||||
*/
|
||||
public toJson (address: string | Uint8Array, passphrase?: string): KeyringPair$Json {
|
||||
return this._pairs.get(address).toJson(passphrase);
|
||||
return this.#pairs.get(address).toJson(passphrase);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,24 +10,20 @@ import { decodeAddress } from '@polkadot/util-crypto';
|
||||
type KeyringPairMap = Record<string, KeyringPair>;
|
||||
|
||||
export default class Pairs implements KeyringPairs {
|
||||
private _map: KeyringPairMap;
|
||||
|
||||
constructor () {
|
||||
this._map = {};
|
||||
}
|
||||
readonly #map: KeyringPairMap = {};
|
||||
|
||||
public add (pair: KeyringPair): KeyringPair {
|
||||
this._map[pair.publicKey.toString()] = pair;
|
||||
this.#map[pair.publicKey.toString()] = pair;
|
||||
|
||||
return pair;
|
||||
}
|
||||
|
||||
public all (): KeyringPair[] {
|
||||
return Object.values(this._map);
|
||||
return Object.values(this.#map);
|
||||
}
|
||||
|
||||
public get (address: string | Uint8Array): KeyringPair {
|
||||
const pair = this._map[decodeAddress(address).toString()];
|
||||
const pair = this.#map[decodeAddress(address).toString()];
|
||||
|
||||
assert(pair, (): string => {
|
||||
const formatted: string = isU8a(address) || isHex(address)
|
||||
@@ -41,6 +37,6 @@ export default class Pairs implements KeyringPairs {
|
||||
}
|
||||
|
||||
public remove (address: string | Uint8Array): void {
|
||||
delete this._map[decodeAddress(address).toString()];
|
||||
delete this.#map[decodeAddress(address).toString()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ const BN_OPTIONS = {
|
||||
};
|
||||
|
||||
export default class DeriveJunction {
|
||||
private _chainCode: Uint8Array = new Uint8Array(32);
|
||||
readonly #chainCode: Uint8Array = new Uint8Array(32);
|
||||
|
||||
private _isHard = false;
|
||||
#isHard = false;
|
||||
|
||||
public static from (value: string): DeriveJunction {
|
||||
const [code, isHard] = value.startsWith('/')
|
||||
@@ -38,15 +38,15 @@ export default class DeriveJunction {
|
||||
}
|
||||
|
||||
public get chainCode (): Uint8Array {
|
||||
return this._chainCode;
|
||||
return this.#chainCode;
|
||||
}
|
||||
|
||||
public get isHard (): boolean {
|
||||
return this._isHard;
|
||||
return this.#isHard;
|
||||
}
|
||||
|
||||
public get isSoft (): boolean {
|
||||
return !this._isHard;
|
||||
return !this.#isHard;
|
||||
}
|
||||
|
||||
public hard (value: number | BN | string | Uint8Array): DeriveJunction {
|
||||
@@ -54,7 +54,7 @@ export default class DeriveJunction {
|
||||
}
|
||||
|
||||
public harden (): DeriveJunction {
|
||||
this._isHard = true;
|
||||
this.#isHard = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -72,14 +72,14 @@ export default class DeriveJunction {
|
||||
return this.soft(blake2AsU8a(value));
|
||||
}
|
||||
|
||||
this._chainCode.fill(0);
|
||||
this._chainCode.set(value, 0);
|
||||
this.#chainCode.fill(0);
|
||||
this.#chainCode.set(value, 0);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public soften (): DeriveJunction {
|
||||
this._isHard = false;
|
||||
this.#isHard = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -6,37 +6,32 @@ import keyExtractPath, { ExtractResult } from './extractPath';
|
||||
|
||||
describe('keyExtractPath', (): void => {
|
||||
it('extracts properly from soft', (): void => {
|
||||
expect(
|
||||
keyExtractPath('/1')
|
||||
).toEqual({
|
||||
parts: ['/1'],
|
||||
path: [
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
]
|
||||
});
|
||||
const test = keyExtractPath('/1');
|
||||
|
||||
expect(test.parts).toEqual(['/1']);
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(false);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('extracts properly from hard', (): void => {
|
||||
expect(
|
||||
keyExtractPath('//1')
|
||||
).toEqual({
|
||||
parts: ['//1'],
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
]
|
||||
});
|
||||
const test = keyExtractPath('//1');
|
||||
|
||||
expect(test.parts).toEqual(['//1']);
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('extracts properly from hard/soft', (): void => {
|
||||
expect(
|
||||
keyExtractPath('//1/2')
|
||||
).toEqual({
|
||||
parts: ['//1', '/2'],
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) },
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
]
|
||||
});
|
||||
const test = keyExtractPath('//1/2');
|
||||
|
||||
expect(test.parts).toEqual(['//1', '/2']);
|
||||
expect(test.path.length).toEqual(2);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
expect(test.path[1].isHard).toEqual(false);
|
||||
expect(test.path[1].chainCode).toEqual(Uint8Array.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('does not extract from invalid paths', (): void => {
|
||||
|
||||
@@ -12,126 +12,115 @@ describe('keyExtractSuri', (): void => {
|
||||
});
|
||||
|
||||
it('derives on "hello world"', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world')
|
||||
).toEqual({
|
||||
path: [],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world');
|
||||
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('derives on "hello world/1', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world/1')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world/1');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(false);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world/DOT', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world/DOT')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world/DOT');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(false);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world//1', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world//1')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world//1');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world//DOT', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world//DOT')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world//DOT');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world//1/DOT', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world//1/DOT')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) },
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world//1/DOT');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(2);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
expect(test.path[1].isHard).toEqual(false);
|
||||
expect(test.path[1].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world//DOT/1', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world//DOT/1')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) },
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world//DOT/1');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(2);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
expect(test.path[1].isHard).toEqual(false);
|
||||
expect(test.path[1].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world///password"', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world///password')
|
||||
).toEqual({
|
||||
password: 'password',
|
||||
path: [],
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world///password');
|
||||
|
||||
expect(test.password).toEqual('password');
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('derives on "hello world//1/DOT///password"', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world//1/DOT///password')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) },
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
password: 'password',
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world//1/DOT///password');
|
||||
|
||||
expect(test.password).toEqual('password');
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(2);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
expect(test.path[1].isHard).toEqual(false);
|
||||
expect(test.path[1].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on "hello world/1//DOT///password"', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('hello world/1//DOT///password')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: false, _chainCode: Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) },
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
password: 'password',
|
||||
phrase: 'hello world'
|
||||
});
|
||||
const test = keyExtractSuri('hello world/1//DOT///password');
|
||||
|
||||
expect(test.password).toEqual('password');
|
||||
expect(test.phrase).toEqual('hello world');
|
||||
expect(test.path.length).toEqual(2);
|
||||
expect(test.path[0].isHard).toEqual(false);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
expect(test.path[1].isHard).toEqual(true);
|
||||
expect(test.path[1].chainCode).toEqual(Uint8Array.from([12, 68, 79, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('derives on actual Alice', (): void => {
|
||||
expect(
|
||||
keyExtractSuri('bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice')
|
||||
).toEqual({
|
||||
path: [
|
||||
{ _isHard: true, _chainCode: Uint8Array.from([20, 65, 108, 105, 99, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) }
|
||||
],
|
||||
phrase: 'bottom drive obey lake curtain smoke basket hold race lonely fit walk'
|
||||
});
|
||||
const test = keyExtractSuri('bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice');
|
||||
|
||||
expect(test.password).not.toBeDefined();
|
||||
expect(test.phrase).toEqual('bottom drive obey lake curtain smoke basket hold race lonely fit walk');
|
||||
expect(test.path.length).toEqual(1);
|
||||
expect(test.path[0].isHard).toEqual(true);
|
||||
expect(test.path[0].chainCode).toEqual(Uint8Array.from([20, 65, 108, 105, 99, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -416,6 +416,13 @@
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.8.0"
|
||||
|
||||
"@babel/plugin-syntax-import-meta@^7.8.3":
|
||||
version "7.8.3"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-import-meta/-/plugin-syntax-import-meta-7.8.3.tgz#230afff79d3ccc215b5944b438e4e266daf3d84d"
|
||||
integrity sha512-vYiGd4wQ9gx0Lngb7+bPCwQXGK/PR6FeTIJ+TIOlq+OfOKG/kCAOO2+IBac3oMM9qV7/fU76hfcqxUaLKZf1hQ==
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.8.3"
|
||||
|
||||
"@babel/plugin-syntax-json-strings@^7.8.0":
|
||||
version "7.8.3"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz#01ca21b668cd8218c9e640cb6dd88c5412b2c96a"
|
||||
@@ -1967,15 +1974,16 @@
|
||||
dependencies:
|
||||
"@types/node" ">= 8"
|
||||
|
||||
"@polkadot/dev@^0.40.22":
|
||||
version "0.40.22"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.40.22.tgz#6306f3d0400180f57bdfa63ce63ee2e9da96d3f8"
|
||||
integrity sha512-c1m1rk4FFXq/Jy67CzJkZLNtB7agjrB4Tbbwum7WItcdb6GrjnWB32ZmHEBPd982CTyiBRi5Y2OoUZMp6uR13A==
|
||||
"@polkadot/dev@^0.41.1":
|
||||
version "0.41.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.41.1.tgz#00585db9d4a78b143c7a9572636fb404dbe9de27"
|
||||
integrity sha512-DWmXD1WDDX/xUfLoF1r/dP9E2158iPHSOEURfnyZrvBgMNYh5FqFZ7dO4sMPebZlHeg5jaK/GzhR0kKr78s8SA==
|
||||
dependencies:
|
||||
"@babel/cli" "^7.8.4"
|
||||
"@babel/core" "^7.8.4"
|
||||
"@babel/plugin-proposal-class-properties" "^7.8.3"
|
||||
"@babel/plugin-proposal-decorators" "^7.8.3"
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.8.3"
|
||||
"@babel/plugin-proposal-numeric-separator" "^7.8.3"
|
||||
"@babel/plugin-proposal-object-rest-spread" "^7.8.3"
|
||||
"@babel/plugin-proposal-optional-chaining" "^7.8.3"
|
||||
@@ -1983,6 +1991,8 @@
|
||||
"@babel/plugin-proposal-private-methods" "^7.8.3"
|
||||
"@babel/plugin-syntax-bigint" "^7.8.3"
|
||||
"@babel/plugin-syntax-dynamic-import" "^7.8.3"
|
||||
"@babel/plugin-syntax-import-meta" "^7.8.3"
|
||||
"@babel/plugin-syntax-top-level-await" "^7.8.3"
|
||||
"@babel/plugin-transform-runtime" "^7.8.3"
|
||||
"@babel/preset-env" "^7.8.4"
|
||||
"@babel/preset-react" "^7.8.3"
|
||||
|
||||
Reference in New Issue
Block a user