mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-05-31 14:31:03 +00:00
Schnorrkel support (#72)
* Schnorrkel support * Uuse KeyringOptions in loadAll * Bump * Bump version * Integrate new updates
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Prefix } from '@polkadot/keyring/address/types';
|
||||
import { KeyringInstance, KeyringPair } from '@polkadot/keyring/types';
|
||||
import { KeyringInstance, KeyringPair, KeyringOptions } from '@polkadot/keyring/types';
|
||||
import { AddressSubject } from './observable/types';
|
||||
|
||||
import testKeyring from '@polkadot/keyring/testing';
|
||||
import { isString } from '@polkadot/util';
|
||||
import { isBoolean, isString } from '@polkadot/util';
|
||||
|
||||
import accounts from './observable/accounts';
|
||||
import addresses from './observable/addresses';
|
||||
@@ -18,13 +18,12 @@ export default class Base {
|
||||
private _accounts: AddressSubject;
|
||||
private _addresses: AddressSubject;
|
||||
private _keyring?: KeyringInstance;
|
||||
private _prefix: Prefix;
|
||||
private _prefix?: Prefix;
|
||||
|
||||
constructor () {
|
||||
this._accounts = accounts;
|
||||
this._addresses = addresses;
|
||||
this._keyring = undefined;
|
||||
this._prefix = 42;
|
||||
}
|
||||
|
||||
get accounts () {
|
||||
@@ -51,6 +50,30 @@ export default class Base {
|
||||
return this.keyring.encodeAddress(key);
|
||||
}
|
||||
|
||||
getPair (address: string | Uint8Array): KeyringPair {
|
||||
return this.keyring.getPair(address);
|
||||
}
|
||||
|
||||
getPairs (): Array<KeyringPair> {
|
||||
return this.keyring.getPairs().filter((pair: KeyringPair) =>
|
||||
env.isDevelopment() || pair.getMeta().isTesting !== true
|
||||
);
|
||||
}
|
||||
|
||||
isAvailable (_address: Uint8Array | string): boolean {
|
||||
const accountsValue = this.accounts.subject.getValue();
|
||||
const addressesValue = this.addresses.subject.getValue();
|
||||
const address = isString(_address)
|
||||
? _address
|
||||
: this.encodeAddress(_address);
|
||||
|
||||
return !accountsValue[address] && !addressesValue[address];
|
||||
}
|
||||
|
||||
isPassValid (password: string): boolean {
|
||||
return password.length > 0 && password.length <= MAX_PASS_LEN;
|
||||
}
|
||||
|
||||
setAddressPrefix (prefix: number): void {
|
||||
this._prefix = prefix as Prefix;
|
||||
}
|
||||
@@ -59,10 +82,12 @@ export default class Base {
|
||||
env.set(isDevelopment);
|
||||
}
|
||||
|
||||
protected initKeyring (): void {
|
||||
const keyring = testKeyring();
|
||||
protected initKeyring (options: KeyringOptions & { isDevelopment?: boolean }): void {
|
||||
const keyring = testKeyring({ addressPrefix: this._prefix, ...options });
|
||||
|
||||
keyring.setAddressPrefix(this._prefix);
|
||||
if (isBoolean(options.isDevelopment)) {
|
||||
this.setDevMode(options.isDevelopment);
|
||||
}
|
||||
|
||||
this._keyring = keyring;
|
||||
|
||||
@@ -87,28 +112,4 @@ export default class Base {
|
||||
pair.setMeta({ whenCreated: Date.now() });
|
||||
}
|
||||
}
|
||||
|
||||
isAvailable (_address: Uint8Array | string): boolean {
|
||||
const accountsValue = this.accounts.subject.getValue();
|
||||
const addressesValue = this.addresses.subject.getValue();
|
||||
const address = isString(_address)
|
||||
? _address
|
||||
: this.encodeAddress(_address);
|
||||
|
||||
return !accountsValue[address] && !addressesValue[address];
|
||||
}
|
||||
|
||||
isPassValid (password: string): boolean {
|
||||
return password.length > 0 && password.length <= MAX_PASS_LEN;
|
||||
}
|
||||
|
||||
getPair (address: string | Uint8Array): KeyringPair {
|
||||
return this.keyring.getPair(address);
|
||||
}
|
||||
|
||||
getPairs (): Array<KeyringPair> {
|
||||
return this.keyring.getPairs().filter((pair: KeyringPair) =>
|
||||
env.isDevelopment() || pair.getMeta().isTesting !== true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user