mirror of
https://github.com/dariusk/express-activitypub.git
synced 2024-11-29 02:10:59 +00:00
Merge pull request #6 from vitalyster/crypot
Drop unnecessary native module
This commit is contained in:
commit
e21a5e0ca1
2 changed files with 23 additions and 15 deletions
|
@ -9,11 +9,10 @@
|
||||||
"cors": "^2.8.4",
|
"cors": "^2.8.4",
|
||||||
"express": "^4.16.3",
|
"express": "^4.16.3",
|
||||||
"express-basic-auth": "^1.1.5",
|
"express-basic-auth": "^1.1.5",
|
||||||
"generate-rsa-keypair": "^0.1.2",
|
|
||||||
"request": "^2.87.0"
|
"request": "^2.87.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.10.0"
|
"node": ">=10.12.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
const express = require('express'),
|
const express = require('express'),
|
||||||
router = express.Router(),
|
router = express.Router(),
|
||||||
crypto = require('crypto'),
|
crypto = require('crypto');
|
||||||
generateRSAKeypair = require('generate-rsa-keypair');
|
|
||||||
|
|
||||||
function createActor(name, domain, pubkey) {
|
function createActor(name, domain, pubkey) {
|
||||||
return {
|
return {
|
||||||
|
@ -48,12 +47,22 @@ router.post('/create', function (req, res) {
|
||||||
let db = req.app.get('db');
|
let db = req.app.get('db');
|
||||||
let domain = req.app.get('domain');
|
let domain = req.app.get('domain');
|
||||||
// create keypair
|
// create keypair
|
||||||
var pair = generateRSAKeypair();
|
crypto.generateKeyPair('rsa', {
|
||||||
let actorRecord = createActor(account, domain, pair.public);
|
modulusLength: 4096,
|
||||||
|
publicKeyEncoding: {
|
||||||
|
type: 'spki',
|
||||||
|
format: 'pem'
|
||||||
|
},
|
||||||
|
privateKeyEncoding: {
|
||||||
|
type: 'pkcs8',
|
||||||
|
format: 'pem'
|
||||||
|
}
|
||||||
|
}, (err, publicKey, privateKey) => {
|
||||||
|
let actorRecord = createActor(account, domain, publicKey);
|
||||||
let webfingerRecord = createWebfinger(account, domain);
|
let webfingerRecord = createWebfinger(account, domain);
|
||||||
const apikey = crypto.randomBytes(16).toString('hex');
|
const apikey = crypto.randomBytes(16).toString('hex');
|
||||||
try {
|
try {
|
||||||
db.prepare('insert or replace into accounts(name, actor, apikey, pubkey, privkey, webfinger) values(?, ?, ?, ?, ?, ?)').run(`${account}@${domain}`, JSON.stringify(actorRecord), apikey, pair.public, pair.private, JSON.stringify(webfingerRecord));
|
db.prepare('insert or replace into accounts(name, actor, apikey, pubkey, privkey, webfinger) values(?, ?, ?, ?, ?, ?)').run(`${account}@${domain}`, JSON.stringify(actorRecord), apikey, publicKey, privateKey, JSON.stringify(webfingerRecord));
|
||||||
res.status(200).json({msg: 'ok', apikey});
|
res.status(200).json({msg: 'ok', apikey});
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
|
|
Loading…
Reference in a new issue