mirror of
https://github.com/amark/gun.git
synced 2025-06-07 14:46:44 +00:00
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:
parent
cedf9b8809
commit
d06359f45c
@ -68,7 +68,14 @@
|
|||||||
}
|
}
|
||||||
check.hash = function(eve, msg, val, key, soul, at, no){
|
check.hash = function(eve, msg, val, key, soul, at, no){
|
||||||
SEA.work(val, null, function(data){
|
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) }
|
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!");
|
no("Data hash not same as hash!");
|
||||||
}, {name: 'SHA-256'});
|
}, {name: 'SHA-256'});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user