Querying Attestations

So now, how can you verify if Alice attested to Bob's signature? We will be using Sign Protocol's Indexing Service to do exactly that!

First, we will create a helper function that we can reuse for making requests to the Sign Protocol Indexing Service.

import axios from "axios";

// Generate a function for making requests to the Sign Protocol Indexing Service
async function makeAttestationRequest(endpoint: string, options: any) {
    const url = `https://testnet-rpc.sign.global/api/${endpoint}`;
    const res = await axios.request({
      url,
      headers: {
        "Content-Type": "application/json; charset=UTF-8"
      },
      ...options
    });
    // throw API errors
    if (res.status !== 200) {
      throw new Error(JSON.stringify(res));
    }
    // return original response
    return res.data;
}

Next, we will use this function to query for Alice's attestation of Bob's signature.

async function queryAttestations() {
    const response = await makeAttestationRequest(
        "index/attestations",
        {
            method: "GET",
            params: {
                mode: "onchain", // Data storage location
                schemaId: "onchain_evm_84532_0x34", // Your full schema's ID
                attester: "0x...", // Alice's address
                indexingValue: "0x...".toLowerCase(), // Bob's address
            }
        }
    );
    
    // Make sure the request was successfully processed.
    if (!response.success) {
      return { success: false, message: response?.message ?? "Attestation query failed." };
    }
    
    // Return a message if no attestations are found.
    if (response.data?.total === 0) {
      return { success: false, message: "No attestation for this address found." };
    }
    
    // Return all attestations that match our query.
    return {
      success: true,
      attestations: response.data.rows
    };
}

Great! So now, we have a list of available attestations that Alice has made, of Bob's signature. If we only need to check for the existence of at least one attestation that matches our criteria, we could stop here. But what if we wanted to validate the message that Alice was attesting? Perhaps there are several different contracts that Alice has notarized for Bob and we are looking for a specific one. When you are ready, move on to the next page where we will parse the attestation data.

Last updated