mirror of
https://github.com/amark/gun.git
synced 2025-06-03 20:56:43 +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
|
||||
*.new
|
||||
*.DS_store
|
||||
.esm-cache
|
||||
|
@ -34,7 +34,7 @@
|
||||
.poiret {
|
||||
font-family: 'Poiret One', sans-serif;
|
||||
}
|
||||
.large {
|
||||
.large {
|
||||
font-size: 200%;
|
||||
}
|
||||
#converse .what, #converse .who {
|
||||
@ -68,8 +68,19 @@
|
||||
</div>
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<!--
|
||||
<script src="/gun/lib/cryptography.js"></script>
|
||||
<script src="/gun/sea.js"></script>
|
||||
-->
|
||||
<script>
|
||||
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');
|
||||
chat.map().val(function(msg, field){
|
||||
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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@std/esm": "^0.8.3",
|
||||
"aws-sdk": ">=2.41.0",
|
||||
"formidable": ">=1.1.1",
|
||||
"ws": "~>2.2.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"express": ">=4.15.2",
|
||||
"subtle": "^0.1.8",
|
||||
"text-encoding": "^0.6.4",
|
||||
"buffer": "^5.0.7",
|
||||
"eccrypto": "^1.0.3",
|
||||
"express": ">=4.15.2",
|
||||
"hapi": "^16.1.1",
|
||||
"inert": "^4.2.0",
|
||||
"ip": "^1.1.5",
|
||||
"mocha": ">=3.2.0",
|
||||
"node-localstorage": "^1.3.0",
|
||||
"panic-manager": "^1.2.0",
|
||||
"panic-server": "^1.1.0",
|
||||
"subtle": "^0.1.8",
|
||||
"text-encoding": "^0.6.4",
|
||||
"uglify-js": ">=2.8.22",
|
||||
"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.
|
||||
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
|
||||
each.user(val, key, node, soul, tmp);
|
||||
}
|
||||
@ -716,7 +716,10 @@
|
||||
each.own = function(val, key, node, soul, tmp){
|
||||
check['own'+soul+key] = 1;
|
||||
SEA.read(val, tmp, function(data){
|
||||
var u;
|
||||
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!"});
|
||||
});
|
||||
}
|
||||
@ -807,7 +810,7 @@
|
||||
SEA.verify = function(m, p, s, cb){
|
||||
var doIt = function(resolve, reject){
|
||||
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) })
|
||||
};
|
||||
if(cb){doIt(cb, function(){cb()})} else { return new Promise(doIt) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user