amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.03k stars 1.16k forks source link

LEX with Content-Addressing in user's graph #1267

Open fitouch opened 2 years ago

fitouch commented 2 years ago

https://gun.eco/docs/SEA.certify#5-there-are-ways-to-get-a-list-of-links-added-by-a-particular-user

// 1. We may use a LEX query to get all links for a particular user gun .user(room.pub) .get('#links') .get({'.': {'*': Bob.pub}}) .map() .once((d,k)=> { bobLinks[k]= JSON.parse(d) })

It works only without gun.user(room.pub). Is it a bug? I really want this part for my project.

bmatusiak commented 2 years ago

i thought the same but you dont necessarily need Content-Addressing in a user graph. as the content is protected by the hash.

so hash it like normal. and save it like normal.. put/store the hash's "soul" in the user graph that points to the hashed content

you may just want to store the soul to have it map/link to it.

fitouch commented 2 years ago

I thought about hash it normal, but sometimes I want to edit or delete the message from my own user graph and save soul in the room (user graph). LEX is not working in user graph without hash, is it?

fitouch commented 2 years ago

https://gun.eco/docs/SEA.certify#5-there-are-ways-to-get-a-list-of-links-added-by-a-particular-user

Is the code broken or outdated?

fitouch commented 2 years ago

@bmatusiak I kept testing. LEX does not work in user graph at all. How can we fix it?

bmatusiak commented 2 years ago

use lex in map, not in get, as per @amark

fitouch commented 2 years ago

@bmatusiak https://jsfiddle.net/c04fnro3/24/

The operator "=" does not work in user graph, only public graph. Can you test?

fitouch commented 2 years ago

@bmatusiak @amark

Here's my fix for LEX in user graph. It works for me, I tested it in public graph, content-addressing in public graph, user graph, and user graph with cerify.

The only thing is that the operator "=" does not work well with content-addressing (key + hash) in user graph and public graph. I'm sure we can fix that but for now I want LEX to work in user graph. Let me know what you think of the code below.

gun.js lines 25 - 41 var ms = ""; String.match = function(t, o){ var tmp, u; if(t) {if (t.split("/").length > 1) ms = t.split("/").pop();} if('string' !== typeof t){ return false } if('string' == typeof o){ o = {'=': o} } o = o || {}; tmp = (o['='] || o['*'] || o['>'] || o['<']); if(o["="] && (ms === tmp || t === tmp)){ return true } else if(o["*"] && (ms.startsWith(tmp) || t.startsWith(tmp))){ return true } else if(o[">"] && (ms > tmp || t > tmp)){ return true } else if(o["<"] && (ms < tmp || t < tmp)){ return true } if(u !== o['=']){ return false; } tmp = (o['*'] || o['>']); if(t.slice(0, (tmp||'').length) === tmp){ return true } if(u !== o['*']){ return false; } if(u !== o['>'] && u !== o['<']){ return (t >= o['>'] && t <= o['<'])? true : false; } if(u !== o['>'] && t >= o['>']){ return true } if(u !== o['<'] && t <= o['<']){ return true } return false; }

fitouch commented 2 years ago

@bmatusiak @amark

I spent more time testing with the current code in gun.js and I found that gun.user(Bob.pub).get('list').map().get({'.': { "=": new Date().toISOString() }}) works. Is that expected?

fitouch commented 2 years ago

@bmatusiak @amark @Orimay

I have a fix for LEX issue. I ran "npm run test" and all passed. Can one of you give me an access to commit my fix and review it?

fitouch commented 2 years ago

@amark https://github.com/amark/gun/pull/1268 is ready for review!