mirror of
https://github.com/amark/gun.git
synced 2025-06-06 22:26:48 +00:00
sea.js bugfix & Gun chat to have SEA & User stuff in comments
This commit is contained in:
parent
ae68b13528
commit
ccdf936304
29
.eslintrc
Normal file
29
.eslintrc
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"parser": "babel-eslint",
|
||||||
|
"extends": [
|
||||||
|
"standard",
|
||||||
|
"eslint:recommended"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"babel",
|
||||||
|
"promise"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"browser" : true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"__DEV__" : false,
|
||||||
|
"__TEST__" : false,
|
||||||
|
"__PROD__" : false,
|
||||||
|
"__COVERAGE__" : false
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"key-spacing" : 0,
|
||||||
|
"jsx-quotes" : [2, "prefer-single"],
|
||||||
|
"max-len" : [2, 80, 2],
|
||||||
|
"object-curly-spacing" : [2, "always"],
|
||||||
|
"semi" : [2, "never"],
|
||||||
|
"no-mixed-spaces-and-tabs": [2],
|
||||||
|
"arrow-parens" : [2, "always"]
|
||||||
|
}
|
||||||
|
}
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ yarn.lock
|
|||||||
*.bak
|
*.bak
|
||||||
*.new
|
*.new
|
||||||
*.DS_store
|
*.DS_store
|
||||||
|
.esm-cache
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
.poiret {
|
.poiret {
|
||||||
font-family: 'Poiret One', sans-serif;
|
font-family: 'Poiret One', sans-serif;
|
||||||
}
|
}
|
||||||
.large {
|
.large {
|
||||||
font-size: 200%;
|
font-size: 200%;
|
||||||
}
|
}
|
||||||
#converse .what, #converse .who {
|
#converse .what, #converse .who {
|
||||||
@ -68,8 +68,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<script src="/jquery.js"></script>
|
<script src="/jquery.js"></script>
|
||||||
<script src="/gun.js"></script>
|
<script src="/gun.js"></script>
|
||||||
|
<!--
|
||||||
|
<script src="/gun/lib/cryptography.js"></script>
|
||||||
|
<script src="/gun/sea.js"></script>
|
||||||
|
-->
|
||||||
<script>
|
<script>
|
||||||
var gun = Gun(location.origin+'/gun');
|
var gun = Gun(location.origin+'/gun');
|
||||||
|
var user = gun.user && gun.user();
|
||||||
|
if (user) {
|
||||||
|
// 1st: call create. 2nd call auth. After that, call recall
|
||||||
|
// user.create('dude', 'my secret').then(function(ack) { console.log('created ack:', ack) })
|
||||||
|
// user.auth('dude', 'my secret').then(function(user) { console.log('authenticated user:', user) })
|
||||||
|
// user.recall().then(function(ack) { console.log('recall ack:', ack) });
|
||||||
|
}
|
||||||
var chat = gun.get('converse');
|
var chat = gun.get('converse');
|
||||||
chat.map().val(function(msg, field){
|
chat.map().val(function(msg, field){
|
||||||
var ul = $('ul'), last = sort(field, ul.children('li').last()), li;
|
var ul = $('ul'), last = sort(field, ul.children('li').last()), li;
|
||||||
|
9
index.js
9
index.js
@ -1 +1,8 @@
|
|||||||
module.exports = require('./lib/server');
|
|
||||||
|
const Gun = require('./lib/gunwrapper')
|
||||||
|
const myDir = __dirname // TODO: where did __dirname go ?
|
||||||
|
|
||||||
|
// From here on we're ES6 import compatible...
|
||||||
|
require = require('@std/esm')(module) // eslint-disable-line no-global-assign
|
||||||
|
|
||||||
|
module.exports = require('./lib/server.mjs').default(Gun, myDir)
|
||||||
|
12051
lib/cryptography.js
12051
lib/cryptography.js
File diff suppressed because one or more lines are too long
15
lib/gunwrapper.js
Normal file
15
lib/gunwrapper.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
// This does all old-fashion require stuff before '@std/mjs' steps in...
|
||||||
|
const Gun = require('../gun')
|
||||||
|
require('../nts')
|
||||||
|
require('./s3')
|
||||||
|
try {
|
||||||
|
require('./ws')
|
||||||
|
} catch (e) {
|
||||||
|
require('./wsp/server')
|
||||||
|
}
|
||||||
|
require('./verify')
|
||||||
|
require('./file')
|
||||||
|
require('./bye')
|
||||||
|
|
||||||
|
module.exports = Gun
|
41
lib/serve.mjs
Normal file
41
lib/serve.mjs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
|
let dirname // TODO: where did __dirname go ?
|
||||||
|
|
||||||
|
const serve = (req, res, nxt) => {
|
||||||
|
if (!req || !res) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = nxt || serve
|
||||||
|
|
||||||
|
if (!req.url) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 <= req.url.indexOf('gun.js')) {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||||
|
res.end(serve.js = serve.js || fs.readFileSync(dirname + '/gun.js'))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 <= req.url.indexOf('gun/')) {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/javascript' })
|
||||||
|
var path = dirname + '/' + req.url.split('/').slice(2).join('/'), file
|
||||||
|
try {
|
||||||
|
file = fs.readFileSync(path)
|
||||||
|
} catch(e) {} // eslint-disable-line no-empty
|
||||||
|
if (file) {
|
||||||
|
res.end(file)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (dir) => {
|
||||||
|
dirname = dir
|
||||||
|
return serve
|
||||||
|
}
|
7
lib/server.mjs
Normal file
7
lib/server.mjs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
import serve from './serve'
|
||||||
|
|
||||||
|
export default (Gun, dir) => { // TODO: where did __dirname go ?
|
||||||
|
Gun.serve = serve(dir)
|
||||||
|
return Gun
|
||||||
|
}
|
@ -47,22 +47,24 @@
|
|||||||
"node": ">=0.6.6"
|
"node": ">=0.6.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@std/esm": "^0.8.3",
|
||||||
"aws-sdk": ">=2.41.0",
|
"aws-sdk": ">=2.41.0",
|
||||||
"formidable": ">=1.1.1",
|
"formidable": ">=1.1.1",
|
||||||
"ws": "~>2.2.3"
|
"ws": "~>2.2.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"express": ">=4.15.2",
|
|
||||||
"subtle": "^0.1.8",
|
|
||||||
"text-encoding": "^0.6.4",
|
|
||||||
"buffer": "^5.0.7",
|
"buffer": "^5.0.7",
|
||||||
"eccrypto": "^1.0.3",
|
"eccrypto": "^1.0.3",
|
||||||
|
"express": ">=4.15.2",
|
||||||
"hapi": "^16.1.1",
|
"hapi": "^16.1.1",
|
||||||
"inert": "^4.2.0",
|
"inert": "^4.2.0",
|
||||||
"ip": "^1.1.5",
|
"ip": "^1.1.5",
|
||||||
"mocha": ">=3.2.0",
|
"mocha": ">=3.2.0",
|
||||||
|
"node-localstorage": "^1.3.0",
|
||||||
"panic-manager": "^1.2.0",
|
"panic-manager": "^1.2.0",
|
||||||
"panic-server": "^1.1.0",
|
"panic-server": "^1.1.0",
|
||||||
|
"subtle": "^0.1.8",
|
||||||
|
"text-encoding": "^0.6.4",
|
||||||
"uglify-js": ">=2.8.22",
|
"uglify-js": ">=2.8.22",
|
||||||
"uws": "~>0.14.1"
|
"uws": "~>0.14.1"
|
||||||
}
|
}
|
||||||
|
7
sea.js
7
sea.js
@ -665,7 +665,7 @@
|
|||||||
}
|
}
|
||||||
if('pub/' === soul.slice(0,4)){ // special case, account data for a public key.
|
if('pub/' === soul.slice(0,4)){ // special case, account data for a public key.
|
||||||
each.pub(val, key, node, soul, soul.slice(4));
|
each.pub(val, key, node, soul, soul.slice(4));
|
||||||
}
|
}
|
||||||
if(at.user && (tmp = at.user._.sea)){ // not special case, if we are logged in, then
|
if(at.user && (tmp = at.user._.sea)){ // not special case, if we are logged in, then
|
||||||
each.user(val, key, node, soul, tmp);
|
each.user(val, key, node, soul, tmp);
|
||||||
}
|
}
|
||||||
@ -716,7 +716,10 @@
|
|||||||
each.own = function(val, key, node, soul, tmp){
|
each.own = function(val, key, node, soul, tmp){
|
||||||
check['own'+soul+key] = 1;
|
check['own'+soul+key] = 1;
|
||||||
SEA.read(val, tmp, function(data){
|
SEA.read(val, tmp, function(data){
|
||||||
|
var u;
|
||||||
check['own'+soul+key] = 0;
|
check['own'+soul+key] = 0;
|
||||||
|
// TODO: hopefully fixed this right, typeof u === 'undefined' thus
|
||||||
|
// if there is signature, and data is undefined, then:
|
||||||
on.to('end', {no: tmp = (u === (val = data)), err: tmp && "Signature mismatch!"});
|
on.to('end', {no: tmp = (u === (val = data)), err: tmp && "Signature mismatch!"});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -807,7 +810,7 @@
|
|||||||
SEA.verify = function(m, p, s, cb){
|
SEA.verify = function(m, p, s, cb){
|
||||||
var doIt = function(resolve, reject){
|
var doIt = function(resolve, reject){
|
||||||
ecCrypto.verify(new Buffer(p, 'hex'), nodehash(m), new Buffer(s, 'hex'))
|
ecCrypto.verify(new Buffer(p, 'hex'), nodehash(m), new Buffer(s, 'hex'))
|
||||||
.then(function(){resolve(true)})
|
.then(function(){ resolve(true)})
|
||||||
.catch(function(e){ Gun.log(e);reject(e) })
|
.catch(function(e){ Gun.log(e);reject(e) })
|
||||||
};
|
};
|
||||||
if(cb){doIt(cb, function(){cb()})} else { return new Promise(doIt) }
|
if(cb){doIt(cb, function(){cb()})} else { return new Promise(doIt) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user