Sismo Connect can be used to request zero-knowledge proofs (ZKPs) that attest group membership from users.
Type definitions
The ClaimRequest holds all the information needed to generate such a proof. It has the following properties:
groupId (required): the group identifier that the user must prove membership of in order to generate the proof. The groupId can be found in the Sismo Factory.
value (optional): by default set to “1”. Querying a specific value restricts eligibility to users belonging to the group with the minimum specified value or matching the exact value.
claimType (optional): by default ClaimType.GTE. Defines the type of group membership required. The following claim types are currently supported:
ClaimType.GTE: the user must prove that they own an account with at least the requested value.
ClaimType.EQ: the user must prove that he owns an account with the exact requested value.
groupTimestamp (optional): set to “latest” by default. Groups are composed of snapshots generated either once, daily, or weekly. Each Group Snapshot generated has a timestamp associated with them. By default, the selected group is the latest Group Snapshot generated. But you are free to select a Group Snapshot with a different timestamp than the latest generated one.
isOptional(optional): by default set to false. If set to true the user can optionally prove their group membership.
isSelectableByUser(optional): by default set to false and only available for ClaimType.GTE. This allows users to selectively choose the value used to generate the proof.
// Types (typescript version)enumClaimType { GTE =0, GT =1,// not supported EQ =2, LT =3,// not supported LTE =4// not supported}typeClaimRequest= { groupId:string; claimType?:ClaimType; groupTimestamp?:number|"latest"; value?:number; isOptional?:boolean; isSelectableByUser?:boolean;};
Making an ClaimRequest is only possible in the front end as the request redirects users to the Sismo Vault app, where users can generate a zero-knowledge proof.
ClaimRequests are passed as props to the SismoConnectButton either through:
the claim props for one claim request: ClaimRequest or,
the claims props for several claim requests: ClaimRequest[]
Responses are received through either:
the onResponse: (response: SismoConnectResponse) => void callback for offchain verification or,
the onResponseBytes (response: string) => void callback for onchain verification.
One ClaimRequest - code example
app.tsx
import { SismoConnectButton, SismoConnectClientConfig, SismoConnectResponse } from"@sismo-core/sismo-connect-react";<SismoConnectButton// the client config createdconfig={config}// request a proof of group membership // (here the group with id 0x42c768bb8ae79e4c5c05d3b51a4ec74a)claim={{groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}}onResponse={async (response:SismoConnectResponse) => {//Send the response to your server to verify it//thanks to the @sismo-core/sismo-connect-server package }}onResponseBytes={async (bytes:string) => {//Send the response to your contract to verify it//thanks to the @sismo-core/sismo-connect-solidity package }}/>
Multiple AuthRequests - code example
app.tsx
// You can also create several auth requests // in the same buttonimport { SismoConnectButton, SismoConnectClientConfig, SismoConnectResponse } from"@sismo-core/sismo-connect-react";<SismoConnectButtonconfig={config}// request multiple proofs of group membership // (here the groups with id 0x42c768bb8ae79e4c5c05d3b51a4ec74a and 0x8b64c959a715c6b10aa8372100071ca7)claims={[ {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}, {groupId:"0x8b64c959a715c6b10aa8372100071ca7"}, ]}onResponse={async (response:SismoConnectResponse) => {//Send the response to your server to verify it//thanks to the @sismo-core/sismo-connect-server package }}onResponseBytes={async (bytes:string) => {//Send the response to your contract to verify it//thanks to the @sismo-core/sismo-connect-solidity package }}/>
One or multiple claim requests can be made using the sismoConnect.request() method available on the sismoConnect variable.
Responses could be received through either:
the sismoConnect.getResponse() method for offchain verification or,
the sismoConnect.getResponseBytes() method for onchain verification.
One ClaimRequest - code example
App.tsx
import { useSismoConnect, SismoConnectResponse } from"@sismo-core/sismo-connect-react";const { sismoConnect } =useSismoConnect({ config });// request a proof of group membership // (here the group with id 0x42c768bb8ae79e4c5c05d3b51a4ec74a)functiononClick(){sismoConnect.request({ claim: {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"} });}// Proofs are available in two differents types depending on usage (offchain or onchaon verification)constresponse:SismoConnectResponse|null=sismoConnect.getResponse();constresponseBytes:string|null=sismoConnect.getResponseBytes();if(response || responseBytes) {// Send response to the backend to verify it or,// Send responseBytes to smart contract to verify it. }
Multiple ClaimRequests - code example
App.tsx
import { useSismoConnect, SismoConnectResponse } from"@sismo-core/sismo-connect-react";const { sismoConnect } =useSismoConnect({ config });// request multiple proofs of group membership // (here the groups with id 0x42c768bb8ae79e4c5c05d3b51a4ec74a and 0x8b64c959a715c6b10aa8372100071ca7)functiononClick(){sismoConnect.request({ claims: [ {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}, {groupId:"0x8b64c959a715c6b10aa8372100071ca7"}, ] });}// Proofs are available in two differents types depending on usage (offchain or onchaon verification)constresponse:SismoConnectResponse|null=sismoConnect.getResponse();constresponseBytes:string|null=sismoConnect.getResponseBytes();if(response || responseBytes) {// Send response to the backend to verify it or,// Send responseBytes to smart contract to verify it. }
One or multiple ClaimRequests can be made using the sismoConnect.request() method available on a SismoConnect instance.
Responses could be received through either:
the sismoConnect.getResponse() method for offchain verification or,
the sismoConnect.getResponseBytes() method for onchain verification.
One ClaimRequest - code example
app.ts
import { SismoConnect, SismoConnectResponse } from"@sismo-core/sismo-connect-client";constsismoConnect=SismoConnect({config});// request a proof of group membership // (here the group with id 0x42c768bb8ae79e4c5c05d3b51a4ec74a)functiononClick(){sismoConnect.request({ claim: {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"} });}// Receive the proofs in two different formatsconstresponse:SismoConnectResponse|null=sismoConnect.getResponse();constresponseBytes:string|null=sismoConnect.getResponseBytes();if(response || responseBytes) {// Send response to the backend to verify it or,// Send responseBytes to smart contract to verify it. }
Multiple ClaimRequests - code example
app.ts
import { SismoConnect, SismoConnectResponse } from"@sismo-core/sismo-connect-client";constsismoConnect=SismoConnect({config});// request multiple proofs of group membership // (here the groups with id 0x42c768bb8ae79e4c5c05d3b51a4ec74a and 0x8b64c959a715c6b10aa8372100071ca7)functiononClick(){sismoConnect.request({ claims: [ {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}, {groupId:"0x8b64c959a715c6b10aa8372100071ca7"}, ] });}// Receive the proofs in two different formatsconstresponse:SismoConnectResponse|null=sismoConnect.getResponse();constresponseBytes:string|null=sismoConnect.getResponseBytes();if(response || responseBytes) {// Send response to the backend to verify it or,// Send responseBytes to smart contract to verify it. }
Verifying a ClaimRequest
Once a user has generated the proof on the Data Vault app, your application must verify it. This can be made either offchain in your backend or onchain in your smart contract. The sismo-connect-server package exposes a SismoConnect variable.
One or multiple claim requests can be verified offchain on a backend server using the sismoConnect.verify() method available on a SismoConnect instance.
If the proof is valid sismoConnect.verify() returns a result of type SismoConnectVerifiedResult else it will throw an error.
One ClaimRequest - code example
import { SismoConnect, SismoConnectVerifiedResult } from"@sismo-core/sismo-connect-server";constsismoConnect=SismoConnect({config});asyncfunctionverifyResponse(sismoConnectResponse:SismoConnectResponse) {// verifies the proofs contained in the sismoConnectResponse// with respect to the different claimsconstresult:SismoConnectVerifiedResult=awaitsismoConnect.verify( sismoConnectResponse, {// proofs in the sismoConnectResponse should be valid// with respect to a group membership claim: {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"} } )}
If you are using Nextjs, you will need to add this config in the next.config.js file to be able to verify the proof. You can find more information here.
import { SismoConnect, SismoConnectVerifiedResult } from"@sismo-core/sismo-connect-server";constsismoConnect=SismoConnect({config});asyncfunctionverifyResponse(sismoConnectResponse:SismoConnectResponse) {// verifies the proofs contained in the sismoConnectResponse// with respect to the different claimsconstresult:SismoConnectVerifiedResult=awaitsismoConnect.verify( sismoConnectResponse, {// proofs in the sismoConnectResponse should be valid// with respect to the groups memberships claims: [ {groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}, {groupId:"0x8b64c959a715c6b10aa8372100071ca7"}, ] } )}
The sismo-connect-solidity package exposes a Sismo Connect Library, which can be inherited by your contract either using Foundry or Hardhat.
The Sismo Connect Library exposes:
a verify() function, which allows you to verify a proof generated by the Sismo Vault app with respect to some requests directly in your contract. The verify() function takes an object containing:
a responseBytes send from the front end,
an claim or claims corresponding to the claim request made in the front end.
a buildClaim() helper to recreate the ClaimRequest made in the front end
One ClaimRequest - code example
contractMyContractisSismoConnect { // inherits from Sismo Connect library// call SismoConnect constructor with your appIdconstructor(bytes16 appId) SismoConnect(buildConfig(appId)) {}functiondoSomethingUsingSismoConnect(bytesmemory sismoConnectResponse) public { SismoConnectVerifiedResult memory result =verify({ responseBytes: sismoConnectResponse, claim:buildClaim({groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}), });// do something once verified }}
Multiple ClaimRequests - code example
contractMyContractisSismoConnect { // inherits from Sismo Connect library// call SismoConnect constructor with your appIdconstructor(bytes16 appId) SismoConnect(buildConfig(appId)) {}functiondoSomethingUsingSismoConnect(bytesmemory sismoConnectResponse) public { ClaimRequest[] memory claims =new ClaimRequest[](2); claims[0] =buildClaim({groupId:"0x42c768bb8ae79e4c5c05d3b51a4ec74a"}) claims[1] =buildClaim({groupId:"0x8b64c959a715c6b10aa8372100071ca7"}) SismoConnectVerifiedResult memory result =verify({ responseBytes: sismoConnectResponse, claims: claims, });// do something once verified }}