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

Feat : Add sismo in TurboEth #174

Open
wants to merge 12 commits into
base: integrations
Choose a base branch
from
7 changes: 7 additions & 0 deletions app/(general)/integration/sismo/auth/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client"

import Auth from "@/integrations/sismo/components/Auth"

export default function AuthPage() {
return <Auth />
}
7 changes: 7 additions & 0 deletions app/(general)/integration/sismo/claim/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client"

import Claim from "@/integrations/sismo/components/Claim"

export default function ClaimPage() {
return <Claim />
}
64 changes: 64 additions & 0 deletions app/(general)/integration/sismo/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use client"

import React from "react"
import Link from "next/link"
import { turboIntegrations } from "@/data/turbo-integrations"
import { LuBook } from "react-icons/lu"

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
import {
PageHeader,
PageHeaderCTA,
PageHeaderDescription,
PageHeaderHeading,
} from "@/components/layout/page-header"
import { PageSection } from "@/components/layout/page-section"
import { LightDarkImage } from "@/components/shared/light-dark-image"

import { SideBar } from "./sidebar"

interface SismoLayoutProps {
children?: React.ReactNode
}

export default function SismoLayout({ children }: SismoLayoutProps) {
return (
<div className="container relative mt-20">
<PageHeader className="pb-8">
<LightDarkImage
LightImage={turboIntegrations.sismo.imgLight}
DarkImage={turboIntegrations.sismo.imgDark}
alt="Sismo Logo"
width={100}
height={100}
/>
<PageHeaderHeading>Sismo</PageHeaderHeading>
<PageHeaderDescription>
Sismo ETH is a decentralized identity aggregator and crypto-native SSO
that uses zero-knowledge proofs (ZKPs) to enable users to aggregate
and selectively disclose personal data to applications.
</PageHeaderDescription>
<PageHeaderCTA>
<Link
href={turboIntegrations.sismo.url}
target="_blank"
rel="noreferrer noopener"
className={cn(buttonVariants({ variant: "outline" }))}
>
<LuBook className="mr-2 h-4 w-4" />
Documentation
</Link>
</PageHeaderCTA>
</PageHeader>
<PageSection className="w-full">
<section className="flex w-full flex-col overflow-hidden rounded-xl bg-muted sm:flex-row">
<SideBar />
<div className="min-h-[600px] flex-1 flex-col items-center justify-center p-10 text-center">
{children}
</div>
</section>
</PageSection>
</div>
)
}
5 changes: 5 additions & 0 deletions app/(general)/integration/sismo/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Sismo from "@/integrations/sismo"

export default function SismoPage() {
return <Sismo />
}
67 changes: 67 additions & 0 deletions app/(general)/integration/sismo/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"use client"

import Link from "next/link"
import { usePathname } from "next/navigation"
import { turboIntegrations } from "@/data/turbo-integrations"

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/components/ui/button"
import { LinkComponent } from "@/components/shared/link-component"
import { ArweaveAccountPreview } from "@/integrations/arweave/components/arweave-account/sidebar-preview"

export const SideBar = () => {
const pathname = usePathname()

const sismoBaseUrl = turboIntegrations.sismo.href
return (
<aside aria-label="Sidebar" className="w-full sm:w-64">
<div className="overflow-y-auto bg-background px-3 py-4 text-left sm:h-full">
<ArweaveAccountPreview />
<ul className="space-y-2 font-medium">
<li>
<Link href={`${sismoBaseUrl}/auth`}>
<span
className={cn(
"group flex w-full items-center rounded-md border border-transparent px-2 py-1 hover:bg-muted hover:text-foreground",
pathname === `${sismoBaseUrl}/auth`
? "bg-muted font-medium text-foreground"
: "text-muted-foreground"
)}
>
<span>Auth</span>
</span>
</Link>
</li>
<li>
<Link href={`${sismoBaseUrl}/claim`}>
<span
className={cn(
"group flex w-full items-center rounded-md border border-transparent px-2 py-1 hover:bg-muted hover:text-foreground",
pathname === `${sismoBaseUrl}/claim`
? "bg-muted font-medium text-foreground"
: "text-muted-foreground"
)}
>
<span>Claim</span>
</span>
</Link>
</li>
<li>
<Link href={`${sismoBaseUrl}/signature`}>
<span
className={cn(
"group flex w-full items-center rounded-md border border-transparent px-2 py-1 hover:bg-muted hover:text-foreground",
pathname === `${sismoBaseUrl}/signature`
? "bg-muted font-medium text-foreground"
: "text-muted-foreground"
)}
>
<span>Signature</span>
</span>
</Link>
</li>
</ul>
</div>
</aside>
)
}
7 changes: 7 additions & 0 deletions app/(general)/integration/sismo/signature/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use client"

import Signature from "@/integrations/sismo/components/Signature"

