Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function verifyTwitter (did, claim) {
if (!claim) return null
const verified = await didJWT.verifyJWT(claim)
if (verified.payload.sub !== did) {
throw new Error('Verification not valid for given user')
}
const claimData = verified.payload.claim
if (!claimData.twitter_handle || !claimData.twitter_proof) {
throw new Error('The claim for your twitter is not correct')
}
return {
username: claimData.twitter_handle,
proof: claimData.twitter_proof,
verifiedBy: verified.payload.iss
}
}
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
return _context6.abrupt('return', didJWT.verifyJWT(jwt, { audience: audience }));
case 1:
case 'end':
return _context6.stop();
}
}
}, _callee6, this);
}));
async verifyDid(token){
require('ethr-did-resolver')()
return await verifyJWT(token)
}
async authenticateDisclosureResponse(token, callbackUrl = null) {
const { payload, doc } = await verifyJWT(token, {
audience: this.did,
callbackUrl,
auth: true,
})
if (payload.req) {
const challenge = await verifyJWT(payload.req)
if (challenge.payload.iss !== this.did) {
throw new Error(`Challenge issuer does not match current identity: ${challenge.payload.iss} !== ${this.did}`)
} else if (challenge.payload.type !== Types.DISCLOSURE_REQUEST) {
throw new Error(`Challenge payload type invalid: ${challenge.payload.type}`)
} else {
return this.processDisclosurePayload({ payload, doc })
}
} else {
throw new Error('Challenge was not included in response')
}
}
const verifying = verified.map(token => verifyJWT(token, {audience: this.did}).catch(() => {
invalid.push(token)
return Promise.resolve(null)
}))
async verifyJWT (jwt, audience = this.did) {
return didJWT.verifyJWT(jwt, {audience})
}
verifyResponse (token) {
return verifyJWT(token, {audience: this.credentials.did}).then(res => {
this.doc = res.doc
return this.credentials.processDisclosurePayload(res)
})
}