diff --git a/CRIP/CRIP-HumanBenchmarkWordsPerMinute.md b/CRIP/CRIP-HumanBenchmarkWordsPerMinute.md new file mode 100644 index 0000000..61ec8ef --- /dev/null +++ b/CRIP/CRIP-HumanBenchmarkWordsPerMinute.md @@ -0,0 +1,54 @@ +| proposal | title | description | author | discussions-to | status | type | category | created | requires | +|----------|--------------------------------|--------------------------------------------------------------------|---------------------------|----------------|--------|-------------|----------|------------|----------| +| CRIP-14 | Human Benchmark Words Per Minute | Integration with Human Benchmark to verify Words Per Minute Score | Ritik Bhatt | | Draft | Integration | CRIP | 2024-07-07 | | + +## Title + +Human Benchmark Words Per Minute Integration + +## Introduction + +This proposal outlines the integration of Human Benchmark as a data provider for the Catoff-Reclaim integration project. The integration focuses on retrieving and processing the Words Per Minute (WPM) score from Human Benchmark, enabling users to verify their typing speed on the Catoff platform. Users will be able to utilize their WPM data for various challenges and verifications. + +## External APIs Needed + +- **Human Benchmark API**: Currently, Human Benchmark does not provide a public API for accessing Words Per Minute scores, so this integration will rely on data extraction methods from the Human Benchmark app/web. + +## Use Cases + +1. **User Verification**: Verify the Words Per Minute (WPM) score on a user's Human Benchmark account. +2. **Challenge Participation**: Allow users to participate in challenges that require proof of their WPM score on Human Benchmark. +3. **Typing Speed Benchmarking**: Validate users' typing abilities based on their WPM score. + +## Data Provider + +- **Name**: Human Benchmark Words Per Minute +- **Hash Value**: 0x9f83e5b4c7a9b72c4e7b7c9d9e9b8d7e3f9b5d8c9f7c8d7e8f9f8e7b9f9b9d9f + +## Code Snippet + +Below is a code snippet that demonstrates the key parts of the Human Benchmark integration. The full implementation should follow the service file template. + +**`services/HumanBenchmarkWordsPerMinuteService.js`** + +```javascript +const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse'); + +exports.processHumanBenchmarkData = async (proof, providerName) => { + console.log("Proof is: ", proof[0]); + + const extractedParameters = JSON.parse(proof[0].claimData.context).extractedParameters; + + const lastUpdateTimeStamp = proof[0].claimData.timestampS; + const wordsPerMinute = extractedParameters.wordsPerMinute; + + console.log("The Words Per Minute on your Human Benchmark is:", wordsPerMinute); + + return new ReclaimServiceResponse( + providerName, + lastUpdateTimeStamp, + 'ritikbhatt', + wordsPerMinute, + proof[0] + ); +}; diff --git a/index.js b/index.js index df7fba0..bfbe55b 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,8 @@ const express = require('express') const bodyParser = require('body-parser') const reclaimController = require('./src/controllers/reclaimController') +require('dotenv').config(); + const app = express() app.use(bodyParser.json()) diff --git a/package.json b/package.json index ac9ddd6..dfe69c7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@reclaimprotocol/js-sdk": "^1.3.6", "axios": "^1.7.2", "body-parser": "^1.20.2", + "chess-web-api": "^1.2.0", "dotenv": "^16.4.5", "express": "^4.19.2" }, diff --git a/src/services/HumanBenchmarkWordsPerMinuteService.js b/src/services/HumanBenchmarkWordsPerMinuteService.js new file mode 100644 index 0000000..fe513f5 --- /dev/null +++ b/src/services/HumanBenchmarkWordsPerMinuteService.js @@ -0,0 +1,20 @@ +const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse'); + +exports.processHumanBenchmarkData = async (proof, providerName) => { + console.log("Proof is: ", proof[0]); + + const extractedParameters = JSON.parse(proof[0].claimData.context).extractedParameters; + + const lastUpdateTimeStamp = proof[0].claimData.timestampS; + const wordsPerMinute = extractedParameters.wordsPerMinute; + + console.log("The Words Per Minute on your Human Benchmark is:", wordsPerMinute); + + return new ReclaimServiceResponse( + providerName, + lastUpdateTimeStamp, + 'ritikbhatt', + wordsPerMinute, + proof[0] + ); +}; diff --git a/src/services/reclaimService.js b/src/services/reclaimService.js index b33006f..09c3b15 100644 --- a/src/services/reclaimService.js +++ b/src/services/reclaimService.js @@ -3,6 +3,7 @@ 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 { processHumanBenchmarkData } = require('./HumanBenchmarkWordsPerMinuteService') exports.signWithProviderID = async (userId, providerId) => { const providerName = RECLAIM_PROVIDER_ID[providerId] @@ -13,11 +14,11 @@ exports.signWithProviderID = async (userId, providerId) => { `Sending signature request to Reclaim for userId: ${userId} with providerName: ${providerName}` ) - try { - const reclaimClient = new Reclaim.ProofRequest(reclaimAppID) - await reclaimClient.buildProofRequest(providerId) + try { + const reclaimClient = new Reclaim.ProofRequest('0x0DaaA5139c462C7bCc8B2F11F792dDD6979f447F') + await reclaimClient.buildProofRequest('09af2449-842c-4a69-8ab9-4d261b014600') reclaimClient.setSignature( - await reclaimClient.generateSignature(reclaimAppSecret) + await reclaimClient.generateSignature('0x7f5bf7d559ffa24fd38c82ca99c657ea2458689d85e86fcbcde547d045f5a8d0') ) const { requestUrl: signedUrl } = await reclaimClient.createVerificationRequest() @@ -34,6 +35,7 @@ exports.signWithProviderID = async (userId, providerId) => { } const handleReclaimSession = async (userId, reclaimClient, providerName) => { + console.log('Starting session') await reclaimClient.startSession({ onSuccessCallback: async proof => { console.log( @@ -49,6 +51,9 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => { case 'GITHUB_ACCOUNT_VERIFICATION': processedData = await processGitHubData(proof, providerName) break + case 'HUMANBENCHMARK_ACCOUNT_VERIFICATION': + processedData = await processHumanBenchmarkData(proof, providerName); + break default: throw new Error(`No handler for provider: ${providerName}`) } @@ -65,4 +70,5 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => { console.error(`Verification failed for userId: ${userId}`, error) }, }) -} + console.log('Ended session') +} \ No newline at end of file diff --git a/src/utils/constants.js b/src/utils/constants.js index 1c58669..417d092 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -1,9 +1,17 @@ exports.RECLAIM_PROVIDER_ID = { twitter: 'TWITTER_ANALYTICS_VIEWS', github: 'GITHUB_ACCOUNT_VERIFICATION', + humanbenchmark: 'HUMANBENCHMARK_ACCOUNT_VERIFICATION' } exports.RECLAIM_APP_ID = { TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id', GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id', + HUMANBENCHMARK_ACCOUNT_VERIFICATION: 'your-humanbenchmark-app-id' } + +exports.PROVIDER_ID = { + twitter: 'twitter-provider-id', + github: 'github-provider-id', + humanbenchmark: 'humanbenchmark-provider-id' +} \ No newline at end of file