I’m currently exploring the possibilities of beaker-plugin-safe-app and wondering how I can access a stored data (e.g. mutable data) at a later point. The example codes in the documentation only mention cases where you create a new MD and then directly use the returned handle. However, when I close the browser I obviously don’t have the handle anymore. Of course I could just store the handle in another data object, but at some point I would need a storage object which I can find via a name/alias or given address.
I’ve seen that it’s possible to generate data at a given address but can’t find how to retrieve the data by providing the chosen address. Am I missing something?
Hi @Mindphreaker, this wouldn’t work, the handle is provided by the browser safe_app plugin and it’s just to keep track of the libs objects instantiated in the local memory, so they are not handles that the network understands or stores anyhow.
If you created a public MutableData with a random address you can retrieve its name/address using
Once you have the address of the public MutableData you can just call
window.safeMutableData.newPublic with the address and type tag, and you should be able to retrieve the stored data using the rest of the MutableData functions.
Another alternative is to make use of the
window.safeMutableData.fromSerial functions, which you actually need to use if you are dealing with private MutableData.
Thx @bochaco that was the missing link! I thought newPublic is only for creating (storing) MD but if I understand you correct, it’s for both, storing and retrieving MD? Or is it just for retrieving and I’m only able to generate MD at a rondom address using newRandomPublic?
Exploring this further I noticed that getNameAndTag returns a Uint8Array. How can this be used to retrieve the MD? In the examples the address is always some string or handle.
I had the exact same question as @Mindphreaker. Could you elaborate further on your quoted statement? I’m not a web dev by trade, so I have a lot of catching up to do, but I saw in another thread that there is HTML5 local storage that could hold the serialized MD. But the user could be logging into the app from different computers. How then would you access a private MD created on one device from a different device in the future? Are there any examples of what you described in the demo apps? Thx in advance.
Hi @Mindphreaker, I think an example of this is what happens with the email app inbox MD, there are other cases in the apps where we also use this technique, but this one is quite simple to review if that’s what you need.
The email app creates the inbox MD at a random address when you create your email ID:
It then serialises it:
…and it then stores it in its own container, the app’s own container:
When you open the app from another device, or even from the same device after restarting the email app, it goes and gets the serialised inbox from it’s own container, it deserialises it, and after that it can action on it using the MutableData functions:
I’m really sorry but to be honest, this example raises more questions than it solves. E.g. you mentioned that serialisation is needed for storing PrivateMD:
- If I see it correctly, your example stores a PublicMD
- Why is serialisation needed for PrivateMD and not for PublicMD
- Why do I even need to serialise in the first place?
There is reason for this, to encrypt some data the encryptor function/method needs to know the data. So rather than an encryptor method that takes any data type, generally it will take a stream of bytes. Many of the algorithms in enc/compress etc. work on a byte array. The simplest cross platform way to get a byte array is to serialise a type into the byte array.
I hope this makes sense.
This makes sense. But the mentioned example code uses it for a PublicMD which isn’t even encrypted, right?
Btw: I’ll split my other question in another topic to prevent even more confusion.
A reason why you may want to serialise a public MD is so you don’t have to keep track of its XorName and tag type somewhere, remember that to fetch a MutableData from the network you need both the XoRname and its tag type as its address in the network is a composite of the two.
Wouldn’t duplicating the MD in serialized form in the app’s container make the application more expensive for the users (like twice as expensive)? I think it will take some playing around with the email app to better grasp this. My intuition was that the apps would be storing address pointers to the data that they need, similar to what was done for immutable data in the email app archive.
This topic was automatically closed after 60 days. New replies are no longer allowed.