SEA tweaks

This commit is contained in:
Mark Nadal 2018-08-24 02:04:58 -07:00
parent 9781877db8
commit 90feaa5397
2 changed files with 18 additions and 21 deletions

19
sea.js
View File

@ -24,7 +24,7 @@
// THIS IS AN EARLY ALPHA!
function SEA(){}
if(typeof window !== "undefined"){ SEA.window = window }
if(typeof window !== "undefined"){ (SEA.window = window).SEA = SEA }
module.exports = SEA;
})(USE, './root');
@ -174,7 +174,7 @@
});
try{
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){
console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
}
@ -240,16 +240,14 @@
})(USE, './parse');
;USE(function(module){
const {
subtle, ossl = subtle, random: getRandomBytes, TextEncoder, TextDecoder
} = USE('./shim')
const shim = USE('./shim');
const Buffer = USE('./buffer')
const parse = USE('./parse')
const { pbkdf2 } = USE('./settings')
// This internal func returns SHA-256 hashed data for signing
const sha256hash = async (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)
}
module.exports = sha256hash
@ -368,7 +366,8 @@
const r = { pub: sa.pub, priv: sa.priv, /* pubId, */ epub: dh.epub, epriv: dh.epriv }
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r;
} catch(e) {
} catch(e) {
console.log(e);
SEA.err = e;
if(cb){ cb() }
return;
@ -404,7 +403,8 @@
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r;
} catch(e) {
} catch(e) {
console.log(e);
SEA.err = e;
if(cb){ cb() }
return;
@ -441,7 +441,8 @@
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r;
} catch(e) {
} catch(e) {
console.log(e);
SEA.err = e;
if(cb){ cb() }
return;

View File

@ -7,7 +7,6 @@ var config = {
'/': __dirname + '/index.html',
'/gun.js': __dirname + '/../../gun.js',
'/jquery.js': __dirname + '/../../examples/jquery.js',
'/cryptomodules.js': __dirname + '/../../lib/cryptomodules.js',
'/sea.js': __dirname + '/../../sea.js'
}
}
@ -57,6 +56,7 @@ describe("Make sure SEA syncs correctly", function(){
res.end("I am "+ env.i +"!");
});
var Gun = require('gun');
require('gun/sea');
var gun = Gun({file: env.i+'data', web: server});
server.listen(port, function(){
test.done();
@ -80,10 +80,8 @@ describe("Make sure SEA syncs correctly", function(){
script.onload = cb; script.src = src;
document.head.appendChild(script);
}
load('cryptomodules.js', function(){
load('sea.js', function(){
test.done();
});
load('sea.js', function(){
test.done();
});
}, {i: i += 1, config: config}));
});
@ -140,8 +138,8 @@ describe("Make sure SEA syncs correctly", function(){
return bob.run(function(test){
test.async();
window.gun.get('alias/alice').map().val(function(data){
window.ref = gun.get('pub/'+data.pub);
window.gun.get('~@alice').map().once(function(data){
window.ref = gun.get('~'+data.pub);
test.done();
});
});
@ -152,7 +150,7 @@ describe("Make sure SEA syncs correctly", function(){
test.async();
window.count = [];
ref.get('who').get('said').map().val(function(data){
ref.get('who').get('said').map().once(function(data){
console.log("read...", data);
window.count.push(data);
if(window.count.length - 1){ return }
@ -181,10 +179,8 @@ describe("Make sure SEA syncs correctly", function(){
script.onload = cb; script.src = src;
document.head.appendChild(script);
}
load('cryptomodules.js', function(){
load('sea.js', function(){
test.done();
});
load('sea.js', function(){
test.done();
});
}, {i: 1, config: config});
});