mirror of
https://github.com/amark/gun.git
synced 2025-06-06 14:16:44 +00:00
SEA tweaks
This commit is contained in:
parent
9781877db8
commit
90feaa5397
13
sea.js
13
sea.js
@ -24,7 +24,7 @@
|
|||||||
// THIS IS AN EARLY ALPHA!
|
// THIS IS AN EARLY ALPHA!
|
||||||
|
|
||||||
function SEA(){}
|
function SEA(){}
|
||||||
if(typeof window !== "undefined"){ SEA.window = window }
|
if(typeof window !== "undefined"){ (SEA.window = window).SEA = SEA }
|
||||||
|
|
||||||
module.exports = SEA;
|
module.exports = SEA;
|
||||||
})(USE, './root');
|
})(USE, './root');
|
||||||
@ -174,7 +174,7 @@
|
|||||||
});
|
});
|
||||||
try{
|
try{
|
||||||
const WebCrypto = require('node-webcrypto-ossl')
|
const WebCrypto = require('node-webcrypto-ossl')
|
||||||
api.ossl = new WebCrypto({directory: 'key_storage'}).subtle // ECDH
|
api.ossl = new WebCrypto({directory: 'ossl'}).subtle // ECDH
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
|
console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
|
||||||
}
|
}
|
||||||
@ -240,16 +240,14 @@
|
|||||||
})(USE, './parse');
|
})(USE, './parse');
|
||||||
|
|
||||||
;USE(function(module){
|
;USE(function(module){
|
||||||
const {
|
const shim = USE('./shim');
|
||||||
subtle, ossl = subtle, random: getRandomBytes, TextEncoder, TextDecoder
|
|
||||||
} = USE('./shim')
|
|
||||||
const Buffer = USE('./buffer')
|
const Buffer = USE('./buffer')
|
||||||
const parse = USE('./parse')
|
const parse = USE('./parse')
|
||||||
const { pbkdf2 } = USE('./settings')
|
const { pbkdf2 } = USE('./settings')
|
||||||
// This internal func returns SHA-256 hashed data for signing
|
// This internal func returns SHA-256 hashed data for signing
|
||||||
const sha256hash = async (mm) => {
|
const sha256hash = async (mm) => {
|
||||||
const m = parse(mm)
|
const m = parse(mm)
|
||||||
const hash = await ossl.digest({name: pbkdf2.hash}, new TextEncoder().encode(m))
|
const hash = await shim.subtle.digest({name: pbkdf2.hash}, new shim.TextEncoder().encode(m))
|
||||||
return Buffer.from(hash)
|
return Buffer.from(hash)
|
||||||
}
|
}
|
||||||
module.exports = sha256hash
|
module.exports = sha256hash
|
||||||
@ -369,6 +367,7 @@
|
|||||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||||
return r;
|
return r;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
SEA.err = e;
|
SEA.err = e;
|
||||||
if(cb){ cb() }
|
if(cb){ cb() }
|
||||||
return;
|
return;
|
||||||
@ -405,6 +404,7 @@
|
|||||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||||
return r;
|
return r;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
SEA.err = e;
|
SEA.err = e;
|
||||||
if(cb){ cb() }
|
if(cb){ cb() }
|
||||||
return;
|
return;
|
||||||
@ -442,6 +442,7 @@
|
|||||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||||
return r;
|
return r;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
SEA.err = e;
|
SEA.err = e;
|
||||||
if(cb){ cb() }
|
if(cb){ cb() }
|
||||||
return;
|
return;
|
||||||
|
@ -7,7 +7,6 @@ var config = {
|
|||||||
'/': __dirname + '/index.html',
|
'/': __dirname + '/index.html',
|
||||||
'/gun.js': __dirname + '/../../gun.js',
|
'/gun.js': __dirname + '/../../gun.js',
|
||||||
'/jquery.js': __dirname + '/../../examples/jquery.js',
|
'/jquery.js': __dirname + '/../../examples/jquery.js',
|
||||||
'/cryptomodules.js': __dirname + '/../../lib/cryptomodules.js',
|
|
||||||
'/sea.js': __dirname + '/../../sea.js'
|
'/sea.js': __dirname + '/../../sea.js'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,6 +56,7 @@ describe("Make sure SEA syncs correctly", function(){
|
|||||||
res.end("I am "+ env.i +"!");
|
res.end("I am "+ env.i +"!");
|
||||||
});
|
});
|
||||||
var Gun = require('gun');
|
var Gun = require('gun');
|
||||||
|
require('gun/sea');
|
||||||
var gun = Gun({file: env.i+'data', web: server});
|
var gun = Gun({file: env.i+'data', web: server});
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
test.done();
|
test.done();
|
||||||
@ -80,11 +80,9 @@ describe("Make sure SEA syncs correctly", function(){
|
|||||||
script.onload = cb; script.src = src;
|
script.onload = cb; script.src = src;
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
load('cryptomodules.js', function(){
|
|
||||||
load('sea.js', function(){
|
load('sea.js', function(){
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}, {i: i += 1, config: config}));
|
}, {i: i += 1, config: config}));
|
||||||
});
|
});
|
||||||
return Promise.all(tests);
|
return Promise.all(tests);
|
||||||
@ -140,8 +138,8 @@ describe("Make sure SEA syncs correctly", function(){
|
|||||||
return bob.run(function(test){
|
return bob.run(function(test){
|
||||||
test.async();
|
test.async();
|
||||||
|
|
||||||
window.gun.get('alias/alice').map().val(function(data){
|
window.gun.get('~@alice').map().once(function(data){
|
||||||
window.ref = gun.get('pub/'+data.pub);
|
window.ref = gun.get('~'+data.pub);
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -152,7 +150,7 @@ describe("Make sure SEA syncs correctly", function(){
|
|||||||
test.async();
|
test.async();
|
||||||
|
|
||||||
window.count = [];
|
window.count = [];
|
||||||
ref.get('who').get('said').map().val(function(data){
|
ref.get('who').get('said').map().once(function(data){
|
||||||
console.log("read...", data);
|
console.log("read...", data);
|
||||||
window.count.push(data);
|
window.count.push(data);
|
||||||
if(window.count.length - 1){ return }
|
if(window.count.length - 1){ return }
|
||||||
@ -181,11 +179,9 @@ describe("Make sure SEA syncs correctly", function(){
|
|||||||
script.onload = cb; script.src = src;
|
script.onload = cb; script.src = src;
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
load('cryptomodules.js', function(){
|
|
||||||
load('sea.js', function(){
|
load('sea.js', function(){
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}, {i: 1, config: config});
|
}, {i: 1, config: config});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user