Skip to content

Instantly share code, notes, and snippets.

@joaoaguiam
Created December 4, 2018 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaoaguiam/cfca66b182a92fe50f1914136bd3847f to your computer and use it in GitHub Desktop.
Save joaoaguiam/cfca66b182a92fe50f1914136bd3847f to your computer and use it in GitHub Desktop.
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