Created
December 4, 2018 22:41
-
-
Save joaoaguiam/cfca66b182a92fe50f1914136bd3847f to your computer and use it in GitHub Desktop.
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
module.exports = { | |
/** | |
* Verify github account method. It will return the github username if verified correctly. | |
* @param did DID of the user to be verified | |
* @param proof URL to the gist file under the user account containing the user DID. | |
* @returns Object containing the github user in the data field and in case of error, the error message under the error field. | |
*/ | |
verifyGithub: async (did, proof) => { | |
if (!proof || proof.trim() === "") { | |
throw new Error("verifyGithub: proof (gist url) parameter is not present"); | |
} | |
if (!did || did.trim() === "") { | |
throw new Error("verifyGithub: DID parameter is not present"); | |
} | |
let gistFileContent = await (await fetch(proof)).text(); | |
if (gistFileContent.trim() !== did) { | |
return { error: "Gist File provided does not contain the correct DID" }; | |
} | |
const githubUsername = gistUrl.replace("https://gist.githubusercontent.com/", "").split("/")[0]; | |
return { data: githubUsername }; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment