rename Signer controller to Keyring

This commit is contained in:
Pedro Gomes 2020-05-25 18:54:32 +02:00
parent bc2c4ceff5
commit 1ccf17ce6f
6 changed files with 18 additions and 18 deletions

View File

@ -1,6 +1,6 @@
import {
IWakuProvider,
IWakuSigner,
IWakuKeyring,
IWakuStore,
IWakuClient,
JsonRpcRequest,
@ -8,15 +8,15 @@ import {
import {
HttpConnection,
WakuProvider,
WakuSigner,
WakuKeyring,
WakuStore,
} from "./controllers";
import { isSignerMethod, isNetworkMethod } from "./helpers/validators";
import { isKeyringMethod, isNetworkMethod } from "./helpers/validators";
import { WAKU_PREFIX } from "./constants";
class Waku implements IWakuClient {
public provider: IWakuProvider;
public store: IWakuStore;
public signer: IWakuSigner;
public keyring: IWakuKeyring;
constructor(provider: string | IWakuProvider, store?: IWakuStore) {
this.provider =
@ -24,17 +24,17 @@ class Waku implements IWakuClient {
? new WakuProvider(new HttpConnection(provider))
: provider;
this.store = store || new WakuStore();
this.signer = new WakuSigner(this.store);
this.keyring = new WakuKeyring(this.store);
}
public async init(): Promise<any> {
await this.signer.init();
await this.keyring.init();
return this.provider.init();
}
public async request(payload: JsonRpcRequest): Promise<any> {
if (isSignerMethod(payload.method)) {
return this.signer.request(payload);
if (isKeyringMethod(payload.method)) {
return this.keyring.request(payload);
} else if (isNetworkMethod(payload.method)) {
return this.provider.request(payload);
}

View File

@ -10,7 +10,7 @@ export const NETWORK_METHODS = {
waku_cancelLightClient: "waku_cancelLightClient",
};
export const SIGNER_METHODS = {
export const KEYRING_METHODS = {
waku_newKeyPair: "waku_newKeyPair",
waku_addPrivateKey: "waku_addPrivateKey",
waku_deleteKeyPair: "waku_deleteKeyPair",
@ -37,6 +37,6 @@ export const MESSAGING_METHODS = {
export const RPC_METHODS = {
NETWORK: NETWORK_METHODS,
SIGNER: SIGNER_METHODS,
KEYRING: KEYRING_METHODS,
MESSAGING: MESSAGING_METHODS,
};

View File

@ -1,4 +1,4 @@
export * from "./http";
export * from "./provider";
export * from "./signer";
export * from "./keyring";
export * from "./store";

View File

@ -7,7 +7,7 @@ import {
} from "eccrypto-js";
import {
IWakuSigner,
IWakuKeyring,
IWakuStore,
KeyMap,
KeyPair,
@ -19,7 +19,7 @@ import { STORE_KEYS_ID, WAKU_PREFIX } from "../constants";
import { uuid, getFirstMatch } from "../helpers";
import { isKeyPair, isSymKey } from "../helpers/validators";
export class WakuSigner implements IWakuSigner {
export class WakuKeyring implements IWakuKeyring {
private keyMap: KeyMap = {};
constructor(private store: IWakuStore) {}

View File

@ -1,7 +1,7 @@
import { KeyPair, SymKey } from "../typings";
import {
NETWORK_METHODS,
SIGNER_METHODS,
KEYRING_METHODS,
MESSAGING_METHODS,
} from "../constants";
@ -18,9 +18,9 @@ export function isNetworkMethod(value?: string): boolean {
return Object.keys(NETWORK_METHODS).includes(value);
}
export function isSignerMethod(value?: string): boolean {
export function isKeyringMethod(value?: string): boolean {
if (!value) return false;
return Object.keys(SIGNER_METHODS).includes(value);
return Object.keys(KEYRING_METHODS).includes(value);
}
export function isMessagingMethod(value?: string): boolean {

View File

@ -11,7 +11,7 @@ export interface IWakuProvider extends BasicProvider, IWakuController {
enable(): Promise<any>;
}
export interface IWakuSigner extends IWakuController {
export interface IWakuKeyring extends IWakuController {
newKeyPair(): Promise<string>;
addPrivateKey(prvKey: string): Promise<string>;
deleteKeyPair(id: string): Promise<boolean>;
@ -35,5 +35,5 @@ export interface IWakuStore {
export interface IWakuClient extends IWakuController {
provider: IWakuProvider;
store: IWakuStore;
signer: IWakuSigner;
keyring: IWakuKeyring;
}