Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nip05: nostr-tools #2695

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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);

Check failure on line 74 in modules/core/server/routes/core.server.routes.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

modules/core/server/routes/core.server.routes.js#L74

[no-var] Unexpected var, use let or const instead.
var hex = result.data;

Check failure on line 75 in modules/core/server/routes/core.server.routes.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

modules/core/server/routes/core.server.routes.js#L75

[no-var] Unexpected var, use let or const instead.
} else {
// what should we return if there's no npub?
var hex = 'no npub';

Check failure on line 78 in modules/core/server/routes/core.server.routes.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

modules/core/server/routes/core.server.routes.js#L78

[no-var] Unexpected var, use let or const instead.

Check failure on line 78 in modules/core/server/routes/core.server.routes.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

modules/core/server/routes/core.server.routes.js#L78

[no-redeclare] 'hex' is already defined.
}

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
Loading