Skip to content

Instantly share code, notes, and snippets.

const DIDPushAuthentication = request =>
compose(
map(passThrough(() => logger.debug('DID Push Authentication Success.'))),
flatMap(pushAuthentication),
flatMap(saveChallenge),
flatMap(decryptedDID => eitherToAsyncEffect(getEnvironmentVariables({ ...request, recipientDid: decryptedDID }))),
flatMap(did => eitherToAsyncEffect(getDecryptedDID(did))),
map(response => response.data.did),
flatMap(() => getDIDByUserName(request.userName)),
eitherToAsyncEffect,
const checkAuthenticationStatus = request =>
compose(
map(passThrough(response => logger.debug(`DID Authentication Status Response: ${deepInspect(response)}`))),
flatMap(response => eitherToAsyncEffect(getJWT(response))),
flatMap(() => getAuthenticationByChallengeId(request)),
eitherToAsyncEffect,
validateRequest,
map(passThrough(request => logger.debug(`DID Authentication Status Request: ${deepInspect(request)}`)))
)(request);
const Callback = request =>
compose(
map(passThrough(() => logger.debug('DID Authentication Callback Request Stored In Fauna.'))),
flatMap(storeSuccessfulAuthentication),
flatMap(request => eitherToAsyncEffect(encryptDID(request))),
flatMap(validateChallenge),
eitherToAsyncEffect,
validateRequest,
map(passThrough(request => logger.debug(`DID Authentication Callback Request: ${deepInspect(request)}`))),
)(request);
import { authentication } from 'didauth';
const payload = {
clientId: 'client id', // client id provided by MATTR
clientSecret: 'client secret', // client secret provided by MATTR
tenant: 'your-tenant.vii.mattr.global', // your tenant provided by MATTR
did: 'did:method:code', // your verifier DID representing your application created in MATTR platform
challengeId: 'your-challenge-id', // custom ID provided by your application to connect request internally
templateId: 'presentation template id', // presentation template ID created in MATTR platform
callbackURL: 'https://your-domain.tld/didauth/callback' // callback url of your website that the digital wallet will call
// composition snippet from https://github.com/MeetMartin/did-authentication/blob/main/effects/Authentication.js
const DIDAuthentication = challengeId =>
compose(
map(passThrough(url => logger.debug(`DID Authentication Redirect URL: ${deepInspect(url)}`))),
flatMap(authentication),
flatMap(saveChallenge),
eitherToAsyncEffect,
map(passThrough(input => logger.debug(`DID Authentication Input Variables: ${deepInspect(input)}`))),
getInputVariables,
import { SignJWT, jwtVerify, importSPKI, importPKCS8 } from 'jose';
const privateKey =
`-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIMpFEKC3T8wWYu2e+63MuicRSt4ddWXGIZFXw4vnk+aL
-----END PRIVATE KEY-----`;
const publicKey =
`-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA+L7HHlAU8Zviz0MCX4VSY1xRnX0UTSwb2bQPF6Oqh0g=
import { authentication } from 'didauth';
authentication(payload)
.trigger
(errors => console.log(errors) || ({
statusCode: 500,
body: 'Internal Server Error'
}))
(JWSURL => ({
statusCode: 301,
# private key
openssl genpkey -algorithm rsa -out rsa-private.pem
# public key
openssl pkey -in rsa-private.pem -pubout -out rsa-public.pem
# private key
openssl genpkey -algorithm ed25519 -out eddsa-private.pem
# public key
openssl pkey -in eddsa-private.pem -pubout -out eddsa-public.pem
const myJWT = 'eyJhbGciOfJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkaWWiOiJka…afyMH0.WrIEBW5LNLjfGWqIA4XKsyIiuWzbIIpNadfZVkmA6hPs';
// store JWT in session storage
sessionStorage.setItem('JWT', myJWT);
console.log('My JWT is', sessionStorage.getItem('JWT'));
// remove JWT from storage
sessionStorage.removeItem('JWT');