Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
54 changes: 54 additions & 0 deletions CRIP/CRIP-LeetcodeMaxStreak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
| proposal | title | description | author | discussions-to | status | type | category | created | requires |
|----------|----------------------------|----------------------------------------------------------|---------------------------|----------------|--------|-------------|----------|------------|----------|
| CRIP-11 | Leetcode Max Streak | Integration with Leetcode to verify user max streak | Ritik Bhatt <[email protected]> | | Draft | Integration | CRIP | 2024-07-07 | |

## Title

Leetcode Max Streak Integration

## Introduction

This proposal outlines the integration of Leetcode as a data provider for the Catoff-Reclaim integration project. The integration aims to retrieve and process the maximum streak data from Leetcode, allowing users to validate their coding activity on the Catoff platform. This will enable users to use their Leetcode max streak data for various challenges and verifications on Catoff.

## External APIs Needed

- Leetcode API: Leetcode doesn't have a public API for streak data, so the integration will use data extraction methods from the Leetcode app/web.

## Use Cases

1. **User Verification**: Verify the max streak on a user's Leetcode account.
2. **Challenge Participation**: Allow users to participate in challenges that require proof of their max streak on Leetcode.
3. **Coding Activity**: Validate users' coding activity based on their Leetcode max streak.

## Data Provider

- **Name**: Leetcode Max Streak
- **Hash Value**: 0x8bbe041be479e12ef2efee703fced2f4b605c4a6d69e9957d955bebb92ad30ed

## Code Snippet

Below is a code snippet that demonstrates the key parts of the Leetcode integration. The full implementation should follow the service file template.

**`services/LeetcodeMaxStreakService.js`**

```javascript
const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse');

exports.processLeetcodeData = 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 maxStreak = extractedParameters.streak;

console.log("The Maximum Streak on your Leetcode is:", maxStreak);

return new ReclaimServiceResponse(
providerName,
lastUpdateTimeStamp,
'ritikbhatt',
maxStreak,
proof[0]
);
};
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
20 changes: 20 additions & 0 deletions src/services/LeetcodeMaxStreakService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse');

exports.processLeetcodeData = 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 maxStreak = extractedParameters.streak;

console.log("The Maximum Streak on your Leetcode is:", maxStreak);

return new ReclaimServiceResponse(
providerName,
lastUpdateTimeStamp,
'ritikbhatt',
maxStreak,
proof[0]
);
};
16 changes: 11 additions & 5 deletions src/services/reclaimService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { processLeetcodeData } = require('./LeetcodeMaxStreakService')

exports.signWithProviderID = async (userId, providerId) => {
const providerName = RECLAIM_PROVIDER_ID[providerId]
Expand All @@ -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('0x989AB80745743218D03F75C7A4E29F1E8151881a')
await reclaimClient.buildProofRequest('ebc4927b-ebac-4969-99fa-46d2218be85b')
reclaimClient.setSignature(
await reclaimClient.generateSignature(reclaimAppSecret)
await reclaimClient.generateSignature('0x2762a40f292443a5d512613ada961528f2c9a69dc20d146438c0827b66331016')
)
const { requestUrl: signedUrl } =
await reclaimClient.createVerificationRequest()
Expand All @@ -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(
Expand All @@ -49,6 +51,9 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => {
case 'GITHUB_ACCOUNT_VERIFICATION':
processedData = await processGitHubData(proof, providerName)
break
case 'LEETCODE_ACCOUNT_VERIFICATION':
processedData = await processLeetcodeData(proof, providerName);
break
default:
throw new Error(`No handler for provider: ${providerName}`)
}
Expand All @@ -65,4 +70,5 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => {
console.error(`Verification failed for userId: ${userId}`, error)
},
})
}
console.log('Ended session')
}
8 changes: 8 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
exports.RECLAIM_PROVIDER_ID = {
twitter: 'TWITTER_ANALYTICS_VIEWS',
github: 'GITHUB_ACCOUNT_VERIFICATION',
groww: 'LEETCODE_ACCOUNT_VERIFICATION'
}

exports.RECLAIM_APP_ID = {
TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id',
GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id',
GROWW_ACCOUNT_VERIFICATION: 'your-leetcode-app-id'
}

exports.PROVIDER_ID = {
twitter: 'twitter-provider-id',
github: 'github-provider-id',
groww: 'leetcode-provider-id'
}