maidsafe-archive / beaker-plugin-safe-app Goto Github PK
View Code? Open in Web Editor NEWSAFE App API plugin for SAFE Browser
License: GNU General Public License v3.0
SAFE App API plugin for SAFE Browser
License: GNU General Public License v3.0
MD keys are returned as an object rather than uint8array like md values. This means developers are not able to use .toString() on keys but are able to use it on values. There is a work around for this
function uintToString(key) {
let uintArray = new Uint8Array(Object.values(key));
return new TextDecoder('utf-8').decode(uintArray);
}
(taken from Feedy)
which returns the md keys as a string. Also I noticed that as a string the letter "r" was added on to one of the keys in the latest browser.
http://docs.maidsafe.net/beaker-plugin-safe-app/#filemetadata
dataMapName should be datamapName (i.e. as returned by the code)
I'm a bit confused here as I've had very similar code working before. I may go back to that and try to figure out what's causing this, but it would probably be quicker for Maidsafe to see what's happening and it may be a bug anyway, if an obscure one.
I'll link to the full code in a follow up, but what I'm doing is the usual auth, initialise, connect using the safeApp API and then I try to access the _public container. The result though is always 'false' (I don't have access).
If I break the code in the .then() handler, I see the result is false (no error - implying appHandle is valid). If I do the following in the console at that point:
window.safeApp.canAccessContainer(appHandle, '_public', ['Read'])
...then examine the Promise, it is always resolved to false, which I think means it is not a timing issue.
Given it doesn't generate an error I don't think it should ever return false for those parameters. So either it's a bug in not generating an error, or I'm falling over some other bug. Unless... stupid 😉
There's a forum discussion: https://forum.safedev.org/t/container-access-any-recent-dom-api-changes/1314?u=happybeing
The code is probably live on alpha2 at: safe://solidpoc5
I've just pushed to github here:
Relevant code is in solid-safenetwork.js.
The call is in _getMdHandle():
https://github.com/theWebalyst/solid-safenetwork/blob/wip/src/safenetwork-solid.js#L592
Where the safeApp.authorise, initisalise and connect are done in safenetworkAuthorise() here:
https://github.com/theWebalyst/solid-safenetwork/blob/wip/src/safenetwork-solid.js#L364
i get an error when trying to fetch immutable data here is a section of my code
window.safeNfs.fetch(nfsHandle, uintToString(key)))
.then((fileHandle) =>
window.safeNfs.getFileMeta(fileHandle))
.then((fileMeta) => {
console.log('file meta:', fileMeta);
console.log(fileMeta.dataMapName.buffer);
window.safeImmutableData.fetch(authorisedAppToken, fileMeta.dataMapName.buffer)
.then((readerHandle) =>
window.safeImmutableData.read(readerHandle))
.then((data) =>
console.log('ImmutableData data read: ', data));
});
and here are the results from the console
file meta: Object {dataMapName: Object, size: 423, version: 0}
VM94:79 [5, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
VM94:78 file meta: Object {dataMapName: Object, size: 7032, version: 0}
VM94:79 [5, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
VM94:78 file meta: Object {dataMapName: Object, size: 3587, version: 0}
VM94:79 [5, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
VM94:78 file meta: Object {dataMapName: Object, size: 3538, version: 0}
VM94:79 [5, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0]
C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203 Uncaught (in promise) Error: Core error: Routing client error -> Requested data not found(…)onCbReply @ C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203onIPCMessage @ C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:118emitMany @ events.js:127emit @ events.js:201
C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203 Uncaught (in promise) Error: Core error: Routing client error -> Requested data not found(…)onCbReply @ C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203onIPCMessage @ C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:118emitMany @ events.js:127emit @ events.js:201
C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203 Uncaught (in promise) Error: Core error: Routing client error -> Requested data not found(…)onCbReply @ C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203onIPCMessage @ C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:118emitMany @ events.js:127emit @ events.js:201
C:\Users\josephm\Desktop\New folder\safe-browser-v0.3.0-win-x64\resources\app\node_modules\pauls-el…:203 Uncaught (in promise) Error: Core error: Routing client error -> Requested data not found(…)
tested on safe browser v0.3
I just wanted to play around with Private MDs and noticed that I can't generate a nonce. I first authenticate against the network and afterwards I call window.safeCrypto.generateNonce() which fails with the following msg. It can be tested here: safe://www.lol/index.html
First click auth button, wait, and afterwards click create private MD.
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}proto: Promise[[PromiseStatus]]: "rejected"[[PromiseValue]]: Error: Invalid handle: undefined
at onCbReply (F:\safe\safe-browser\resources\app\node_modules\pauls-electron-rpc\lib\import-api.js:203:19)
at EventEmitter.onIPCMessage (F:\safe\safe-browser\resources\app\node_modules\pauls-electron-rpc\lib\import-api.js:118:14)
at emitMany (events.js:127:13)
at EventEmitter.emit (events.js:201:7)message: "Invalid handle: undefined"stack: (...)get stack: stack()set stack: stack()proto: Object
F:\safe\safe-browser\resources\app\node_modules\pauls-el…:203
Uncaught (in promise) Error: Invalid handle: undefined(…)onCbReply @ F:\safe\safe-browser\resources\app\node_modules\pauls-el…:203onIPCMessage @ F:\safe\safe-browser\resources\app\node_modules\pauls-el…:118emitMany @ events.js:127emit @ events.js:201
When using window.safeMutableDataEntries.forEach
,
until browser 0.7 , I used to be able to read the returned keys as strings.
Now, with the 0.8 browser I get an object in the form of :
Object {0: 95, 1: 109, 2: 101, 3: 116, 4: 97, 5: 100, 6: 97, 7: 116, 8: 97, _refs: Array(1)}
I see that this one translates into :" metadata" , ""
Is window.safeMutableDataEntries.forEach supposed to return a key for the mutable metadata ? I don't think it was the case before.
How do you access the key name now ? the doc ( 0.4.3 ) says : k.toString() , but this just returns "[object Object]"
[This issue was posted earlier today on the dev forum, but I think it may be more appropriate here]
I have a live app on Alpha2 which is behaving oddly, quite likely my fault, but possibly a bug in the API.
The issue is that while I am using safeMutableData.getVersion()
successfully most of the time, I can also reliably cause it to fail with an 'invalid handle' error, although the handle it reports as invalid is as expected, so I don't know why it thinks it is invalid.
To reproduce:
appHandle
and a delay while you authorise litewrite, after which the handle for the MD container, and an 'emulate as NFS' handle are printed for later reference by a function called _getMdHandle
(search for the latter in the console output if you can't find the messages).window.safeMutableData.getEntries(self.mdRoot)
- which is successfully using the handle which the error reports as invalid. See _getFolder implementation for that call to window.safeMutableData.getEntries(self.mdRoot)
. Notice that _getFolder
is successfully calling the function that is later generating an error (window.safeMutableData.getVersion(self.mdRoot)
) and with the same MD handle.I may be doing something wrong in how I'm using the API, or maybe I'm triggering a bug in it, or? I'm not really sure how to debug this without getting into the browser code and I'm not ready to do that! Any ideas, help appreciated. Thanks.
If anyone else want to try the above and report whether they get this error (or others) or not, please do, it may be helpful.
I apologise now for the structure of the code to any who open it - I'm still a newb on how best to use promises, handle errors etc. Tips gratefully received from everyone :slight_smile:
Using: Peruse built locally for mock (0.41 I think)
I pass a callback to safeApp.initialise()
but this is never called, so my app thinks the network is always disconnected. I beleive the callback should be called when I do a successful safeApp.connectAuthorised()
.
Here's my code:
https://github.com/theWebalyst/solid-safenetwork/blob/wip/src/safenetwork-webapi.js#L220
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.