export default function SignaturePage() {
return <Signature />
}
1 change: 1 addition & 0 deletions app/api/sismo/auth/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { POST } from "@/integrations/sismo/api/auth"
1 change: 1 addition & 0 deletions app/api/sismo/claim/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { POST } from "@/integrations/sismo/api/claim"
1 change: 1 addition & 0 deletions app/api/sismo/signature/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { POST } from "@/integrations/sismo/api/signature"
10 changes: 10 additions & 0 deletions data/turbo-integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export const turboIntegrations: Record<string, TurboIntegration> = {
imgDark: "/integrations/gitcoin-passport.svg",
category: "services",
},
sismo: {
name: "Sismo ETH",
href: "/integration/sismo",
url: "https://www.sismo.io/",
description:
"Sismo ETH is a decentralized identity aggregator and crypto-native SSO that uses zero-knowledge proofs (ZKPs) to enable users to aggregate and selectively disclose personal data to applications.",
imgLight: "/integrations/sismo-protocol-light.png",
imgDark: "/integrations/sismo-protocol-dark.png",
category: "services",
},
starter: {
name: "Starter Template",
href: "/integration/starter",
Expand Down
1 change: 1 addition & 0 deletions integrations/sismo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Sismo
46 changes: 46 additions & 0 deletions integrations/sismo/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
AuthType,
SismoConnect,
SismoConnectVerifiedResult,
} from "@sismo-core/sismo-connect-server"

import { getConfig } from "../utils/getConfig"

export async function POST(req: Request) {
try {
const config = getConfig("auth")
const sismoConnect = SismoConnect({ config })

const sismoConnectResponse = await req.json().catch((error) => {
console.error("Error parsing request body as JSON:", error)
return null
})

if (sismoConnectResponse === null) {
return new Response("Invalid JSON in request body", { status: 400 })
}

console.log("authApi")
const result: SismoConnectVerifiedResult = await sismoConnect.verify(
sismoConnectResponse,
{
auths: [
{ authType: AuthType.GITHUB, isOptional: true },
{ authType: AuthType.TWITTER },
{ authType: AuthType.VAULT },
{ authType: AuthType.EVM_ACCOUNT },
],
}
)

if (result) {
return new Response(JSON.stringify(result), {
status: 200,
headers: { "Content-Type": "application/json" },
})
}
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e)
return new Response(errorMessage, { status: 501 })
}
}
52 changes: 52 additions & 0 deletions integrations/sismo/api/claim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
AuthType,
ClaimType,
SismoConnect,
SismoConnectVerifiedResult,
} from "@sismo-core/sismo-connect-server"

import { getConfig } from "../utils/getConfig"

export async function POST(req: Request) {
try {
const config = getConfig("claims")
const sismoConnect = SismoConnect({ config })

const sismoConnectResponse = await req.json().catch((error) => {
console.error("Error parsing request body as JSON:", error)
return null
})

if (sismoConnectResponse === null) {
return new Response("Invalid JSON in request body", { status: 400 })
}

const result: SismoConnectVerifiedResult = await sismoConnect.verify(
sismoConnectResponse,
{
auths: [{ authType: AuthType.GITHUB, isOptional: true }],
claims: [
{
groupId: "0xda1c3726426d5639f4c6352c2c976b87",
},
{
groupId: "0x1cde61966decb8600dfd0749bd371f12",
claimType: ClaimType.GTE,
value: 15, // dhadrien.sismo.eth has a score of 46, eligible. Can reveal more.
isSelectableByUser: true, // can reveal more than 15 if they want
},
],
}
)

if (result) {
return new Response(JSON.stringify(result), {
status: 200,
headers: { "Content-Type": "application/json" },
})
}
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e)
return new Response(errorMessage, { status: 500 })
}
}
44 changes: 44 additions & 0 deletions integrations/sismo/api/signature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
AuthType,
SismoConnect,
SismoConnectVerifiedResult,
} from "@sismo-core/sismo-connect-server"

import { getConfig } from "../utils/getConfig"

export async function POST(req: Request) {
try {
const config = getConfig("signature")
const sismoConnect = SismoConnect({ config })

const sismoConnectResponse = await req.json().catch((error) => {
console.error("Error parsing request body as JSON:", error)
return null
})

if (sismoConnectResponse === null) {
return new Response("Invalid JSON in request body", { status: 400 })
}

const result: SismoConnectVerifiedResult = await sismoConnect.verify(
sismoConnectResponse,
{
auths: [{ authType: AuthType.GITHUB, isOptional: true }],
signature: {
message: "I want TurboEth with Sismo",
isSelectableByUser: true,
},
}
)

if (result) {
return new Response(JSON.stringify(result), {
status: 200,
headers: { "Content-Type": "application/json" },
})
}
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e)
return new Response(errorMessage, { status: 500 })
}
}
Loading