Skip to content

Commit

Permalink
Merge pull request #2695 from Trustroots/add-nostr-package
Browse files Browse the repository at this point in the history
nip05: nostr-tools
  • Loading branch information
guaka committed Aug 9, 2024
2 parents 2e67bd0 + 2656ba8 commit d53eddc
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 14 deletions.
32 changes: 18 additions & 14 deletions modules/core/server/routes/core.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const _ = require('lodash');
const core = require('../controllers/core.server.controller');
const tribes = require('../../../tribes/server/controllers/tribes.server.controller');
const nip19 = require('nostr-tools/nip19');

module.exports = function (app) {
const redirect = function (src, dst) {
Expand Down Expand Up @@ -54,33 +55,36 @@ module.exports = function (app) {
// Object is passed to layout at `core.renderIndex()`
app.route('/circles/:tribe').get(core.renderIndex);

app.route('/.well-known/nostr.json').get(function(req, res) {
app.route('/.well-known/nostr.json').get(function (req, res) {
// NIP05 work in progress, https://github.com/Trustroots/trustroots/issues/2692
const mongoose = require('mongoose');
const User = mongoose.model('User');

const name = req.query.name;
User.findOne({ username: name }, function(err, user) {

User.findOne({ username: name }, function (err, user) {
if (err) {
res.status(500).send({ error: 'Internal server error' });
} else if (!user) {
res.status(404).send({ error: 'User not found' });
} else {
const nostrNpub = user.nostrNpub || 'User does not have a Nostr public key';
// const npubs = {
// "nostroots": "7e7e9c42a91bfef19fa929e5fda1b72e0ebc1a4c1141673e2794234d86addf4e",
// "thefriendlyhost": "84d17317d46629037291f93df470c28082a874305e41c9465970659e9254edab"
// };
const nostrNpub = user.nostrNpub;

if (nostrNpub) {
var result = nip19.decode(nostrNpub);
var hex = result.data;
} else {
// what should we return if there's no npub?
var hex = 'no npub';
}

res.json({
"names": {
[name]: nostrNpub // TODO convert npub to hex
}
names: {
[name]: hex,
},
});

}
});

});

// Define application route
Expand Down
198 changes: 198 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"natural": "5.2.3",
"ng-file-upload": "12.2.13",
"nodemailer": "6.7.8",
"nostr-tools": "2.7.2",
"nunjucks": "3.2.3",
"passport": "0.5.0",
"passport-facebook": "3.0.0",
Expand Down

0 comments on commit d53eddc

Please sign in to comment.