Browse Source

update gundb, fix user leave

Nikolay Suslov 5 years ago
parent
commit
592efca5a8

+ 11 - 1
public/lib/gundb/sea.js

@@ -47,6 +47,15 @@
   })(USE, './https');
 
   ;USE(function(module){
+    if(typeof global !== "undefined"){
+      var g = global;
+      g.btoa = function (data) { return Buffer.from(data, "binary").toString("base64"); };
+      g.atob = function (data) { return Buffer.from(data, "base64").toString("binary"); };
+    }
+  })(USE, './base64');
+
+  ;USE(function(module){
+    USE('./base64');
     // This is Array extended to have .toString(['utf8'|'hex'|'base64'])
     function SeaArray() {}
     Object.assign(SeaArray, { from: Array.from })
@@ -72,6 +81,7 @@
   })(USE, './array');
 
   ;USE(function(module){
+    USE('./base64');
     // This is Buffer implementation used in SEA. Functionality is mostly
     // compatible with NodeJS 'safe-buffer' and is used for encoding conversions
     // between binary and 'hex' | 'utf8' | 'base64'
@@ -174,7 +184,7 @@
         random: (len) => Buffer.from(crypto.randomBytes(len))
       });
       //try{
-        const WebCrypto = USE('node-webcrypto-ossl', 1);
+        const { Crypto: WebCrypto } = USE('@peculiar/webcrypto', 1);
         api.ossl = api.subtle = new WebCrypto({directory: 'ossl'}).subtle // ECDH
       //}catch(e){
         //console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");

+ 3 - 1
public/lib/gundb/sea/array.js

@@ -1,4 +1,6 @@
-
+    function btoa(b) {
+      return new Buffer(b).toString('base64');
+    };
     // This is Array extended to have .toString(['utf8'|'hex'|'base64'])
     function SeaArray() {}
     Object.assign(SeaArray, { from: Array.from })

+ 3 - 1
public/lib/gundb/sea/buffer.js

@@ -1,4 +1,6 @@
-
+    function atob(a) {
+      return new Buffer(a, 'base64').toString('binary');
+    };
     // This is Buffer implementation used in SEA. Functionality is mostly
     // compatible with NodeJS 'safe-buffer' and is used for encoding conversions
     // between binary and 'hex' | 'utf8' | 'base64'

+ 1 - 1
public/lib/gundb/sea/shim.js

@@ -22,7 +22,7 @@
         random: (len) => Buffer.from(crypto.randomBytes(len))
       });
       //try{
-        const WebCrypto = require('node-webcrypto-ossl', 1);
+        const { Crypto: WebCrypto } = USE('@peculiar/webcrypto', 1);
         api.ossl = api.subtle = new WebCrypto({directory: 'ossl'}).subtle // ECDH
       //}catch(e){
         //console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");

+ 8 - 7
public/web/index-app.js

@@ -400,13 +400,14 @@ class IndexApp {
                             {
                                 "label": 'Sign OUT',
                                 "onclick": function (e) {
-                                    _LCSDB.user().leave().then(function(ack) {
-                                        if (ack.pub) {
-                                            window.sessionStorage.removeItem('alias');
-                                            window.sessionStorage.removeItem('tmp');
-                                            window.location.reload(true);
-                                        }
-                                    });
+                                    _LCSDB.user().leave();
+                                    setTimeout(() =>  
+                                   {
+                                    //window.sessionStorage.removeItem('alias');
+                                    //window.sessionStorage.removeItem('tmp');
+                                    window.location.reload(true);
+                                }, 1);
+                                   
                                 }
                             }),
                         {