Giter VIP home page Giter VIP logo

beaker-plugin-safe-app's People

Contributors

b-zee avatar bochaco avatar frabrunelle avatar hitman401 avatar hunterlester avatar joshuef avatar loziniak avatar pravarseth avatar s-coyle avatar safesurfer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beaker-plugin-safe-app's Issues

Getting Mutable Data keys

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.

window.safeApp.canAccessContainer(appHandle, '_public', ['Read']) always resolves false

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

fetching immutable data

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

Error when calling window.safeCrypto.generateNonce(): Invalid handle: undefined

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

window.safeMutableDataEntries.forEach , v 0.4.3

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]"

safeMutableData.getVersion() FAILED due to invalid container handle

[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:

  1. Login to an account on Alpha2 and visit safe://litewrite.rsports - this is a simple note taking app which allows you to create notes offline or online, and syncs them to SAFE storage when online.
  2. Create a note (the app is offline at this stage), by clicking the '+' top left, and entering text in the area just to the right. The first line of the text serves as a document title, and a menu entry will be added to the left, under the '+'.
  3. Connect to SAFE by clicking the SAFE icon in the top right of the litewrite display. Notice the activity in the debug console: you'll see the 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).
  4. In the console you will see lots of activity following connection, and at this point I believe there will not be any errors (but I can't be sure of that as I have made some code changes since I had a clean account to play with). You will also notice that so long as you remain connected, the console shows a flurry of output every ten seconds, when the RS.js core of the app attempts to sync local storage (IndexDB entries) with files it creates in the root container, in /remotestorage/documents/notes/. This includes stuff to show me that my code is accessing the container and generating a directory listing by filtering the results of 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.
  5. Set a breakpoint (if you like) at the line in litewrite.min.js containing the text 'safeMutableData.getVersion() FAILED'
  6. Create a new note (click the '+') and type a few characters. This will force an immediate attempt to sync with the network and is when I get the error. Repeat this until you get the error in the console (or hit that breakpoint). For me I get it every time now.

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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.