Getting started

  1. npm i proofable. We recommend the Node LTS versions: v12.16.3+

  2. create an authentication token using: ./proofable-cli auth. You can find details from here

  3. import Proofable package

    import { newAPIClient, Anchor, Key /* and more */ } from "proofable";
    
  4. create a Proofable API client

    const client = newAPIClient("api.proofable.io:443");
    
  5. create a trie from data

    const trie = await client.createTrieFromKeyValues(
      dataToKeyValues({
        "balcony/wind/speed": "11km/h",
        "balcony/wind/direction": "N",
        "living_room/temp": "24.8℃",
        "living_room/Co2": "564ppm",
      })
    );
    
  6. anchor the trie to a blockchain that is supported by Proofable. Here we use Hedera testnet, as it is cool and fast

    const trieProof = await client.anchorTrie(trie, Anchor.Type.HEDERA);
    
    console.dir(trieProof.toObject());
    

    Anchor Trie Example

  7. export the trie for later use. This trie file is a self-contained certificate that can be used later on to do all sorts of manipulations, including verifiying the data

    await client.exportTrie(trieId, "./example.proofable");
    
  8. import and verify the trie we just exported. Note that in order to use this convenient and efficient verification API, we have to ensure the original key-values are sorted. This sorting can be done efficiently in real world case, e.g. when querying a database

    const result = await client.importAndVerifyTrieWithSortedKeyValues(
      "./example.proofable",
      sortKeyValues(
        dataToKeyValues({
          "balcony/wind/speed": "11km/h",
          "balcony/wind/direction": "N",
          "living_room/temp": "24.8℃",
          "living_room/Co2": "564ppm",
        })
      ),
      undefined,
      "./example.proofable.dot"
    );
    
    console.dir(result);
    

    Import and Verify Trie Example

    Proof Dot Graph Example

  9. create a key-values proof for the data subset directly from the already proved trie. This proof file is a self-contained certificate that proves the data subset

    await client.createKeyValuesProof(
      result.trie!.id,
      result.proof.id!,
      KeyValuesFilter.from([
        Key.from("balcony/wind/speed"),
        Key.from("living_room/Co2"),
      ]),
      /*
      or you can directly use `KeyValue`s:
      KeyValuesFilter.from(
        dataToKeyValues({
          "balcony/wind/speed": "11km/h",
          "living_room/Co2": "564ppm",
        })
      )
      */
      "./example.subproofable"
    );
    
  10. verify the key-values proof we just created. Again, we need to sort the original data subset

    const result = await client.verifyKeyValuesProofWithSortedKeyValues(
      "./example.subproofable",
      sortKeyValues(
        dataToKeyValues({
          "balcony/wind/speed": "11km/h",
          "living_room/Co2": "564ppm",
        })
      ),
      "./example.subproofable.dot"
    );
    
    console.dir(result);
    

    As you can see, the trie and proof.id are undefined comparing to previous output, which indicates that the key-values proof is independent of any tries

    Verify Key-values Proof Example

    Subproof Dot Graph Example

You can find the complete source code of this guide from here, which can be run as:

npm run example-basic