SEA - Update sea.work to support hex (#1266)

This was would encode to hex:
```var data = "hello world";
var hash1 = await SEA.work(data, null, null, {name: "SHA-256",encode:
"hex"});
```
but this would not verify correctly:
gun.get('#').get(hash1).put(data);

This PR will first check base64 (current functionality) and if it fails now it will fall back and check hex.
This commit is contained in:
I001962 2022-08-09 15:24:29 -07:00 committed by GitHub
parent cedf9b8809
commit d06359f45c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,7 +68,14 @@
}
check.hash = function(eve, msg, val, key, soul, at, no){
SEA.work(val, null, function(data){
function hexToBase64(hexStr) {
let base64 = "";
for(let i = 0; i < hexStr.length; i++) {
base64 += !(i - 1 & 1) ? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16)) : ""}
return btoa(base64);}
if(data && data === key.split('#').slice(-1)[0]){ return eve.to.next(msg) }
else if (data && data === hexToBase64(key.split('#').slice(-1)[0])){
return eve.to.next(msg) }
no("Data hash not same as hash!");
}, {name: 'SHA-256'});
}
@ -238,4 +245,4 @@
var fl = Math.floor; // TODO: Still need to fix inconsistent state issue.
// TODO: Potential bug? If pub/priv key starts with `-`? IDK how possible.