Control priv access via # (#286)

This commit is contained in:
Jaco Greeff
2020-02-22 18:19:35 +01:00
committed by GitHub
parent 3b71f10d1e
commit e69e98182b
13 changed files with 332 additions and 378 deletions
+2 -2
View File
@@ -10,7 +10,7 @@
],
"resolutions": {
"babel-core": "^7.0.0-bridge.0",
"typescript": "^3.7.5"
"typescript": "^3.8.2"
},
"scripts": {
"build": "polkadot-dev-build-ts",
@@ -31,7 +31,7 @@
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@polkadot/dev": "^0.40.18",
"@polkadot/dev": "^0.41.3",
"@polkadot/ts": "^0.2.3",
"babel-plugin-transform-vue-template": "^0.4.2",
"empty": "^0.10.1",
+3 -3
View File
@@ -40,9 +40,9 @@
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@polkadot/keyring": "^2.4.1",
"@polkadot/util": "^2.4.1",
"@polkadot/util-crypto": "^2.4.1",
"@polkadot/keyring": "^2.5.1",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"@react-native-community/cli-platform-ios": "^3.0.0",
"@types/react-test-renderer": "16.9.2",
"babel-jest": "^25.1.0",
+3 -3
View File
@@ -26,9 +26,9 @@
"react-is": "*"
},
"devDependencies": {
"@polkadot/keyring": "^2.4.1",
"@polkadot/util": "^2.4.1",
"@polkadot/util-crypto": "^2.4.1",
"@polkadot/keyring": "^2.5.1",
"@polkadot/util": "^2.5.1",
"@polkadot/util-crypto": "^2.5.1",
"@types/react-copy-to-clipboard": "^4.3.0",
"@types/react-dom": "^16.9.5",
"@types/styled-components": "^4.4.3",
+1 -1
View File
@@ -19,7 +19,7 @@
"react-native": "*"
},
"devDependencies": {
"@polkadot/util-crypto": "^2.4.1",
"@polkadot/util-crypto": "^2.5.1",
"@types/react-native": "^0.61.12"
}
}
+3 -3
View File
@@ -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",
+19 -19
View File
@@ -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();
}
+4 -4
View File
@@ -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;
}
+4 -4
View File
@@ -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 {
+1 -1
View File
@@ -13,7 +13,7 @@
"store": "^2.0.12"
},
"devDependencies": {
"@polkadot/util": "^2.4.1",
"@polkadot/util": "^2.5.1",
"@types/store": "^2.0.2"
},
"peerDependencies": {
+49 -49
View File
@@ -13,76 +13,76 @@ type ChangeCallback = (settings: SettingsStruct) => void;
type OnTypes = 'change';
export class Settings implements SettingsStruct {
private _apiUrl: string;
readonly #emitter: EventEmitter;
private _camera: string;
#apiUrl: string;
private _emitter: EventEmitter;
#camera: string;
private _i18nLang: string;
#i18nLang: string;
private _icon: string;
#icon: string;
private _ledgerConn: string;
#ledgerConn: string;
private _locking: string;
#locking: string;
private _prefix: number;
#prefix: number;
private _uiMode: string;
#uiMode: string;
private _uiTheme: string;
#uiTheme: string;
constructor () {
const settings = store.get('settings') || {};
this._emitter = new EventEmitter();
this.#emitter = new EventEmitter();
this._apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINT_DEFAULT;
this._camera = settings.camera || CAMERA_DEFAULT;
this._ledgerConn = settings.ledgerConn || LEDGER_CONN_DEFAULT;
this._i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
this._icon = settings.icon || ICON_DEFAULT;
this._locking = settings.locking || LOCKING_DEFAULT;
this._prefix = isUndefined(settings.prefix) ? PREFIX_DEFAULT : settings.prefix;
this._uiMode = settings.uiMode || UIMODE_DEFAULT;
this._uiTheme = settings.uiTheme || UITHEME_DEFAULT;
this.#apiUrl = settings.apiUrl || process.env.WS_URL || ENDPOINT_DEFAULT;
this.#camera = settings.camera || CAMERA_DEFAULT;
this.#ledgerConn = settings.ledgerConn || LEDGER_CONN_DEFAULT;
this.#i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
this.#icon = settings.icon || ICON_DEFAULT;
this.#locking = settings.locking || LOCKING_DEFAULT;
this.#prefix = isUndefined(settings.prefix) ? PREFIX_DEFAULT : settings.prefix;
this.#uiMode = settings.uiMode || UIMODE_DEFAULT;
this.#uiTheme = settings.uiTheme || UITHEME_DEFAULT;
}
public get camera (): string {
return this._camera;
return this.#camera;
}
public get apiUrl (): string {
return this._apiUrl;
return this.#apiUrl;
}
public get i18nLang (): string {
return this._i18nLang;
return this.#i18nLang;
}
public get icon (): string {
return this._icon;
return this.#icon;
}
public get ledgerConn (): string {
return this._ledgerConn;
return this.#ledgerConn;
}
public get locking (): string {
return this._locking;
return this.#locking;
}
public get prefix (): number {
return this._prefix;
return this.#prefix;
}
public get uiMode (): string {
return this._uiMode;
return this.#uiMode;
}
public get uiTheme (): string {
return this._uiTheme;
return this.#uiTheme;
}
public get availableCamera (): Option[] {
@@ -123,37 +123,37 @@ export class Settings implements SettingsStruct {
public get (): SettingsStruct {
return {
apiUrl: this._apiUrl,
camera: this._camera,
i18nLang: this._i18nLang,
icon: this._icon,
ledgerConn: this._ledgerConn,
locking: this._locking,
prefix: this._prefix,
uiMode: this._uiMode,
uiTheme: this._uiTheme
apiUrl: this.#apiUrl,
camera: this.#camera,
i18nLang: this.#i18nLang,
icon: this.#icon,
ledgerConn: this.#ledgerConn,
locking: this.#locking,
prefix: this.#prefix,
uiMode: this.#uiMode,
uiTheme: this.#uiTheme
};
}
public set (settings: Partial<SettingsStruct>): void {
this._apiUrl = settings.apiUrl || this._apiUrl;
this._camera = settings.camera || this._camera;
this._ledgerConn = settings.ledgerConn || this._ledgerConn;
this._i18nLang = settings.i18nLang || this._i18nLang;
this._icon = settings.icon || this._icon;
this._locking = settings.locking || this._locking;
this._prefix = isUndefined(settings.prefix) ? this._prefix : settings.prefix;
this._uiMode = settings.uiMode || this._uiMode;
this._uiTheme = settings.uiTheme || this._uiTheme;
this.#apiUrl = settings.apiUrl || this.#apiUrl;
this.#camera = settings.camera || this.#camera;
this.#ledgerConn = settings.ledgerConn || this.#ledgerConn;
this.#i18nLang = settings.i18nLang || this.#i18nLang;
this.#icon = settings.icon || this.#icon;
this.#locking = settings.locking || this.#locking;
this.#prefix = isUndefined(settings.prefix) ? this.#prefix : settings.prefix;
this.#uiMode = settings.uiMode || this.#uiMode;
this.#uiTheme = settings.uiTheme || this.#uiTheme;
const newValues = this.get();
store.set('settings', newValues);
this._emitter.emit('change', newValues);
this.#emitter.emit('change', newValues);
}
public on (type: OnTypes, cb: ChangeCallback): void {
this._emitter.on(type, cb);
this.#emitter.on(type, cb);
}
}
+1 -1
View File
@@ -16,7 +16,7 @@
"@polkadot/util-crypto": "*"
},
"devDependencies": {
"@polkadot/util-crypto": "^2.4.1",
"@polkadot/util-crypto": "^2.5.1",
"@types/color": "^3.0.1"
}
}
+1 -1
View File
@@ -18,7 +18,7 @@
"vue": "*"
},
"devDependencies": {
"@polkadot/util-crypto": "^2.4.1",
"@polkadot/util-crypto": "^2.5.1",
"vue": "^2.6.11"
}
}
+241 -287
View File
File diff suppressed because it is too large Load Diff