ssb-invite
Advanced tools
Comparing version 2.1.7 to 2.1.8
67
index.js
'use strict' | ||
var valid = require('muxrpc-validation')({}) | ||
var crypto = require('crypto') | ||
var ssbKeys = require('ssb-keys') | ||
var cont = require('cont') | ||
var explain = require('explain-error') | ||
var ip = require('ip') | ||
var ref = require('ssb-ref') | ||
var level = require('level') | ||
var path = require('path') | ||
const valid = require('muxrpc-validation')({}) | ||
const crypto = require('crypto') | ||
const ssbKeys = require('ssb-keys') | ||
const cont = require('cont') | ||
const explain = require('explain-error') | ||
const ip = require('ip') | ||
const ref = require('ssb-ref') | ||
const level = require('level') | ||
const path = require('path') | ||
var createClient = require('ssb-client/client') | ||
const createClient = require('ssb-client/client') | ||
function logErrorCb (err) { | ||
if (err) console.log(err) | ||
} | ||
// invite plugin | ||
@@ -53,3 +57,4 @@ // adds methods for producing invite-codes, | ||
server.auth.hook((fn, args) => { | ||
var pubkey = args[0]; var cb = args[1] | ||
const pubkey = args[0] | ||
const cb = args[1] | ||
@@ -89,3 +94,3 @@ // run normal authentication | ||
var addr = getInviteAddress() | ||
let addr = getInviteAddress() | ||
if (!addr) { | ||
@@ -99,3 +104,3 @@ return cb(new Error( | ||
addr = addr.split(';').shift() | ||
var host = ref.parseAddress(addr).host | ||
let host = ref.parseAddress(addr).host | ||
if (typeof host !== 'string') { | ||
@@ -120,4 +125,4 @@ return cb(new Error('Could not parse host portion from server address:' + addr)) | ||
// generate a key-seed and its key | ||
var seed = crypto.randomBytes(32) | ||
var keyCap = ssbKeys.generate('ed25519', seed) | ||
const seed = crypto.randomBytes(32) | ||
const keyCap = ssbKeys.generate('ed25519', seed) | ||
@@ -135,3 +140,3 @@ // store metadata under the generated pubkey | ||
else if (opts.modern) { | ||
var wsAddr = getInviteAddress().split(';').sort(function (a, b) { | ||
const wsAddr = getInviteAddress().split(';').sort(function (a, b) { | ||
return +/^ws/.test(b) - +/^ws/.test(a) | ||
@@ -149,3 +154,3 @@ }).shift() | ||
use: valid.async(function (req, cb) { | ||
var rpc = this | ||
const rpc = this | ||
@@ -161,9 +166,15 @@ // fetch the code | ||
// if(hops[req.feed] == 1) | ||
if (follows && follows[server.id] && follows[server.id][req.feed]) { return cb(new Error('already following')) } | ||
if (follows && follows[server.id] && follows[server.id][req.feed]) { | ||
return cb(new Error('already following')) | ||
} | ||
// although we already know the current feed | ||
// it's included so that request cannot be replayed. | ||
if (!req.feed) { return cb(new Error('feed to follow is missing')) } | ||
if (!req.feed) { | ||
return cb(new Error('feed to follow is missing')) | ||
} | ||
if (invite.used >= invite.total) { return cb(new Error('invite has expired')) } | ||
if (invite.used >= invite.total) { | ||
return cb(new Error('invite has expired')) | ||
} | ||
@@ -205,3 +216,3 @@ invite.used++ | ||
if (invite.charAt(0) === '"' && invite.charAt(invite.length - 1) === '"') { invite = invite.slice(1, -1) } | ||
var opts | ||
let opts | ||
// connect to the address in the invite code | ||
@@ -211,6 +222,6 @@ // using a keypair generated from the key-seed in the invite code | ||
if (ref.isLegacyInvite(invite)) { | ||
var parts = invite.split('~') | ||
const parts = invite.split('~') | ||
opts = ref.parseAddress(parts[0])// .split(':') | ||
// convert legacy code to multiserver invite code. | ||
var protocol = 'net:' | ||
let protocol = 'net:' | ||
if (opts.host.endsWith('.onion')) { protocol = 'onion:' } | ||
@@ -230,3 +241,3 @@ invite = protocol + opts.host + ':' + opts.port + '~shs:' + opts.key.slice(1, -8) + ':' + parts[1] | ||
remote: invite, | ||
config: config, | ||
config, | ||
manifest: { invite: { use: 'async' }, getAddress: 'async' } | ||
@@ -242,5 +253,5 @@ }, cb) | ||
function retry (fn, cb) { | ||
var n = 0 | ||
let n = 0 | ||
;(function next () { | ||
var start = Date.now() | ||
const start = Date.now() | ||
fn(function (err, value) { | ||
@@ -280,4 +291,4 @@ n++ | ||
if (err) return cb(err) | ||
rpc.close() | ||
rpc.close() | ||
rpc.close(logErrorCb) | ||
rpc.close(logErrorCb) | ||
// ignore err if this is new style invite | ||
@@ -284,0 +295,0 @@ if (server.gossip) server.gossip.add(ref.parseInvite(invite).remote, 'seed') |
{ | ||
"name": "ssb-invite", | ||
"description": "", | ||
"version": "2.1.7", | ||
"version": "2.1.8", | ||
"homepage": "https://github.com/ssbc/ssb-invite", | ||
@@ -12,3 +12,3 @@ "repository": { | ||
"test": "npm run test:js && npm run lint", | ||
"test:js": "tape test/*.test.js", | ||
"test:js": "tape test/*.test.js | tap-arc", | ||
"lint": "standard --fix" | ||
@@ -19,3 +19,3 @@ }, | ||
"explain-error": "^1.0.4", | ||
"ip": "^1.1.5", | ||
"ip": "^1.1.8", | ||
"level": "^6.0.1", | ||
@@ -25,12 +25,13 @@ "muxrpc-validation": "^3.0.2", | ||
"ssb-keys": "^7.2.2", | ||
"ssb-ref": "^2.14.0" | ||
"ssb-ref": "^2.16.0" | ||
}, | ||
"devDependencies": { | ||
"pull-stream": "^3.6.14", | ||
"scuttle-testbot": "^1.2.3", | ||
"ssb-friends": "^4.1.4", | ||
"ssb-replicate": "^1.3.2", | ||
"pull-stream": "^3.7.0", | ||
"scuttle-testbot": "^2.2.0", | ||
"ssb-friends": "^4.4.10", | ||
"ssb-replicate": "^1.3.5", | ||
"ssb-ws": "^6.2.3", | ||
"standard": "^14.3.4", | ||
"tape": "^4.13.2" | ||
"standard": "^17.1.0", | ||
"tap-arc": "^1.2.2", | ||
"tape": "^4.17.0" | ||
}, | ||
@@ -37,0 +38,0 @@ "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)", |
// WARNING: this test currently only passes if the computer has a network. | ||
var tape = require('tape') | ||
var pull = require('pull-stream') | ||
var ref = require('ssb-ref') | ||
var crypto = require('crypto') | ||
var Server = require('./test-bot') | ||
const tape = require('tape') | ||
const pull = require('pull-stream') | ||
const ref = require('ssb-ref') | ||
const crypto = require('crypto') | ||
const Server = require('./test-bot') | ||
@@ -18,5 +18,5 @@ if (process.env.TRAVIS === 'true') { | ||
tape('test invite.accept api', function (t) { | ||
var alice = Server({ allowPrivate: true }) | ||
var bob = Server() | ||
var carol = Server() | ||
const alice = Server({ allowPrivate: true }) | ||
const bob = Server() | ||
const carol = Server() | ||
@@ -56,9 +56,9 @@ if (!alice.getAddress('device')) { throw new Error('alice must have device address') } | ||
tape('test invite.accept api using non default app key', function (t) { | ||
var caps = { | ||
const caps = { | ||
shs: crypto.randomBytes(32).toString('base64') | ||
} | ||
var alice = Server({ allowPrivate: true, caps }) | ||
var bob = Server({ caps }) | ||
var carol = Server({ caps }) | ||
const alice = Server({ allowPrivate: true, caps }) | ||
const bob = Server({ caps }) | ||
const carol = Server({ caps }) | ||
@@ -98,4 +98,4 @@ if (!alice.getAddress('device')) { throw new Error('alice must have device address') } | ||
tape('test invite.accept doesnt follow if already followed', function (t) { | ||
var alice = Server({ allowPrivate: true }) | ||
var bob = Server() | ||
const alice = Server({ allowPrivate: true }) | ||
const bob = Server() | ||
@@ -118,3 +118,3 @@ // request a secret that with particular permissions. | ||
// this makes the tests fail unless we get the address the same way as invite code. | ||
var expected = alice.address('public') || alice.address('local') || alice.address('device') | ||
const expected = alice.address('public') || alice.address('local') || alice.address('device') | ||
@@ -159,4 +159,4 @@ t.deepEqual({ | ||
tape('test invite.accept api with ipv6', { skip: skipIPv6 }, function (t) { | ||
var alice = Server({ allowPrivate: true }) | ||
var bob = Server() | ||
const alice = Server({ allowPrivate: true }) | ||
const bob = Server() | ||
@@ -173,5 +173,5 @@ alice.invite.create(1, function (err, invite) { | ||
// console.log(inviteV6, invite) | ||
var parts = invite.split('~') | ||
const parts = invite.split('~') | ||
var addr = ref.parseAddress(parts[0]) | ||
const addr = ref.parseAddress(parts[0]) | ||
@@ -178,0 +178,0 @@ addr.host = '::1' |
// WARNING: this test currently only passes if the computer has a network. | ||
var tape = require('tape') | ||
var ssbKeys = require('ssb-keys') | ||
var ssbClient = require('ssb-client') | ||
var crypto = require('crypto') | ||
var Server = require('./test-bot') | ||
const tape = require('tape') | ||
const ssbKeys = require('ssb-keys') | ||
const ssbClient = require('ssb-client') | ||
const crypto = require('crypto') | ||
const Server = require('./test-bot') | ||
var host = '127.0.0.1' | ||
const host = '127.0.0.1' | ||
// var host = '::' | ||
@@ -13,3 +13,3 @@ // WARNING host '::' currently fails this tests because it creates an invite | ||
var wsConnections = { | ||
const wsConnections = { | ||
incoming: { | ||
@@ -26,8 +26,8 @@ net: [{ scope: ['local', 'device'], transform: 'shs', host }], | ||
tape('test invite.create with modern', function (t) { | ||
var alice = Server({ | ||
const alice = Server({ | ||
allowPrivate: true, | ||
connections: wsConnections | ||
}) | ||
var bob = Server() | ||
var carol = Server() | ||
const bob = Server() | ||
const carol = Server() | ||
console.log({ | ||
@@ -73,7 +73,7 @@ alice: alice.id, | ||
tape('invite guest may NOT call get', function (t) { | ||
var caps = { | ||
const caps = { | ||
shs: crypto.randomBytes(32).toString('base64') | ||
} | ||
var alice = Server({ | ||
const alice = Server({ | ||
allowPrivate: true, | ||
@@ -83,3 +83,3 @@ connections: wsConnections, | ||
}) | ||
var bobKeys = ssbKeys.generate() | ||
const bobKeys = ssbKeys.generate() | ||
@@ -86,0 +86,0 @@ alice.publish({ type: 'test', okay: true }, function (err, msg) { |
// WARNING: this test currently only passes if the computer has a network. | ||
var tape = require('tape') | ||
var pull = require('pull-stream') | ||
var Server = require('./test-bot') | ||
const tape = require('tape') | ||
const pull = require('pull-stream') | ||
const Server = require('./test-bot') | ||
@@ -11,3 +11,3 @@ function all (stream, cb) { | ||
tape('test invite with note', function (t) { | ||
var wsConnections = { | ||
const wsConnections = { | ||
incoming: { | ||
@@ -22,7 +22,7 @@ net: [{ scope: ['local', 'device'], transform: 'shs', host: '::' }], | ||
} | ||
var alice = Server({ | ||
const alice = Server({ | ||
allowPrivate: true, | ||
connections: wsConnections | ||
}) | ||
var bob = Server() | ||
const bob = Server() | ||
@@ -29,0 +29,0 @@ alice.invite.create({ uses: 1, note: 'bob' }, (err, invite) => { |
@@ -1,5 +0,5 @@ | ||
var ssbKeys = require('ssb-keys') | ||
var crypto = require('crypto') | ||
const ssbKeys = require('ssb-keys') | ||
const crypto = require('crypto') | ||
var caps = { shs: crypto.randomBytes(32).toString('base64') } | ||
const caps = { shs: crypto.randomBytes(32).toString('base64') } | ||
@@ -17,3 +17,6 @@ module.exports = function (opts = {}) { | ||
return stack(opts) | ||
return stack({ | ||
db1: true, | ||
...opts | ||
}) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26394
602
8
Updatedip@^1.1.8
Updatedssb-ref@^2.16.0