From 31a72bd500a68339fa1b574acaadd8940add7756 Mon Sep 17 00:00:00 2001 From: DanielMowitz Date: Fri, 6 Sep 2019 12:25:50 +0200 Subject: [PATCH 1/6] Worked a bit on Webfinger detection, does not work yet. --- config.json | 4 ++ index.js | 18 ++++++ package.json | 7 ++- bridge.js => save_to_ssb.js | 20 +++--- server.js | 122 ++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 14 deletions(-) create mode 100644 config.json create mode 100644 index.js rename bridge.js => save_to_ssb.js (97%) create mode 100644 server.js diff --git a/config.json b/config.json new file mode 100644 index 0000000..7ade5ab --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "DOMAIN" : "767b16bb.ngrok.io", + "PORT" : 3000 +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..6bb4498 --- /dev/null +++ b/index.js @@ -0,0 +1,18 @@ +const config = require('./config'); +const server = require('./server'); +const express = require('express'); +const app = express(); +const http = require('http'); + +app.set('domain', config.DOMAIN); +app.set('port', process.env.PORT || config.PORT || 3000); +app.set('port-https', process.env.PORT_HTTPS || 8443); + +app.get('/', (req, res) => res.send('Hello World!')); +app.get('/u/:name', server.get_user); +app.get('/.well-known/webfinger', server.get_webfinger); +app.get('/inbox', (req, res) => res.send('Here lies the inbox')); + +http.createServer(app).listen(app.get('port'), function(){ + console.log('Express server listening on port ' + app.get('port')); +}); diff --git a/package.json b/package.json index d06f622..177504a 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,12 @@ "name": "scuttlebutt_to_ap", "version": "1.0.0", "dependencies": { - "ssb-client": "latest", + "express": "latest", + "node-fetch": "latest", "pull-stream": "latest", + "ssb-client": "latest", + "ssb-friends": "latest", "stream-to-pull-stream": "latest", - "node-fetch": "latest" + "http": "latest" } } diff --git a/bridge.js b/save_to_ssb.js similarity index 97% rename from bridge.js rename to save_to_ssb.js index a917f77..271da1a 100644 --- a/bridge.js +++ b/save_to_ssb.js @@ -89,7 +89,7 @@ async function get_last_by_activity_id(id) { */ let last = null; - + let out = new Promise((resolve, reject) => { ssbClient((err, sbot) => { pull( @@ -157,13 +157,13 @@ function add_ssb_message(type, id, actor, summary, object, origin = null, target let actor_id = actor.id; delete actor.id; let actor_promise = createBlobObject(actor_type, actor_id, actor); - + let object_type = object.type; delete object.type; let object_id = object.id; delete object.id; let object_promise = createBlobObject(object_type, object_id, object); - + Promise.all([actor_promise, object_promise]).then(([actor_blob, object_blob]) => { ssbClient((err, sbot) => { if (err) throw err; @@ -196,7 +196,7 @@ function add_ssb_message(type, id, actor, summary, object, origin = null, target sbot.close(); }); }) - + } async function get_json_from_blob(blob_id){ @@ -266,9 +266,9 @@ async function restore_ssb_message(id){ return await out; } -exports.bridge = { +module.exports = { save : (message) => { - if (message.@context === "https://www.w3.org/ns/activitystreams") { + if (message["@context"] === "https://www.w3.org/ns/activitystreams") { //todo: should be @context add_ssb_message( message.type, @@ -284,9 +284,5 @@ exports.bridge = { throw ("Invalid message context."); } }, - restore: (id) => { - let p = restore_ssb_message(id); - - return p; - } -}; + restore: restore_ssb_message +}; \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..085d45f --- /dev/null +++ b/server.js @@ -0,0 +1,122 @@ +const config = require('./config'); +const ssbClient = require('ssb-client'); +const pull = require('pull-stream'); + +DOMAIN = config.DOMAIN; + +async function check_if_in_friends(name){ + let result = false; + let out = new Promise((resolve, reject) => { + ssbClient((err, sbot) => { + if (err) reject(err); + + pull( + sbot.friends.createFriendStream(), + pull.collect((err, array) => { + array.forEach(function (actor) { + let short_actor = (actor.substr(1)); + if (short_actor === name) { + result = true; + } + }); + sbot.close(); + resolve(result); + }) + ); + }); + }); + return await out; +} + +function get_webfinger(req, res) { + let resource = req.query.resource; + if (!resource || !resource.includes('acct:')) { + return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.'); + } + else { + let name = resource.replace('acct:',''); + name = name.substr(0,name.indexOf('@')); + + // This might help with webfinger detection + // let encoded_name = encodeURIComponent(name); + + let p = check_if_in_friends(name); + + p.then((result) => { + if (result) { + res.json( + { + 'subject': `acct:${name}@${DOMAIN}`, + links: [ + { + rel: 'self', + type: 'application/activitypub+json', + href: `https://${DOMAIN}/u/${name}` + } + ], + } + ); + } else { + return res.status(404).send(`No record found for ${name}.`); + } + }).catch((err) => { + return res.status(500).send(`An error occured: ${err}.`); + }) + } +} + +function get_user(req, res){ + let name = req.params.name; + if (!name) { + return res.status(400).send('Bad request.'); + } + else { + + // This might help with webfinger detection + // let encoded_name = encodeURIComponent(name); + + let p = check_if_in_friends(name); + + p.then((result) => { + if (result) { + + res.json( + { + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1' + ], + + id: `https://${DOMAIN}/u/${name}`, + type: 'Person', + preferredUsername: 'TESTPERSON PLS CHANGE', //todo: read from latest about message + inbox: `https://${DOMAIN}/u/${name}/inbox`, + + publicKey: { + id: `https://${DOMAIN}/u/${name}#main-key`, + owner: `https://${DOMAIN}/u/${name}`, + publicKeyPem: '-----BEGIN PUBLIC KEY-----\n' + + 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsT4MEtffaV0uFr9jgSnx\n' + + 'kb1+MMd1/jGYBugJ4jkHc9rvQRJLA2C8O2LbrdNb/00TRHh0pkR7AJW7DWMhIF/P\n' + + 'WmsHcdouAUhovAVO+4yrRK5fMA96JP6k2YwqJK+yjK4SMm9iwvcdBlrkZif0KWvA\n' + + 'Qf4eU24n64NSEdVu48cgZwMvQeYKaAtf2LIhXYOE4pA16C05z3BAar+9m2e1yZMG\n' + + '+JzhoywmpqlrB+XK55wjAIhvwVGgOMtUg5FbHU5sH7wZv7H945t40x7HjNCBxU6d\n' + + 'yrF7Bl6nMg+ifT5a6SzPSJ0f3g99AyfMVL5fnhSodjpsnjohfIsx9Vzd4oO1JhDx\n' + + 'SwIDAQAB\n' + + '-----END PUBLIC KEY-----' + } + } + ); + }else { + return res.status(404).send(`No record found for ${name}.`); + } + }).catch((err) => { + return res.status(500).send(`An error occured: ${err}.`); + }) + } +} + +module.exports = { + get_user, + get_webfinger +}; \ No newline at end of file From c8ddf04cddbe0ea9429efe07bc2f57cb0d9cf0b2 Mon Sep 17 00:00:00 2001 From: DanielMowitz <53856770+DanielMowitz@users.noreply.github.com> Date: Fri, 6 Sep 2019 12:30:29 +0200 Subject: [PATCH 2/6] Update config.json Removed ngrok domain used for testing --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 7ade5ab..dd32768 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { - "DOMAIN" : "767b16bb.ngrok.io", + "DOMAIN" : "", "PORT" : 3000 -} \ No newline at end of file +} From 01cc0c057331fd026118fd65b8aa46844415da04 Mon Sep 17 00:00:00 2001 From: DanielMowitz Date: Mon, 9 Sep 2019 16:56:34 +0200 Subject: [PATCH 3/6] Changed the literal typo that stopped webfinger detection :/ --- server.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index 085d45f..183cd7e 100644 --- a/server.js +++ b/server.js @@ -37,10 +37,7 @@ function get_webfinger(req, res) { let name = resource.replace('acct:',''); name = name.substr(0,name.indexOf('@')); - // This might help with webfinger detection - // let encoded_name = encodeURIComponent(name); - - let p = check_if_in_friends(name); + let p = check_if_in_friends(name + "=.ed25519"); p.then((result) => { if (result) { @@ -50,7 +47,7 @@ function get_webfinger(req, res) { links: [ { rel: 'self', - type: 'application/activitypub+json', + type: 'application/activity+json', href: `https://${DOMAIN}/u/${name}` } ], @@ -72,10 +69,7 @@ function get_user(req, res){ } else { - // This might help with webfinger detection - // let encoded_name = encodeURIComponent(name); - - let p = check_if_in_friends(name); + let p = check_if_in_friends(name + "=.ed25519"); p.then((result) => { if (result) { From ea8cbb43c3879bcc2ea0ea95c53b33117b08b5bd Mon Sep 17 00:00:00 2001 From: DanielMowitz Date: Tue, 24 Sep 2019 15:08:03 +0200 Subject: [PATCH 4/6] Webfinger detection now works and incoming Activities are saved to the ssb log. --- config.json | 6 ++-- index.js | 13 ++++++- package.json | 3 +- save_to_ssb.js | 38 ++++++++++---------- server.js | 96 ++++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 117 insertions(+), 39 deletions(-) diff --git a/config.json b/config.json index dd32768..e480b76 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { - "DOMAIN" : "", - "PORT" : 3000 -} + "DOMAIN": "", + "PORT": 3000 +} \ No newline at end of file diff --git a/index.js b/index.js index 6bb4498..5386512 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,16 @@ const config = require('./config'); const server = require('./server'); const express = require('express'); const app = express(); +const bodyParser = require('body-parser'); const http = require('http'); +var options = { //todo: maybe be more specific here + type: "application/*" +}; + +app.use(bodyParser.raw(options)); +app.use(bodyParser.urlencoded({extended: true})); + app.set('domain', config.DOMAIN); app.set('port', process.env.PORT || config.PORT || 3000); app.set('port-https', process.env.PORT_HTTPS || 8443); @@ -12,7 +20,10 @@ app.get('/', (req, res) => res.send('Hello World!')); app.get('/u/:name', server.get_user); app.get('/.well-known/webfinger', server.get_webfinger); app.get('/inbox', (req, res) => res.send('Here lies the inbox')); +app.get('/users', server.get_users); -http.createServer(app).listen(app.get('port'), function(){ +app.post('/inbox', server.post_inbox); + +http.createServer(app).listen(app.get('port'), function () { console.log('Express server listening on port ' + app.get('port')); }); diff --git a/package.json b/package.json index 177504a..601e755 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,12 @@ "version": "1.0.0", "dependencies": { "express": "latest", + "http": "latest", "node-fetch": "latest", "pull-stream": "latest", "ssb-client": "latest", "ssb-friends": "latest", "stream-to-pull-stream": "latest", - "http": "latest" + "body-parser": "latest" } } diff --git a/save_to_ssb.js b/save_to_ssb.js index 271da1a..724df32 100644 --- a/save_to_ssb.js +++ b/save_to_ssb.js @@ -3,16 +3,16 @@ const pull = require('pull-stream'); const allowed_message_types = [ //valid activitypub message types 'create', - 'update', - 'delete', - 'follow', - 'update', - 'reject', - 'add', - 'remove', - 'like', - 'announce', - 'undo' + 'update', + 'delete', + 'follow', + 'update', + 'reject', + 'add', + 'remove', + 'like', + 'announce', + 'undo' ]; async function createBlobObject(type, objectId, otherData) { @@ -99,16 +99,16 @@ async function get_last_by_activity_id(id) { if (err) reject(err); for (let i in array) { if (array[i].value.content.type.length > 3 && - array[i].value.content.type.substr(0,3) === 'ap-' && + array[i].value.content.type.substr(0, 3) === 'ap-' && allowed_message_types.indexOf(array[i].value.content.type.substr(3)) >= 0) { if (array[i].value.content.id === id) { last = array[i]; } } } - if (last){ + if (last) { resolve(last); - }else { + } else { reject('no activity found'); } @@ -199,7 +199,7 @@ function add_ssb_message(type, id, actor, summary, object, origin = null, target } -async function get_json_from_blob(blob_id){ +async function get_json_from_blob(blob_id) { /* * Gets the Object with the specified id from the @@ -225,7 +225,7 @@ async function get_json_from_blob(blob_id){ return await out; } -async function restore_ssb_message(id){ +async function restore_ssb_message(id) { /* * Gets the Message with the specified id from the @@ -246,12 +246,12 @@ async function restore_ssb_message(id){ msg.type = msg.type.substr(3); delete msg.actor.otherData; - for (let key in actor_data){ + for (let key in actor_data) { msg.actor[key] = actor_data[key]; } delete msg.object.otherData; - for (let key in object_data){ + for (let key in object_data) { msg.object[key] = object_data[key]; } @@ -267,8 +267,8 @@ async function restore_ssb_message(id){ } module.exports = { - save : (message) => { - if (message["@context"] === "https://www.w3.org/ns/activitystreams") { //todo: should be @context + save: (message) => { + if (message["@context"] === "https://www.w3.org/ns/activitystreams") { add_ssb_message( message.type, diff --git a/server.js b/server.js index 183cd7e..763aea3 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,29 @@ const config = require('./config'); const ssbClient = require('ssb-client'); const pull = require('pull-stream'); +const ssb_bridge = require('./save_to_ssb'); DOMAIN = config.DOMAIN; -async function check_if_in_friends(name){ +let chars_to_encode = "_!*'();:@&=+$,/?#[]"; // basically anything covered by %-encoding plus underscore + +function encode_webfinger_name(name) { + for (let i in chars_to_encode) { + name = name.replace(chars_to_encode[i], "_" + chars_to_encode[i].charCodeAt(0).toString(16) + "_"); + } + return name; +} + +function decode_webfinger_name(name) { + for (let i in chars_to_encode) { + name = name.replace("_" + chars_to_encode[i].charCodeAt(0).toString(16) + "_", chars_to_encode[i]); + } + return name +} + +async function check_if_in_friends(name) { let result = false; + name = decode_webfinger_name(name); let out = new Promise((resolve, reject) => { ssbClient((err, sbot) => { if (err) reject(err); @@ -28,14 +46,31 @@ async function check_if_in_friends(name){ return await out; } +async function get_friends() { + let out = new Promise((resolve, reject) => { + ssbClient((err, sbot) => { + if (err) reject(err); + + pull( + sbot.friends.createFriendStream(), + pull.collect((err, array) => { + sbot.close(); + resolve(array); + }) + ); + }); + }); + return await out; +} + function get_webfinger(req, res) { let resource = req.query.resource; if (!resource || !resource.includes('acct:')) { return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.'); - } - else { - let name = resource.replace('acct:',''); - name = name.substr(0,name.indexOf('@')); + } else { + let name = resource.replace('acct:', ''); + name = name.substr(0, name.indexOf('@')); + let encoded_name = encodeURIComponent(name); let p = check_if_in_friends(name + "=.ed25519"); @@ -43,18 +78,18 @@ function get_webfinger(req, res) { if (result) { res.json( { - 'subject': `acct:${name}@${DOMAIN}`, + 'subject': `acct:${encoded_name}@${DOMAIN}`, links: [ { rel: 'self', type: 'application/activity+json', - href: `https://${DOMAIN}/u/${name}` + href: `https://${DOMAIN}/u/${encoded_name}` } ], } ); } else { - return res.status(404).send(`No record found for ${name}.`); + return res.status(404).send(`No record found for ${encoded_name}.`); } }).catch((err) => { return res.status(500).send(`An error occured: ${err}.`); @@ -62,12 +97,11 @@ function get_webfinger(req, res) { } } -function get_user(req, res){ +function get_user(req, res) { let name = req.params.name; if (!name) { return res.status(400).send('Bad request.'); - } - else { + } else { let p = check_if_in_friends(name + "=.ed25519"); @@ -83,8 +117,9 @@ function get_user(req, res){ id: `https://${DOMAIN}/u/${name}`, type: 'Person', - preferredUsername: 'TESTPERSON PLS CHANGE', //todo: read from latest about message - inbox: `https://${DOMAIN}/u/${name}/inbox`, + preferredUsername: 'TESTPERSON', //todo: read from latest about message + // inbox: `https://${DOMAIN}/u/${name}/inbox`, + inbox: `https://${DOMAIN}/inbox`, publicKey: { id: `https://${DOMAIN}/u/${name}#main-key`, @@ -101,7 +136,7 @@ function get_user(req, res){ } } ); - }else { + } else { return res.status(404).send(`No record found for ${name}.`); } }).catch((err) => { @@ -110,7 +145,38 @@ function get_user(req, res){ } } +function get_users(req, res) { + let p = get_friends(); + + p.then((result) => { + if (result) { + let out = {}; + for (let i in result) { + out[i] = encode_webfinger_name(result[i].substr(1).replace("=.ed25519", "")); + } + res.json(out); + } else { + return res.status(404).send(`No record found for ${name}.`); + } + }).catch((err) => { + return res.status(500).send(`An error occured: ${err}.`); + }) +} + +function post_inbox(req, res) { + console.log("Saved activity to ssb log."); + try { + let in_activity = JSON.parse(req.body.toString()); + ssb_bridge.save(in_activity); + } catch (e) { + + } + return res.status(200).send('ayy\n'); +} + module.exports = { get_user, - get_webfinger + get_webfinger, + get_users, + post_inbox, }; \ No newline at end of file From 028683f9635e98188e337428ed1b1f6d55132aa4 Mon Sep 17 00:00:00 2001 From: DanielMowitz Date: Fri, 27 Sep 2019 15:49:31 +0200 Subject: [PATCH 5/6] Edited readme, moved some files and worked a bit on display names. --- README.md | 14 ++++++ server.js | 77 ++++++++++--------------------- save_to_ssb.js => ssb_bridge.js | 80 ++++++++++++++++++++++++++++++++- 3 files changed, 116 insertions(+), 55 deletions(-) rename save_to_ssb.js => ssb_bridge.js (77%) diff --git a/README.md b/README.md index eebedad..ed1a1df 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ # ssb_ap_bridge A Javscript module to implement ActivityPub compatibility to [ssb](https://github.com/ssbc/ssb-db) + +Feel free to open a PR or issue! + +## What currently works: + +- Webfinger detection of known ssb users +- logging AP messages in ssb + +## What still needs work: + +- Converting messages between the services +- encryption of converted messages + + diff --git a/server.js b/server.js index 763aea3..5a66c12 100644 --- a/server.js +++ b/server.js @@ -1,66 +1,23 @@ const config = require('./config'); -const ssbClient = require('ssb-client'); -const pull = require('pull-stream'); -const ssb_bridge = require('./save_to_ssb'); +const ssb_bridge = require('./ssb_bridge'); DOMAIN = config.DOMAIN; let chars_to_encode = "_!*'();:@&=+$,/?#[]"; // basically anything covered by %-encoding plus underscore -function encode_webfinger_name(name) { - for (let i in chars_to_encode) { - name = name.replace(chars_to_encode[i], "_" + chars_to_encode[i].charCodeAt(0).toString(16) + "_"); - } - return name; -} - function decode_webfinger_name(name) { + name = name + "=.ed25519"; for (let i in chars_to_encode) { name = name.replace("_" + chars_to_encode[i].charCodeAt(0).toString(16) + "_", chars_to_encode[i]); } return name } -async function check_if_in_friends(name) { - let result = false; - name = decode_webfinger_name(name); - let out = new Promise((resolve, reject) => { - ssbClient((err, sbot) => { - if (err) reject(err); - - pull( - sbot.friends.createFriendStream(), - pull.collect((err, array) => { - array.forEach(function (actor) { - let short_actor = (actor.substr(1)); - if (short_actor === name) { - result = true; - } - }); - sbot.close(); - resolve(result); - }) - ); - }); - }); - return await out; -} - -async function get_friends() { - let out = new Promise((resolve, reject) => { - ssbClient((err, sbot) => { - if (err) reject(err); - - pull( - sbot.friends.createFriendStream(), - pull.collect((err, array) => { - sbot.close(); - resolve(array); - }) - ); - }); - }); - return await out; +function encode_webfinger_name(name) { + for (let i in chars_to_encode) { + name = name.replace(chars_to_encode[i], "_" + chars_to_encode[i].charCodeAt(0).toString(16) + "_"); + } + return name; } function get_webfinger(req, res) { @@ -72,7 +29,7 @@ function get_webfinger(req, res) { name = name.substr(0, name.indexOf('@')); let encoded_name = encodeURIComponent(name); - let p = check_if_in_friends(name + "=.ed25519"); + let p = ssb_bridge.check_if_in_friends(decode_webfinger_name(name)); p.then((result) => { if (result) { @@ -103,11 +60,22 @@ function get_user(req, res) { return res.status(400).send('Bad request.'); } else { - let p = check_if_in_friends(name + "=.ed25519"); + let p = ssb_bridge.check_if_in_friends(decode_webfinger_name(name)); p.then((result) => { if (result) { + let uname_p = ssb_bridge.get_username(decode_webfinger_name(name)); + let uname = ''; + + uname_p.then((uname_res) => { + uname = uname_res; + }); + + if (uname === '') { + uname = name; + } + res.json( { '@context': [ @@ -117,7 +85,8 @@ function get_user(req, res) { id: `https://${DOMAIN}/u/${name}`, type: 'Person', - preferredUsername: 'TESTPERSON', //todo: read from latest about message + preferredUsername: uname, //todo: read from latest about message + name: uname, // inbox: `https://${DOMAIN}/u/${name}/inbox`, inbox: `https://${DOMAIN}/inbox`, @@ -146,7 +115,7 @@ function get_user(req, res) { } function get_users(req, res) { - let p = get_friends(); + let p = ssb_bridge.get_friends(); p.then((result) => { if (result) { diff --git a/save_to_ssb.js b/ssb_bridge.js similarity index 77% rename from save_to_ssb.js rename to ssb_bridge.js index 724df32..e1d11a8 100644 --- a/save_to_ssb.js +++ b/ssb_bridge.js @@ -266,6 +266,81 @@ async function restore_ssb_message(id) { return await out; } +async function check_if_in_friends(name) { + let result = false; + let out = new Promise((resolve, reject) => { + ssbClient((err, sbot) => { + if (err) reject(err); + + pull( + sbot.friends.createFriendStream(), + pull.collect((err, array) => { + array.forEach(function (actor) { + let short_actor = (actor.substr(1)); + if (short_actor === name) { + result = true; + } + }); + sbot.close(); + resolve(result); + }) + ); + }); + }); + return await out; +} + +async function get_friends() { + let out = new Promise((resolve, reject) => { + ssbClient((err, sbot) => { + if (err) reject(err); + + pull( + sbot.friends.createFriendStream(), + pull.collect((err, array) => { + sbot.close(); + resolve(array); + }) + ); + }); + }); + return await out; +} + +async function get_username(name) { + + let last = null; + + let out = new Promise((resolve, reject) => { + ssbClient((err, sbot) => { + pull( + sbot.createLogStream(), + pull.collect(function (err, array) { + sbot.close(); + if (err) reject(err); + console.log(array); + console.log(name); + for (let i in array) { + if (array[i].value.content.type === 'about' && + array[i].value.author.substr(1) === name && + array[i].value.content.hasOwnProperty('name')) { + last = array[i].value.content.name; + } + } + if (last) { + resolve(last); + } else { + resolve(''); + } + + }), + ); + }); + }); + + return await out; +} + module.exports = { save: (message) => { if (message["@context"] === "https://www.w3.org/ns/activitystreams") { @@ -284,5 +359,8 @@ module.exports = { throw ("Invalid message context."); } }, - restore: restore_ssb_message + restore: restore_ssb_message, + check_if_in_friends, + get_friends, + get_username }; \ No newline at end of file From f9730b002a125d264fc1e450ed11edba5534e401 Mon Sep 17 00:00:00 2001 From: DanielMowitz <53856770+DanielMowitz@users.noreply.github.com> Date: Fri, 27 Sep 2019 15:52:25 +0200 Subject: [PATCH 6/6] Update server.js removed old todo --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 5a66c12..d7b311e 100644 --- a/server.js +++ b/server.js @@ -85,7 +85,7 @@ function get_user(req, res) { id: `https://${DOMAIN}/u/${name}`, type: 'Person', - preferredUsername: uname, //todo: read from latest about message + preferredUsername: uname, name: uname, // inbox: `https://${DOMAIN}/u/${name}/inbox`, inbox: `https://${DOMAIN}/inbox`, @@ -148,4 +148,4 @@ module.exports = { get_webfinger, get_users, post_inbox, -}; \ No newline at end of file +};