-
Notifications
You must be signed in to change notification settings - Fork 9
/
authenticationFlow.ts
32 lines (28 loc) · 1.28 KB
/
authenticationFlow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Authentication } from 'jolocom-lib/js/interactionTokens/authentication'
import { InteractionType } from 'jolocom-lib/js/interactionTokens/types'
import { Flow } from './flow'
import { AuthenticationFlowState, FlowType } from './types'
import { isAuthenticationRequest } from './guards'
export class AuthenticationFlow extends Flow<Authentication> {
public state: AuthenticationFlowState = { description: '' }
public type = FlowType.Authentication
// TODO InteractionType.AuthenticaitonResponse should exist
public async handleInteractionToken(token: Authentication, interactionType: string) {
// FIXME what's with this multilayer type checking
switch (interactionType) {
case InteractionType.Authentication:
// FIXME there's already enough type information from the guard
// These guards are necessary, the instanceof check can happen here
// directly
if (isAuthenticationRequest(token)) {
return this.consumeAuthenticationRequest(token)
}
default:
throw new Error('Interaction type not found')
}
}
public async consumeAuthenticationRequest(token: Authentication) {
if (!this.state.description) this.state.description = token.description
return this.state.description === token.description
}
}