SouthbankSoftware/proofable

How to prove a directory or an image file using node SDK

perdona opened this issue · 9 comments

I'm trying to use the node SDK to prove a directory or an image file, but I can't seem to find any example of how to achieve this.

Hi @perdona, I just created an example (in TypeScript) for you to use Proofable to prove a directory (src/examples). If you clone this repo and run:

cd node_sdk
npm i
npm run example-fs

You should be able to see the following result:
Screen Shot 2020-11-13 at 5 37 35 pm

After you run the above commands, there will also be a Graphviz Dot Graph (mydir.proofable.dot) of your proof generated in your current working directory. You can use a viewer such as this to view it:

Screen Shot 2020-11-13 at 5 47 06 pm

@guiguan Thanks a lot for the rapid response! Will test this asap and post feedback here!
Thanks again!

Works perfectly, guys! Thanks a lot!

Guys, I'm trying to implement a document verification using proofable node sdk.
Is there a way to implement an incremental way of hashing a directory, meaning that root and previous proofs are immutable?

@perdona yes, the proof (trie) itself is immutable, e.g. whenever you modify an existing trie with setTrieKeyValues, a new trie with a new root will be returned, which is built incrementally on top of your old trie. Only modified nodes of the old trie are cloned, other nodes will be shared across the old and new tries. You can still access the old trie with the old root.

For a directory, you can build an initial trie with few key-values, then use setTrieKeyValuess to push more key-values in as a way to build the trie incrementally.

@guiguan Right! So to modify an existing trie, I should use the .proofable exported previously? And which method should I use to proof again new pushed keyvalues? (I'm sorry about posting a lot here)

@perdona yes, for now:

  1. import your existing trie (.proofable) with importTrie
  2. add/update/delete key values with setTrieKeyValues, which will give you the new root
  3. create a proof for the new trie with the new root using createTrieProof
  4. you can use subscribeTrieProof to wait for the new proof to be confirmed. Here is an example
  5. export the new trie which contains everything with exportTrie

After you import the existing trie, you can also use APIs like createkeyvaluesproof to create a proof for a subset of the key-values, and later on, you can use verifyKeyValuesProof to verify them independently.

We are also working on a cloud trie, where we store the trie in Proofable cloud for you and you don't have to keep importing and exporting proofs from time to time.

Thanks a lot @guiguan !