mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-05-31 12:11:04 +00:00
Control priv access via # (#286)
This commit is contained in:
@@ -26,9 +26,9 @@
|
||||
"store": "^2.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.4.1",
|
||||
"@polkadot/types": "^1.4.0-beta.9",
|
||||
"@polkadot/util": "^2.4.1",
|
||||
"@polkadot/keyring": "^2.5.1",
|
||||
"@polkadot/types": "^1.4.0-beta.30",
|
||||
"@polkadot/util": "^2.5.1",
|
||||
"@types/ledgerhq__hw-transport-node-hid": "^4.21.1",
|
||||
"@types/ledgerhq__hw-transport-u2f": "^4.21.1",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
|
||||
@@ -18,40 +18,40 @@ import BrowserStore from './stores/Browser'; // direct import (skip index with a
|
||||
import { MAX_PASS_LEN } from './defaults';
|
||||
|
||||
export default class Base {
|
||||
private _accounts: AddressSubject;
|
||||
#accounts: AddressSubject;
|
||||
|
||||
private _addresses: AddressSubject;
|
||||
#addresses: AddressSubject;
|
||||
|
||||
private _contracts: AddressSubject;
|
||||
#contracts: AddressSubject;
|
||||
|
||||
private _keyring?: KeyringInstance;
|
||||
#keyring?: KeyringInstance;
|
||||
|
||||
protected _store: KeyringStore;
|
||||
|
||||
protected _genesisHash?: string;
|
||||
|
||||
protected _store!: KeyringStore;
|
||||
|
||||
constructor () {
|
||||
this._accounts = accounts;
|
||||
this._addresses = addresses;
|
||||
this._contracts = contracts;
|
||||
this._keyring = undefined;
|
||||
this.#accounts = accounts;
|
||||
this.#addresses = addresses;
|
||||
this.#contracts = contracts;
|
||||
this._store = new BrowserStore();
|
||||
}
|
||||
|
||||
public get accounts (): AddressSubject {
|
||||
return this._accounts;
|
||||
return this.#accounts;
|
||||
}
|
||||
|
||||
public get addresses (): AddressSubject {
|
||||
return this._addresses;
|
||||
return this.#addresses;
|
||||
}
|
||||
|
||||
public get contracts (): AddressSubject {
|
||||
return this._contracts;
|
||||
return this.#contracts;
|
||||
}
|
||||
|
||||
public get keyring (): KeyringInstance {
|
||||
if (this._keyring) {
|
||||
return this._keyring;
|
||||
if (this.#keyring) {
|
||||
return this.#keyring;
|
||||
}
|
||||
|
||||
throw new Error('Keyring should be initialised via \'loadAll\' before use');
|
||||
@@ -95,8 +95,8 @@ export default class Base {
|
||||
}
|
||||
|
||||
public setSS58Format (ss58Format?: Prefix): void {
|
||||
if (this._keyring && ss58Format) {
|
||||
this._keyring.setSS58Format(ss58Format);
|
||||
if (this.#keyring && ss58Format) {
|
||||
this.#keyring.setSS58Format(ss58Format);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +111,9 @@ export default class Base {
|
||||
this.setDevMode(options.isDevelopment);
|
||||
}
|
||||
|
||||
this._keyring = keyring;
|
||||
this.#keyring = keyring;
|
||||
this._genesisHash = options.genesisHash && options.genesisHash.toHex();
|
||||
this._store = options.store || new BrowserStore();
|
||||
this._store = options.store || this._store;
|
||||
|
||||
this.addAccountPairs();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const RECENT_EXPIRY = 24 * 60 * 60;
|
||||
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll({ type: 'ed25519' | 'sr25519' })` is triggered
|
||||
// from the API after the chain is received
|
||||
export class Keyring extends Base implements KeyringStruct {
|
||||
private stores = {
|
||||
#stores = {
|
||||
address: (): AddressSubject => this.addresses,
|
||||
contract: (): AddressSubject => this.contracts,
|
||||
account: (): AddressSubject => this.accounts
|
||||
@@ -114,8 +114,8 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
: this.encodeAddress(_address);
|
||||
const publicKey = this.decodeAddress(address);
|
||||
const stores = type
|
||||
? [this.stores[type]]
|
||||
: Object.values(this.stores);
|
||||
? [this.#stores[type]]
|
||||
: Object.values(this.#stores);
|
||||
|
||||
const info = stores.reduce<SingleAddress | undefined>((lastInfo, store): SingleAddress | undefined =>
|
||||
(store().subject.getValue()[address] || lastInfo), undefined);
|
||||
@@ -319,7 +319,7 @@ export class Keyring extends Base implements KeyringStruct {
|
||||
|
||||
delete json.meta.isRecent;
|
||||
|
||||
this.stores[type]().add(this._store, address, json);
|
||||
this.#stores[type]().add(this._store, address, json);
|
||||
|
||||
return json as KeyringPair$Json;
|
||||
}
|
||||
|
||||
@@ -10,19 +10,19 @@ import path from 'path';
|
||||
|
||||
// NOTE untested and unused by any known apps, probably broken in various mysterious ways
|
||||
export default class FileStore implements KeyringStore {
|
||||
private _path: string;
|
||||
#path: string;
|
||||
|
||||
constructor (path: string) {
|
||||
if (!fs.existsSync(path)) {
|
||||
mkdirp.sync(path);
|
||||
}
|
||||
|
||||
this._path = path;
|
||||
this.#path = path;
|
||||
}
|
||||
|
||||
public all (cb: (key: string, value: KeyringJson) => void): void {
|
||||
fs
|
||||
.readdirSync(this._path)
|
||||
.readdirSync(this.#path)
|
||||
.filter((key): boolean => !['.', '..'].includes(key))
|
||||
.forEach((key): void => {
|
||||
cb(key, this._readKey(key));
|
||||
@@ -44,7 +44,7 @@ export default class FileStore implements KeyringStore {
|
||||
}
|
||||
|
||||
private _getPath (key: string): string {
|
||||
return path.join(this._path, key);
|
||||
return path.join(this.#path, key);
|
||||
}
|
||||
|
||||
private _readKey (key: string): KeyringJson {
|
||||
|
||||
Reference in New Issue
Block a user