From aa4637dd0d82411b1a45eaceb64929d9ffd6f5f2 Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 8 Oct 2024 19:12:21 +0200 Subject: [PATCH] refactor(login): add comments --- src/services/LoginMethodStrategy/NostrLoginStrategy.ts | 6 ++++++ src/services/LoginMethodStrategy/PrivateKeyStrategy.ts | 6 ++++++ src/services/LoginMethodStrategy/loginMethodContext.ts | 7 +++++++ src/services/LoginMethodStrategy/loginMethodStrategy.ts | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/src/services/LoginMethodStrategy/NostrLoginStrategy.ts b/src/services/LoginMethodStrategy/NostrLoginStrategy.ts index 23d0215..b92844a 100644 --- a/src/services/LoginMethodStrategy/NostrLoginStrategy.ts +++ b/src/services/LoginMethodStrategy/NostrLoginStrategy.ts @@ -3,6 +3,12 @@ import { SignedEvent } from '../../types' import { LoginMethodStrategy } from './loginMethodStrategy' import { WindowNostr } from 'nostr-tools/nip07' +/** + * Login Method Strategy when using nostr-login package. + * + * This class extends {@link LoginMethodStrategy base strategy} and implements all login method operations + * @see {@link LoginMethodStrategy} + */ export class NostrLoginStrategy extends LoginMethodStrategy { private nostr: WindowNostr diff --git a/src/services/LoginMethodStrategy/PrivateKeyStrategy.ts b/src/services/LoginMethodStrategy/PrivateKeyStrategy.ts index b1f646d..230cd5c 100644 --- a/src/services/LoginMethodStrategy/PrivateKeyStrategy.ts +++ b/src/services/LoginMethodStrategy/PrivateKeyStrategy.ts @@ -12,6 +12,12 @@ import { AuthState, LoginMethod } from '../../store/auth/types' import { LoginMethodStrategy } from './loginMethodStrategy' import { verifySignedEvent } from '../../utils/nostr' +/** + * Login Method Strategy when using dev private key login. + * + * This class extends {@link LoginMethodStrategy base strategy} and implements all login method operations + * @see {@link LoginMethodStrategy} + */ export class PrivateKeyStrategy extends LoginMethodStrategy { async nip04Encrypt(receiver: string, content: string): Promise { const keys = (store.getState().auth as AuthState).keyPair diff --git a/src/services/LoginMethodStrategy/loginMethodContext.ts b/src/services/LoginMethodStrategy/loginMethodContext.ts index a68f7df..6542ece 100644 --- a/src/services/LoginMethodStrategy/loginMethodContext.ts +++ b/src/services/LoginMethodStrategy/loginMethodContext.ts @@ -8,6 +8,13 @@ import { LoginMethod } from '../../store/auth/types' import { NostrLoginStrategy } from './NostrLoginStrategy' import { PrivateKeyStrategy } from './PrivateKeyStrategy' +/** + * This class is a context provider and helper class. This MUST be instantiated and used as an entry point for any of the {@link LoginMethodOperations LoginMethodOperations} + * @constructor Takes {@link LoginMethod LoginMethod} as an argument and sets the correct strategy + * + * @see {@link LoginMethod} + * @see {@link LoginMethodOperations} + */ export class LoginMethodContext implements LoginMethodOperations { private strategy: LoginMethodStrategy diff --git a/src/services/LoginMethodStrategy/loginMethodStrategy.ts b/src/services/LoginMethodStrategy/loginMethodStrategy.ts index 9ad99fb..35830bc 100644 --- a/src/services/LoginMethodStrategy/loginMethodStrategy.ts +++ b/src/services/LoginMethodStrategy/loginMethodStrategy.ts @@ -2,6 +2,9 @@ import { EventTemplate, UnsignedEvent } from 'nostr-tools' import { SignedEvent } from '../../types/nostr' +/** + * This interface holds all operations that are dependant on the login method and is used as the basis for the login strategies. + */ export interface LoginMethodOperations { nip04Encrypt(receiver: string, content: string): Promise nip04Decrypt(sender: string, content: string): Promise @@ -10,6 +13,10 @@ export interface LoginMethodOperations { signEvent(event: UnsignedEvent | EventTemplate): Promise } +/** + * This is the fallback class that provides base implementation for the {@link LoginMethodOperations login method operations} . Only used to throw errors in case when the LoginMethod is missing (login context not set). + * @see {@link LoginMethodOperations} + */ export class LoginMethodStrategy implements LoginMethodOperations { async nip04Encrypt(_receiver: string, _content: string): Promise { throw new Error('Login method strategy is undefined')