-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7892578
commit 16da1ec
Showing
44 changed files
with
370 additions
and
689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { EvmAddress } from '@lens-protocol/shared-kernel'; | ||
|
||
import { ProfileId } from './Profile'; | ||
|
||
export interface ICredentials { | ||
readonly address: string; | ||
readonly address: EvmAddress; | ||
readonly profileId: ProfileId; | ||
|
||
isExpired(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { EvmAddress, failure, PromiseResult, Result, success } from '@lens-protocol/shared-kernel'; | ||
|
||
import { | ||
ICredentials, | ||
PendingSigningRequestError, | ||
ProfileId, | ||
UserRejectedError, | ||
Wallet, | ||
WalletConnectionError, | ||
} from '../../entities'; | ||
import { SessionData } from './SessionData'; | ||
|
||
/** | ||
* The details required to authenticate the session. | ||
*/ | ||
export type LoginRequest = { | ||
/** | ||
* The Profile Owner or an authorized Profile Manager. | ||
*/ | ||
address: EvmAddress; | ||
/** | ||
* The authenticated Profile ID. | ||
*/ | ||
profileId: ProfileId; | ||
}; | ||
|
||
export interface IWalletFactory { | ||
create(address: EvmAddress): Promise<Wallet>; | ||
} | ||
|
||
export interface IWritableWalletGateway { | ||
save(wallet: Wallet): Promise<void>; | ||
} | ||
|
||
export type LoginError = PendingSigningRequestError | UserRejectedError | WalletConnectionError; | ||
|
||
export interface ILoginPresenter { | ||
present(result: Result<SessionData, LoginError>): void; | ||
} | ||
|
||
export interface ICredentialsIssuer { | ||
issueCredentials(request: LoginRequest): PromiseResult<ICredentials, LoginError>; | ||
} | ||
|
||
export interface ICredentialsWriter { | ||
save(credentials: ICredentials): Promise<void>; | ||
} | ||
|
||
export class Login { | ||
constructor( | ||
private readonly walletFactory: IWalletFactory, | ||
private readonly walletGateway: IWritableWalletGateway, | ||
private readonly credentialsIssuer: ICredentialsIssuer, | ||
private readonly credentialsWriter: ICredentialsWriter, | ||
private readonly presenter: ILoginPresenter, | ||
) {} | ||
|
||
async login(request: LoginRequest): Promise<void> { | ||
const wallet = await this.walletFactory.create(request.address); | ||
const result = await this.credentialsIssuer.issueCredentials(request); | ||
|
||
if (result.isFailure()) { | ||
this.presenter.present(failure(result.error)); | ||
return; | ||
} | ||
|
||
await this.walletGateway.save(wallet); | ||
await this.credentialsWriter.save(result.value); | ||
|
||
this.presenter.present(success(request)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/domain/src/use-cases/authentication/SessionData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EvmAddress } from '@lens-protocol/shared-kernel'; | ||
|
||
import { ProfileId } from '../../entities'; | ||
|
||
/** | ||
* Describes the details of an authenticated session. | ||
*/ | ||
export type SessionData = { | ||
/** | ||
* The Profile Owner or an authorized Profile Manager. | ||
*/ | ||
address: EvmAddress; | ||
/** | ||
* The authenticated Profile ID. | ||
*/ | ||
profileId: ProfileId; | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/domain/src/use-cases/authentication/__helpers__/mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { mockEvmAddress } from '@lens-protocol/shared-kernel/mocks'; | ||
import { mock } from 'jest-mock-extended'; | ||
import { when } from 'jest-when'; | ||
|
||
import { Wallet } from '../../../entities'; | ||
import { mockProfileId, mockWallet } from '../../../entities/__helpers__/mocks'; | ||
import { ActiveWallet } from '../ActiveWallet'; | ||
import { LoginRequest } from '../Login'; | ||
|
||
export function mockLoginRequest(): LoginRequest { | ||
return { | ||
address: mockEvmAddress(), | ||
profileId: mockProfileId(), | ||
}; | ||
} | ||
|
||
export function mockActiveWallet({ wallet = mockWallet() }: { wallet?: Wallet } = {}) { | ||
const activeWallet = mock<ActiveWallet>(); | ||
|
||
when(activeWallet.requireActiveWallet).mockResolvedValue(wallet); | ||
|
||
return activeWallet; | ||
} |
Oops, something went wrong.