diff --git a/.env.example b/.env.example index 2494daa..9e221b9 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ TWITTER_ANALYTICS_VIEWS_SECRET=your-twitter-secret GITHUB_ACCOUNT_VERIFICATION_SECRET=your-github-secret RECLAIM_GITHUB_TOKEN=your-github-token +hugging_SECRET=your-hugging-secret diff --git a/CRIP/CRIP-1.md b/CRIP/CRIP-1.md deleted file mode 100644 index 94a392f..0000000 --- a/CRIP/CRIP-1.md +++ /dev/null @@ -1,74 +0,0 @@ -| proposal | title | description | author | discussions-to | status | type | category | created | requires | -|----------|--------------------|-------------------------------|----------------------------|----------------|--------|-------------|----------|------------|----------| -| CRIP-1 | GitHub Integration | Integration with GitHub API to validate user contributions | John Doe | | Draft | Integration | CRIP | 2024-06-01 | | - -## Title - -GitHub Integration - -## Introduction - -This proposal outlines the integration of GitHub as a data provider for the Catoff-Reclaim integration project. The integration aims to retrieve and process user activity data from GitHub, such as commit history and repository contributions, to be used within the Catoff platform. This will enable users to validate their GitHub contributions and use them for various challenges and verifications on Catoff. - -## External APIs Needed - -- GitHub API: https://docs.github.com/en/rest - -## Use Cases - -1. **User Verification**: Verify the activity of users on GitHub by checking their commit history and contributions. -2. **Challenge Participation**: Allow users to participate in challenges that require proof of GitHub activity. -3. **Skill Assessment**: Assess users' coding skills and contributions based on their GitHub activity. - -## Data Provider - -- **Name**: Github UserName - Fix -- **Hash Value**: 0x68274d4815b6a7c91170c89d3a8cec3b54f4e21f0faf223e677a9134a31f2b32 - -## Code Snippet - -Below is a code snippet that demonstrates the key parts of the GitHub integration. The full implementation should follow the service file template. - -**`services/githubService.js`** - -```javascript -const axios = require('axios') -const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse') - -exports.processGitHubData = async (proof, providerName) => { - const githubUsername = JSON.parse(proof[0].claimData.context) - .extractedParameters.userName - const lastUpdateTimeStamp = proof[0].claimData.timestampS - - const commitCount = await getUserCommits(githubUsername) - - return new ReclaimServiceResponse( - providerName, - lastUpdateTimeStamp, - githubUsername, - commitCount, - proof[0] - ) -} - -const getUserCommits = async username => { - const daysAgo = 3650 // Approx. 10 years - const dateSince = new Date(new Date().setDate(new Date().getDate() - daysAgo)) - .toISOString() - .split('T')[0] - const url = `https://api.github.com/search/commits?q=author:${username}+committer-date:>${dateSince}` - const githubToken = process.env.RECLAIM_GITHUB_TOKEN - - const response = await axios.get(url, { - headers: { - Accept: 'application/vnd.github.cloak-preview', - Authorization: `token ${githubToken}`, - }, - }) - - console.log( - `Total commits by ${username} in the last 10 years: ${response.data.total_count}` - ) - return response.data.total_count -} -``` diff --git a/CRIP/CRIP-HuggingIntegration.md b/CRIP/CRIP-HuggingIntegration.md new file mode 100644 index 0000000..783c09e --- /dev/null +++ b/CRIP/CRIP-HuggingIntegration.md @@ -0,0 +1,52 @@ +| proposal | title | description | author | discussions-to | status | type | category | created | requires | +| ----------- | ------------------- | ------------------------------------------- | -------------------------------------------- | -------------- | ------ | ----------- | -------- | ---------- | -------- | +| CRIP-Strava | Hugging Face Integration | Integration with Hugging Face to verify username | Ritik Prajapat | | Draft | Integration | CRIP | 2024-07-14 | | + +## Title + +Hugging Face Integration + +## Introduction + +This proposal outlines the integration of Hugging Face as a data provider for the Catoff-Reclaim integration project. The integration aims to retrieve and process username on Hugging Face that is to be used within the Catoff platform. This will enable users to validate their claim regarding username needed for various challenges and verifications on Catoff. + +## Use Cases + +1. **User Verification**: Verify the activity of users on Hugging Face by checking their username. +2. **Challenge Participation**: Allow users to participate in challenges that require proof of hugging face username and activity. +3. **Skill Assessment**: Assess users' claim regarding hugging face username. + +## Data Provider + +- **Name**: Hugging Face username dbg +- **Hash Value**: 0xfce8f4b1a3a162135da558676fec0ac61c0cc05a577af0b9420d3aed3e4c4839 + +## Code Snippet + +Below is a code snippet that demonstrates the key parts of the GitHub integration. The full implementation should follow the service file template. + +**`services/githubService.js`** + +```javascript +const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse') + +exports.processhuggingData = async (proof, providerName) => { + const extractedParameters = JSON.parse( + proof[0].claimData.context + ).extractedParameters + + const username = extractedParameters.username + + console.log(`Hugging Face user: ${username}`) + + const lastUpdateTimeStamp = proof[0].claimData.timestampS + + return new ReclaimServiceResponse( + providerName, + lastUpdateTimeStamp, + username, + username, + proof[0] + ) +} +``` diff --git a/src/services/huggingService.js b/src/services/huggingService.js new file mode 100644 index 0000000..f7517ae --- /dev/null +++ b/src/services/huggingService.js @@ -0,0 +1,21 @@ +const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse') + +exports.processhuggingData = async (proof, providerName) => { + const extractedParameters = JSON.parse( + proof[0].claimData.context + ).extractedParameters + + const username = extractedParameters.username + + console.log(`Hugging Face user: ${username}`) + + const lastUpdateTimeStamp = proof[0].claimData.timestampS + + return new ReclaimServiceResponse( + providerName, + lastUpdateTimeStamp, + username, + username, + proof[0] + ) +} diff --git a/src/services/newIntegrationService.js b/src/services/newIntegrationService.js deleted file mode 100644 index 23f1e0f..0000000 --- a/src/services/newIntegrationService.js +++ /dev/null @@ -1,22 +0,0 @@ -const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse') - -exports.processNewIntegrationData = async (proof, providerName) => { - // TODO: Extract relevant data from the proof - // Replace 'newParameter' with the actual parameter you need to extract - const newData = JSON.parse(proof[0].claimData.context).extractedParameters.newParameter - - // TODO: Process the extracted data - // Adjust the extraction logic based on the actual format of the data - // For example, if the data is a string with numeric value - const newValue = newData.match(/value=\\"([\d,]+)/)[1].replace(/,/g, '') - - // TODO: Extract additional relevant data from the proof - const url = JSON.parse(proof[0].claimData.parameters).url - const matchurl = url.match(/user\/([^\/]+)/) - const username = matchurl ? matchurl[1] : null - const lastUpdateTimeStamp = JSON.parse(proof[0].claimData.timestampS) - - // TODO: Create a ReclaimServiceResponse object with the processed data - // Adjust the parameters and processing logic based on the actual data structure - return new ReclaimServiceResponse(providerName, lastUpdateTimeStamp, username, parseInt(newValue, 10), proof[0]) -} diff --git a/src/services/reclaimService.js b/src/services/reclaimService.js index b33006f..007d1a0 100644 --- a/src/services/reclaimService.js +++ b/src/services/reclaimService.js @@ -1,10 +1,14 @@ -const axios = require('axios') +const dotenv = require('dotenv') const { Reclaim } = require('@reclaimprotocol/js-sdk') const { RECLAIM_PROVIDER_ID, RECLAIM_APP_ID } = require('../utils/constants') const { processTwitterData } = require('./twitterService') const { processGitHubData } = require('./githubService') +const { processhuggingData } = require('./huggingService') + +dotenv.config() exports.signWithProviderID = async (userId, providerId) => { + console.log(userId, providerId) const providerName = RECLAIM_PROVIDER_ID[providerId] const reclaimAppID = RECLAIM_APP_ID[providerName] const reclaimAppSecret = process.env[`${providerName}_SECRET`] @@ -49,6 +53,9 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => { case 'GITHUB_ACCOUNT_VERIFICATION': processedData = await processGitHubData(proof, providerName) break + case 'hugging': + processedData = await processhuggingData(proof, providerName) + break default: throw new Error(`No handler for provider: ${providerName}`) } diff --git a/src/utils/constants.js b/src/utils/constants.js index 1c58669..c01f906 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -1,9 +1,11 @@ exports.RECLAIM_PROVIDER_ID = { twitter: 'TWITTER_ANALYTICS_VIEWS', github: 'GITHUB_ACCOUNT_VERIFICATION', + hugging: 'HUGGING_USERNAME_INTEGRATION', } exports.RECLAIM_APP_ID = { TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id', GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id', + HUGGING_USERNAME_INTEGRATION: 'your-hugging-app-id', }