SHA256 hash selection algorithm for AXE - amark/gun GitHub Wiki

Gets the 'closest' SHA256 hash of the passed in string

Example code for Node. Will need to be adapted for browser support.

const crypto = require('crypto')

import SEA from 'gun/sea/sea.js'

let data = []

let data1 = await SEA.work('mark/name', null, null, {name: "SHA-256", encode: 'hex'})
let data2 = await SEA.work('mark/phone', null, null, {name: "SHA-256", encode: 'hex'})
let data3 = await SEA.work('mark/age', null, null, {name: "SHA-256", encode: 'hex'})

data.push(data1, data2, data3)
console.log(data)

let closest = data.reduce((min, c) => c < min? c : min)
let furthest = data.reduce((max, c) => c > max? c : max)

console.log('closest', closest, 'furthest', furthest)