Inherit your contract from the Sismo Connect Library.
Call the SismoConnect constructor in the constructor of your contract with an appId. Here is a tutorial to get an appId.
contractMyContractisSismoConnect { // inherits from Sismo Connect library// call SismoConnect constructor with your appIdconstructor(bytes16 appId) SismoConnect(buildConfig(appId)) {}}
Verify proofs from your users
You will then need to create some request objects to check that the proofs from your users are valid with respect to these requests.
Finally, use the verify() function to verify the proof stored in sismoConnectResponse with respect to some requests. For example, below we verify that the proof in the sismoConnectResponse is cryptographically valid for a certain ClaimRequest, AuthRequests and SignatureRequest.
functiondoSomethingUsingSismoConnect(bytesmemory sismoConnectResponse) public { SismoConnectVerifiedResult memory result =verify({ responseBytes: sismoConnectResponse,// we want users to prove that they own a Sismo Vault// and that they are members of the group with the id 0x42c768bb8ae79e4c5c05d3b51a4ec74a// we are recreating the auth and claim requests made in the frontend to be sure that // the proofs provided in the response are valid with respect to this auth request auth:buildAuth({authType: AuthType.VAULT}), claim:buildClaim({groupId:0x42c768bb8ae79e4c5c05d3b51a4ec74a},// we also want to check if the signed message provided in the response is the signature of the user's address signature:buildSignature({message: abi.encode(msg.sender)}) });// if the proofs and signed message are valid, we can take the userId from the verified result// in this case the userId is the vaultId (since we used AuthType.VAULT in the auth request) // it is the anonymous identifier of a user's vault for a specific app // --> vaultId = hash(userVaultSecret, appId)uint256 vaultId = SismoConnectHelper.getUserId(result, AuthType.VAULT);// do something with this vaultId for example}
If your proof is valid, the contract will continue its execution, otherwise, it will produce an error.
Documentation
verify()
The verify() function allows you to verify a proof generated by the Sismo Vault app with respect to some requests.
responseBytes(required): The response sent back by the Data Vault. It contains the appId, the namespace, the version and the proofs corresponding to the requests made in the front end.
The function needs to verify that the proof is cryptographically valid but also that it has been well generated from the requests specified in the front end. To do this, we also need to set up the same requests in the contract:
claim: The object that holds all the information needed to request a proof of group membership.
auth: The object that holds all the information needed to request a proof of account ownership.
signature: It contains the message that the user should sign.
namespace: The namespace of the application that the contract uses.
And it returns a SismoConnectVerifiedResult.
responseBytes(required)
The responseBytes is the encoded version of the sismoConnectResponse, the response that the front end receives from the Data Vault app.
Once decoded, here is the type of the SismoConnectResponse:
structSismoConnectResponse {// the app identifier (registered in the Sismo Factory)bytes16 appId;// the app service from which the proof is requested// default: bytes16(keccak256("main"))bytes16 namespace;// the version of the Data Vault app// default: "sismo-connect-v2"bytes32 version;// A message provided by the user and signed with the vault.bytes signedMessage;// the array of Sismo Connect proofs generated// only one proof is generated for now) SismoConnectProof[] proofs;}
proofs[] : The array that contains all the sismoConnectProofs the front end provides to the contract.
A sismoConnectProof contains several objects:
claim : The data requested to generate a group membership proof for a specific value.
structClaim { ClaimType claimType; // default: GTE// the group identifier used to check// if the user is eligible in order to generate the zero-knowledge proof.bytes16 groupId;// the timestamp of the group snapshot for which the user had to be eligible to// in order to generate the zero-knowledge proof.bytes16 groupTimestamp;// Make the value the user wants to use to prove membership selectable// e.g. value is 1, the user has a value of 3, he can choose to prove the value 2bool isSelectableByUser;// A group is a mapping of account and value pairs.// Limit eligibility to users in the group with a specified value.uint256 value;bytes extraData;}enumClaimType { GTE, GT, EQ, LT, LTE}
auth : The data requested to generate a proof of account ownership
structAuth { AuthType authType; // default: VAULT// (soon™) Does not reveal the userId with which the user performs the authbool isAnon; // false// Make the account whose ownership the user wants to prove selectablebool isSelectableByUser;// The id of the account// e.g. if the authType is TWITTER, the userId will be your twitterId.uint256 userId;bytes extraData;}enumAuthType { VAULT, GITHUB, TWITTER, EVM_ACCOUNT}
provingScheme : The proving scheme that the Data Vault app uses to generate and verify the proof.
proofData : The proof's content.
extraData : other data that can be used in the future by other proving schemes. Currently not used in the current proving scheme use: the Hydra-S2.
The next objects are the references that allow the verify() function to ensure that the proof sent by the user matches the proof expected by the contract:
claimRequest(optional)
The data requested to generate a group membership proof for a specific value.
A message provided by the user and signed with the Vault.
// Example of a signedMessagestructSignatureRequest {bytes message; // default: "MESSAGE_SELECTED_BY_USER"bool isSelectableByUser; // default: falsebytes extraData; // default: ""}// Example: Build your signed messagesignature:buildSignature({message: message})
namespace(optional)
By default set to “main”. You can optionally define a namespace on top of the appId to use the sismoConnect flow in different parts of your application. You can see an example of two different namespaces used at the end of the sismoConnect server documentation.
SismoConnectVerifiedResult
The SismoConnectVerifiedResult is the object returned by the verify() function if the proofs are valid. It contains all the verifications processed, that is:
The claim: verifiedClaims
The auth: verifiedAuths
The signed message signedMessages
structSismoConnectVerifiedResult {bytes16 appId;bytes16 namespace;bytes32 version; VerifiedAuth[] auths; VerifiedClaim[] claims;bytes signedMessage; }structVerifiedAuth { AuthType authType;bool isAnon; // false// Contains an id regarding the requested auth // that can be used to identify the user// It may be a vaultId, a githubId or a twitterIduint256 userId;bytes extraData;bytes proofData;}structVerifiedClaim { ClaimType claimType;bytes16 groupId;bytes16 groupTimestamp;uint256 value;bytes extraData;// the identifier of the proof, unique for each different namespaceuint256 proofId;bytes proofData;}