-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting up route handlers to controllers
- Loading branch information
Showing
9 changed files
with
132 additions
and
10 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
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
Empty file.
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,39 @@ | ||
import {password} from '../../config' | ||
import {ControllerArguments} from './registration' | ||
import {Response, Request} from 'express' | ||
|
||
const generateCredentialOffer = async ( | ||
options: ControllerArguments, | ||
req: Request, | ||
res: Response | ||
) => { | ||
const {identityWallet} = options | ||
|
||
try { | ||
const credOffer = await identityWallet.create.interactionTokens.request.offer( | ||
{ | ||
callbackURL: '/receive/', | ||
requestedInput: {}, | ||
instant: true | ||
}, | ||
password | ||
) | ||
|
||
return res.status(200).send({token: credOffer.encode()}) | ||
} catch (err) { | ||
return res.status(500).send({error: err.message}) | ||
} | ||
} | ||
|
||
const consumeCredentialOfferResponse = async ( | ||
options: ControllerArguments, | ||
req: Request, | ||
res: Response | ||
) => { | ||
console.log('YES') | ||
} | ||
|
||
export const issuance = { | ||
generateCredentialOffer, | ||
consumeCredentialOfferResponse | ||
} |
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,79 @@ | ||
import {credentialRequirements, password} from '../../config' | ||
import {Express, Request, Response} from 'express' | ||
import {extractDataFromClaims} from '../helpers/' | ||
import {IdentityWallet} from 'jolocom-lib/js/identityWallet/identityWallet' | ||
import {JolocomLib} from 'jolocom-lib' | ||
|
||
export interface ControllerArguments { | ||
app: Express; | ||
identityWallet: IdentityWallet; | ||
password: string; | ||
} | ||
|
||
const generateCredentialShareRequest = async ( | ||
options: ControllerArguments, | ||
req: Request, | ||
res: Response | ||
) => { | ||
const {identityWallet} = options | ||
const callbackURL = '/authentication' | ||
|
||
const credentialRequest = await identityWallet.create.interactionTokens.request.share( | ||
{ | ||
callbackURL, | ||
credentialRequirements | ||
}, password | ||
) | ||
|
||
res.send({token: credentialRequest.encode()}) | ||
} | ||
|
||
const consumeCredentialShareResponse = async ( | ||
options: ControllerArguments, | ||
req: Request, | ||
res: Response | ||
) => { | ||
const {token} = req.body | ||
const {identityWallet} = options | ||
|
||
try { | ||
const credentialResponse = await JolocomLib.parse.interactionToken.fromJWT(token) | ||
|
||
if (!(await JolocomLib.util.validateDigestable(credentialResponse))) { | ||
return res.status(401).send('Invalid signature on interaction token') | ||
} | ||
|
||
// TODO include | parse this from request | ||
const credentialRequest = await identityWallet.create.interactionTokens.request.share( | ||
{ | ||
callbackURL: '/authenticate', | ||
credentialRequirements | ||
}, password | ||
) | ||
|
||
if (!credentialResponse.interactionToken.satisfiesRequest(credentialRequest.interactionToken)) { | ||
return res.status(401).send('The supplied credentials do not match the types of the requested credentials') | ||
} | ||
|
||
const userData = { | ||
...extractDataFromClaims(credentialResponse.interactionToken), | ||
did: credentialResponse.issuer, | ||
status: 'success' | ||
} | ||
console.log(userData) | ||
|
||
// await setAsync( | ||
// identifier, | ||
// JSON.stringify({status: 'success', data: userData}) | ||
// ) | ||
|
||
return res.status(200) | ||
} catch (err) { | ||
return res.status(401).send(err.message) | ||
} | ||
} | ||
|
||
export const registration = { | ||
generateCredentialShareRequest, | ||
consumeCredentialShareResponse | ||
} |
File renamed without changes.
Empty file.
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