Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The main code was not running in my pc, so I made changes in the code . Can anyone check it out?? #46

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"homepage": "https://github.com/CatoffGaming/catoff-reclaim-integration-proposal#readme",
"dependencies": {
"@reclaimprotocol/js-sdk": "^1.3.6",
"@reclaimprotocol/zk-fetch": "^0.1.2",
"axios": "^1.7.2",
"body-parser": "^1.20.2",
"dotenv": "^16.4.5",
Expand Down
Empty file added readme1.md
Empty file.
1 change: 1 addition & 0 deletions src/controllers/reclaimController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { signWithProviderID } = require('../services/reclaimService')

exports.signHandler = async (req, res) => {
const { userId, providerId } = req.body
console.log(req.body);

try {
const signedUrl = await signWithProviderID(userId, providerId)
Expand Down
26 changes: 26 additions & 0 deletions src/services/githubService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const axios = require('axios')
const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse')

exports.processGitHubData = async (proof, providerName) => {
console.log("go for it : ",providerName)
const githubUsername = JSON.parse(proof[0].claimData.context)
.extractedParameters.userName
const lastUpdateTimeStamp = proof[0].claimData.timestampS
Expand All @@ -22,6 +23,7 @@ const getUserCommits = async username => {
const dateSince = new Date(new Date().setDate(new Date().getDate() - daysAgo))
.toISOString()
.split('T')[0]
console.log("user name : ",username)
const url = `https://api.github.com/search/commits?q=author:${username}+committer-date:>${dateSince}`
const githubToken = process.env.RECLAIM_GITHUB_TOKEN

Expand All @@ -37,3 +39,27 @@ const getUserCommits = async username => {
)
return response.data.total_count
}





// // Package import
// import { Reclaim } from '@reclaimprotocol/js-sdk';

// const getVerificationReq = async () => {
// const reclaimClient = new Reclaim.ProofRequest("0x449c4A598810232e36e56579eBB8e28DFb98C47B" );
// const providerIds = [
// 'bc3ebc42-0726-4ac8-9d6b-c4cde5cfa145', // Tyretp
// ];
// const APP_SECRET ="0x80758e792730a0993e3271ccc81b17c1d40a309079165e86ec5713f71e9a2dea" // your app secret key.

// await reclaimClient.buildProofRequest(providerIds[0])
// reclaimClient.setSignature(
// await reclaimClient.generateSignature(
// APP_SECRET
// )
// )
// const {reclaimUrl, statusUrl} = await reclaimClient.createVerificationRequest()
// return {reclaimUrl, statusUrl}
// }
Empty file added src/services/new1.js
Empty file.
48 changes: 47 additions & 1 deletion src/services/reclaimService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,41 @@ const { Reclaim } = require('@reclaimprotocol/js-sdk')
const { RECLAIM_PROVIDER_ID, RECLAIM_APP_ID } = require('../utils/constants')
const { processTwitterData } = require('./twitterService')
const { processGitHubData } = require('./githubService')
require('dotenv').config();

exports.signWithProviderID = async (userId, providerId) => {
console.log("boo : ",userId,providerId);
console.log("RECLAIM_PROVIDER_ID edfe : ",RECLAIM_PROVIDER_ID[providerId])
const providerName = RECLAIM_PROVIDER_ID[providerId]
console.log("Provider name : " ,providerName)
const reclaimAppID = RECLAIM_APP_ID[providerName]
console.log("reclaimAppID : " ,reclaimAppID)
//const hj=`${providerName}_SECRET`;
const reclaimAppSecret = process.env[`${providerName}_SECRET`]
console.log("reclaimAppSecret : " ,reclaimAppSecret)

console.log(
`Sending signature request to Reclaim for userId: ${userId} with providerName: ${providerName}`
)

try {
const reclaimClient = new Reclaim.ProofRequest(reclaimAppID)
console.log(reclaimClient)
await reclaimClient.buildProofRequest(providerId)
reclaimClient.setSignature(
await reclaimClient.generateSignature(reclaimAppSecret)
)

const { requestUrl: signedUrl } =
await reclaimClient.createVerificationRequest()
console.log("hhhbb :",{ requestUrl: signedUrl })

await handleReclaimSession(userId, reclaimClient, providerName)


console.log("ended");
return signedUrl

} catch (error) {
console.error(
`Failed to process Reclaim request for userId: ${userId}`,
Expand All @@ -34,20 +48,27 @@ exports.signWithProviderID = async (userId, providerId) => {
}

const handleReclaimSession = async (userId, reclaimClient, providerName) => {

await reclaimClient.startSession({

onSuccessCallback: async proof => {
console.log("two")
console.log(
`Successful reclaim callback with proof: ${JSON.stringify(proof)}`
)
console.log("aa : ",proof);

try {
let processedData
console.log("two");
switch (providerName) {
case 'TWITTER_ANALYTICS_VIEWS':
processedData = await processTwitterData(proof, providerName)
break
case 'GITHUB_ACCOUNT_VERIFICATION':
case 'GITHUB_ACCOUNT':
console.log("fourth")
processedData = await processGitHubData(proof, providerName)

break
default:
throw new Error(`No handler for provider: ${providerName}`)
Expand All @@ -65,4 +86,29 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => {
console.error(`Verification failed for userId: ${userId}`, error)
},
})
//console.log("hgvnbm : ",t )
}


console.log("ended");


// // Package import
// import { Reclaim } from '@reclaimprotocol/js-sdk';

// const getVerificationReq = async () => {
// const reclaimClient = new Reclaim.ProofRequest("0x695FC75718ed80E17c4A72660314483Decf393B2" );
// const providerIds = [
// '7369ce2a-5e2f-436d-9df7-918197d26b81', // github name1
// ];
// const APP_SECRET ="0x29f88462113efb62bd5e1079bea7ea0eb2684e38bcda505cb1e4438adf606b09" // your app secret key.

// await reclaimClient.buildProofRequest(providerIds[0])
// reclaimClient.setSignature(
// await reclaimClient.generateSignature(
// APP_SECRET
// )
// )
// const {reclaimUrl, statusUrl} = await reclaimClient.createVerificationRequest()
// return {reclaimUrl, statusUrl}
// }
9 changes: 6 additions & 3 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
exports.RECLAIM_PROVIDER_ID = {
twitter: 'TWITTER_ANALYTICS_VIEWS',
github: 'GITHUB_ACCOUNT_VERIFICATION',
'github-provider-id':'GITHUB_ACCOUNT',// add the provider id inside 'Apostrophe'
}

exports.RECLAIM_APP_ID = {
TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id',
GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id',
GITHUB_ACCOUNT: 'github-app-id',/// inside the Apostrophe
}

//user id : 4a1c50a83cf6cc4b55b6b9c53e553e3f847c876b87fb333f71f5d05db8f1a7db

// app secret 0x29f88462113efb62bd5e1079bea7ea0eb2684e38bcda505cb1e4438adf606b09