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!

Querying for an Attestation

You can query for an attestation using our NPM SDK or by making requests to our REST API.

NPM SDK

Our NPM SDK includes an IndexService that you can use to query schemas and attestations.

import { IndexService } from "@ethsign/sp-sdk";

async function queryAttestations() {
  const indexService = new IndexService("testnet");
    
  const attId = `onchain_evm_${chainId}_${attestationId}`;
  const res = await indexService.queryAttestationList({
    schemaId: "onchain_evm_84532_0x34", // Your full schema's ID
    attester: "0x...", // Alice's address
    page: 1,
    mode: "onchain", // Data storage location
    indexingValue: "0x...".toLowerCase(), // Bob's address
  });
  
  return {
    success: true,
    attestations: response.rows,
  };
}

REST API

Alternatively, we will create a helper function that we can reuse to make 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

Logo

Copyright Sign 2021-2024