Skip to content

Commit

Permalink
nip05: use nostr-tools to convert npub to hex #2692
Browse files Browse the repository at this point in the history
  • Loading branch information
K committed Aug 9, 2024
1 parent 42301ce commit 2656ba8
Showing 1 changed file with 18 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);

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

0 comments on commit 2656ba8

Please sign in to comment.