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

Add reclaim uber stamp #2729

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion app/components/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const PLATFORM_CATEGORIES: PLATFORM_CATEGORY[] = [
{
name: "Social & Professional Platforms",
description: "Link your profiles from established social media and professional networking sites for verification.",
platforms: ["Github", "Linkedin", "Google", "Discord"],
platforms: ["Github", "Linkedin", "Google", "Discord", "Uber"],
},
{
name: "Biometric Verification",
Expand Down
8 changes: 8 additions & 0 deletions app/context/ceramicContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const {
Outdid,
AllowList,
Binance,
Uber,
} = stampPlatforms;
import { PlatformProps } from "../components/GenericPlatform";

Expand Down Expand Up @@ -228,6 +229,13 @@ if (process.env.NEXT_PUBLIC_FF_BINANCE_STAMPS === "on") {
});
}

if (process.env.NEXT_PUBLIC_FF_UBER_STAMPS === "on") {
platforms.set("Uber", {
platform: new Uber.UberPlatform(),
platFormGroupSpec: Uber.ProviderConfig,
});
}

export enum IsLoadingPassportState {
Idle,
Loading,
Expand Down
1 change: 1 addition & 0 deletions app/public/assets/uber-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions platforms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@ethersproject/providers": "^5.6.2",
"@gitcoin/passport-types": "^1.0.0",
"@guildxyz/sdk": "^2.5.0",
"@reclaimprotocol/js-sdk": "^1.3.10",
"@spruceid/didkit-wasm": "^0.3.0-alpha0",
"axios": "^0.26.1",
"bignumber.js": "4.0.4",
Expand Down
34 changes: 34 additions & 0 deletions platforms/src/Uber/App-Bindings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Platform } from "../utils/platform";
import { AppContext, ProviderPayload } from "../types";

export class UberPlatform extends Platform {
platformId = "Uber";
path = "uber";

getRequestUrl(state: string, callbackUrl?: string): string {
return `https://publish-credentials.reclaimprotocol.org/integration?state=${state}&redirect_uri=${callbackUrl}`;
}

async getProviderPayload(appContext: AppContext): Promise<ProviderPayload> {
const reqUrl: string = this.getRequestUrl(appContext.state, appContext.callbackUrl);
const width = 600;
const height = 800;
const left = appContext.screen.width / 2 - width / 2;
const top = appContext.screen.height / 2 - height / 2;

// Pass data to the page via props
appContext.window.open(
reqUrl,
"_blank",
`toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=no, copyhistory=no, width=${width}, height=${height}, top=${top}, left=${left}`
);

return appContext.waitForRedirect(this).then((data) => {
return {
code: data.code,
sessionKey: data.state,
signature: data.signature,
};
});
}
}
28 changes: 28 additions & 0 deletions platforms/src/Uber/Providers-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PlatformSpec, PlatformGroupSpec, Provider } from "../types";
import { UberRidesProvider } from "./Providers/uberRides";

export const PlatformDetails: PlatformSpec = {
icon: "./assets/uber-icon.svg",
platform: "Uber",
name: "Uber",
description:
"Using Reclaim's zk technology, you can connect your Uber account without sharing any of the account information with Reclaim or Passport",
connectMessage: "Connect Account",
website: "https://uber.com/",
};

export const ProviderConfig: PlatformGroupSpec[] = [
{
platformGroup: "Account has one ride",
providers: [
{
title: "at least 1 ride",
name: "UberRides",
}
],
},
];

export const providers: Provider[] = [
new UberRidesProvider(),
];
61 changes: 61 additions & 0 deletions platforms/src/Uber/Providers/uberRides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import axios from "axios";
import { ProviderContext, RequestPayload, VerifiedPayload } from "@gitcoin/passport-types";
import { Proof, Reclaim } from "@reclaimprotocol/js-sdk";
import { ProviderExternalVerificationError, type Provider } from "../../types";

type StatusResponse = {
session: {
proofs: Proof[];
};
};
async function verifyUberRides(code: string): Promise<{ hasRide: boolean }> {
const reclaimClient = new Reclaim.ProofRequest(process.env.NEXT_PUBLIC_RECLAIM_APP_ID, { sessionId: code });
const res = await axios.get(reclaimClient.getStatusUrl());
const data = res.data as StatusResponse;
if (data.session) {
const proof = data.session.proofs[0];
if (!Reclaim.verifySignedProof(proof)) {
throw new Error("Proof signature invalid");
}

return {
hasRide: true,
};
} else {
throw new Error("No session in response");
}
}

const checkUberRides = (hasRide: boolean): { valid: boolean; errors: string[] } => {
if (hasRide) {
return {
valid: true,
errors: undefined,
};
} else {
return {
valid: false,
errors: [`Uber account doesn't have any rides.`],
};
}
};

export class UberRidesProvider implements Provider {
type = "uberRides";

async verify(payload: RequestPayload, context: ProviderContext): Promise<VerifiedPayload> {
try {
const { hasRide } = await verifyUberRides(payload.proofs.code);

const { valid, errors } = checkUberRides(hasRide);

return {
valid,
errors,
record: { address: payload.address },
};
} catch (e: unknown) {
throw new ProviderExternalVerificationError(`Error verifying Reclaim Proof: ${String(e)}`);
}
}
}
4 changes: 4 additions & 0 deletions platforms/src/Uber/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Uber Platform
export { UberPlatform } from "./App-Bindings";
export { PlatformDetails, ProviderConfig, providers } from "./Providers-config";
export { UberRidesProvider } from "./Providers/uberRides";
2 changes: 2 additions & 0 deletions platforms/src/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as TrustaLabs from "./TrustaLabs";
import * as Outdid from "./Outdid";
import * as AllowList from "./AllowList";
import * as Binance from "./Binance";
import * as Uber from "./Uber";
import { PlatformSpec, PlatformGroupSpec, Provider } from "./types";

type PlatformConfig = {
Expand Down Expand Up @@ -56,6 +57,7 @@ const platforms: Record<string, PlatformConfig> = {
Outdid,
AllowList,
Binance,
Uber,
};

if (process.env.NEXT_PUBLIC_FF_NEW_POAP_STAMPS === "on") {
Expand Down
6 changes: 4 additions & 2 deletions types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ export type PLATFORM_ID =
| "TrustaLabs"
| "Outdid"
| "AllowList"
| "Binance";
| "Binance"
| "Uber";

export type PLATFORM_CATEGORY = {
name: string;
Expand Down Expand Up @@ -443,7 +444,8 @@ export type PROVIDER_ID =
| "Outdid"
| "AllowList"
| `AllowList#${string}`
| "BinanceBABT";
| "BinanceBABT"
| "UberRides";

export type StampBit = {
bit: number;
Expand Down
Loading