Signature
A Signature
is a specific message embedded in a generated proof that will be checked when verifying the proof. It can be requested from the Data Vault via a SignatureRequest.
Type definitions
The SignatureRequest
is an object with the following properties:
message
(required): the message that the user is going to sign.isSelectableByUser
(optional): by default set tofalse
. Allows the user to edit the message in the Sismo Data Vault app.
// Types (typescript version)
type SignatureRequest = {
message: string;
isSelectableByUser?: boolean;
};
Integrations
SignatureRequest
is made in the front end using either the sismo-connect-react
package or the sismo-connect-client
package.
The proof with the requested signature is then verified either in a backend using the sismo-connect-server
package or in a smart contract using the sismo-connect-solidity
package.
Making a SignatureRequest - Front-end integration
The SismoConnectButton
React component is available from the sismo-connect-react package. It is a wrapper of the sismo-connect-client package.
SignatureRequest is passed to the
SismoConnectButton
through thesignature
propsResponses are received through either:
the
onResponse: (response: SismoConnectResponse) => void
callback for offchain verification or,the
onResponseBytes (response: string) => void
callback for onchain verification.
SignatureRequest - code example
import { SismoConnectButton, SismoConnectClientConfig, SismoConnectResponse, AuthType } from "@sismo-core/sismo-connect-react";
<SismoConnectButton
// the client config created
config={config}
// signature request must be made with at least an auth or one claim
auth={{authType: AuthType.VAULT}}
// your signature request
// that needs to be encoded if you verify proofs in smart contracts
signature={{message: "0x00"}}
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
}}
/>
Verifying a SignatureRequest
A signature request 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.
SignatureRequest - code example
import { SismoConnect, SismoConnectVerifiedResult, AuthType } from "@sismo-core/sismo-connect-server";
const sismoConnect = SismoConnect({config});
async function verifyResponse(sismoConnectResponse: SismoConnectResponse) {
// verifies the proofs contained in the sismoConnectResponse
const result: SismoConnectVerifiedResult = await sismoConnect.verify(
sismoConnectResponse,
{
// signature request must be made with at least an auth or one claim
auth: { authType: AuthType.VAULT },
// your signature request
signature: {message: "0x00"}
}
)
}
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.
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ["@sismo-core/sismo-connect-server"],
},
}
module.exports = nextConfig
Last updated