-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Content Addressing
Mark Nadal edited this page Apr 7, 2020
·
13 revisions
A hash is a short yet unique "fingerprint" of your data. It can be used as a name that is self-referencing to itself, frozen at some point in time. For instance, if the data were to change, then it would also get a new name.
This is useful, because it lets you verify that data has not been changed even if it is in a public place. And using SEA with GUN, it prevent peers from changing the data if some name/key combo of '#'+hash is used.
Note: This does not guarantee peers will keep the data saved though, they might expire it over time.
Here is a quick example of how to get started:
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
<script>
var gun = Gun();
var data = "hello world";
var hash = await SEA.work(data, null, null, {name: "SHA-256"});
gun.get('#').get(hash).put(data);
gun.get('#').get(hash).once(console.log);
</script>Later, try to do something like:
gun.get('#').get(hash).put("hi");
And you'll see an error that the hashes are not the same.