Skip to content

Querying Attestations

To verify that Alice attested to Bob's signature, use Sign Protocol's Indexing Service.

Querying for an attestation

You can query for an attestation with the NPM SDK or the REST API.

NPM SDK

The NPM SDK includes an IndexService for querying schemas and attestations.

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

async function queryAttestations() {
  const indexService = new IndexService("testnet");

  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: res.rows,
  };
}

REST API

To use the REST API instead, create a reusable helper function for 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;
}

Then use it 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,
  };
}

You now have a list of Alice's attestations of Bob's signature. If you only need to check that at least one matching attestation exists, you can stop here. To validate the message Alice attested to (for example, if Alice notarized several contracts for Bob and you need a specific one), parse the attestation data as shown on the next page.