Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'did-jwt' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
async signJWT (payload) {
const settings = {
signer: this.keyring.getJWTSigner(),
issuer: this.did
// TODO - should we have an expiry?
}
return didJWT.createJWT(payload, settings)
}
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
settings = {
signer: this.keyring.getJWTSigner(),
issuer: this.did
// TODO - should we have an expiry?
};
return _context5.abrupt('return', didJWT.createJWT(payload, settings));
case 2:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
forEach(json.claims, (jwt: string) => {
try {
const decodedClaim = decodeJWT(jwt)
if (decodedClaim) {
const signedClaim: VerifiableClaim = {
...decodedClaim.payload,
jwt,
source: {
type: 'matrix',
id: roomId,
},
}
result.push(signedClaim)
}
} catch (e) {
// invalid jwt
}
})
const parseResponse = (res) => {
if (res.error) return Promise.reject(Object.assign({id}, res))
if (message.util.isJWT(res.payload)) {
const jwt = res.payload
const decoded = decodeJWT(jwt)
if (decoded.payload.claim){
return Promise.resolve(Object.assign({id}, res))
}
return this.verifyResponse(jwt).then(parsedRes => {
// Set identifiers present in the response
// TODO maybe just change name in uport-js
if (parsedRes.boxPub) parsedRes.publicEncKey = parsedRes.boxPub
this.setState(parsedRes)
return {id, payload: parsedRes, data: res.data}
})
} else {
return Promise.resolve(Object.assign({id}, res))
}
}
const parseResponse = (res) => {
if (res.error) return Promise.reject(Object.assign({id}, res))
if (message.util.isJWT(res.payload)) {
const jwt = res.payload
const decoded = decodeJWT(jwt)
if (decoded.payload.claim){
return Promise.resolve(Object.assign({id}, res))
}
return this.verifyResponse(jwt).then(parsedRes => {
// Set identifiers present in the response
// TODO maybe just change name in uport-js
if (parsedRes.boxPub) parsedRes.publicEncKey = parsedRes.boxPub
this.setState(parsedRes)
return {id, payload: parsedRes, data: res.data}
})
} else {
return Promise.resolve(Object.assign({id}, res))
}
}
const transport = (uri, opts) => {
const jwt = message.util.getURLJWT(uri)
const decoded = didjwt.decodeJWT(jwt)
expect(/chasqui/.test(decoded.payload.callback)).to.be.true
done()
}
const uport = new Connect('testApp', { transport, vc })
const send = (uri) => {
const jwt = getURLJWT(uri)
const decoded = didjwt.decodeJWT(jwt)
expect(decoded.payload.to).to.equal('2ooE3vLGYi9vHmfYSc3ZxABfN5p8756sgi6')
done()
}
const uport = new Connect('testApp', { vc })
const claims = _.map(encodedClaims, (jwt: string) => {
let result: VerifiableClaim = null
try {
const decodedClaim = decodeJWT(jwt)
result = {
...decodedClaim.payload,
jwt,
}
} catch (e) {
console.log(e)
}
return result
})
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
}
}