Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Type to Keyring as generic type parameter #188

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Json } from './json';
* static property on Keyring classes. See the {@link Keyring} type for more
* information.
*/
export type KeyringClass<State extends Json> = {
export type KeyringClass<Type extends string, State extends Json> = {
/**
* The Keyring constructor. Takes a single parameter, an "options" object.
* See the documentation for the specific keyring for more information about
Expand All @@ -20,13 +20,13 @@ export type KeyringClass<State extends Json> = {
* @param options - The constructor options. Differs between keyring
* implementations.
*/
new (options?: Record<string, unknown>): Keyring<State>;
new (options?: Record<string, unknown>): Keyring<Type, State>;

/**
* The name of this type of keyring. This must uniquely identify the
* keyring type.
*/
type: string;
type: Type;
};

/**
Expand All @@ -44,12 +44,12 @@ export type KeyringClass<State extends Json> = {
* should be treated with care though, just in case it does contain sensitive
* material such as a private key.
*/
export type Keyring<State extends Json> = {
export type Keyring<Type extends string, State extends Json> = {
/**
* The name of this type of keyring. This must match the `type` property of
* the keyring class.
*/
type: string;
type: Type;

/**
* Get the addresses for all accounts in this keyring.
Expand Down Expand Up @@ -264,3 +264,11 @@ export type Keyring<State extends Json> = {
*/
destroy?(): Promise<void>;
};

/**
* A Keyring factory function.
*/
export type KeyringBuilder<Type extends string, State extends Json> = {
(): Keyring<Type, State>;
type: Type;
};
Loading