identities ported out
parent
9143bd08b7
commit
27adc68c03
|
|
@ -1,4 +1,5 @@
|
||||||
identities.nedb
|
identities.nedb
|
||||||
node_modules
|
node_modules
|
||||||
*.pem
|
*.pem
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
.DS_Store
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b255382d6242d7ea3877bf059d2934125e0c4d95
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 5a633625615c79f87786d74ea925790ccdd82aba
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit e8577f3654cac97ee18faae28c80a2200aaaad5a
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit e67324fdea7a192c7ce1b4c6b3c3b9f82f11eee7
|
||||||
25
index.js
25
index.js
|
|
@ -1,33 +1,8 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
const api = require('./api');
|
const api = require('./api');
|
||||||
const NodeRSA = require('node-rsa');
|
|
||||||
const rsa = new NodeRSA();
|
|
||||||
const fs = require('fs');
|
|
||||||
const nedb = require('nedb');
|
|
||||||
const identities = new nedb({
|
|
||||||
filename: 'identities.nedb',
|
|
||||||
autoload: true
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use('/api ', api);
|
app.use('/api ', api);
|
||||||
app.listen(6565);
|
app.listen(6565);
|
||||||
|
|
||||||
function createIdentity(name) {
|
|
||||||
const pair = rsa.generateKeyPair()
|
|
||||||
|
|
||||||
identities.insert({
|
|
||||||
name,
|
|
||||||
type: 'public',
|
|
||||||
key: pair.exportKey('pkcs1-public-pem')
|
|
||||||
});
|
|
||||||
identities.insert({
|
|
||||||
name,
|
|
||||||
type: 'private',
|
|
||||||
key: pair.exportKey('pkcs1-private-pem')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
createIdentity
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
const NodeRSA = require('node-rsa');
|
||||||
|
const nedb = require('nedb');
|
||||||
|
const rsa = new NodeRSA();
|
||||||
|
const identities = new nedb({
|
||||||
|
filename: 'identities.nedb',
|
||||||
|
autoload: true
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createIdentity(name) {
|
||||||
|
const pair = rsa.generateKeyPair()
|
||||||
|
|
||||||
|
await new Promise(res => {
|
||||||
|
identities.insert({
|
||||||
|
name,
|
||||||
|
type: 'public',
|
||||||
|
key: pair.exportKey('pkcs1-public-pem')
|
||||||
|
}, res);
|
||||||
|
})
|
||||||
|
await new Promise(res => {
|
||||||
|
identities.insert({
|
||||||
|
name,
|
||||||
|
type: 'private',
|
||||||
|
key: pair.exportKey('pkcs1-private-pem')
|
||||||
|
}, res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getIdentity() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getAllIdentities() {
|
||||||
|
return await new Promise(res => {
|
||||||
|
identities.find({}, (err, docs) => {
|
||||||
|
const names = docs.reduce((acc, obj) => {
|
||||||
|
if(obj._id in acc) return acc;
|
||||||
|
else acc[obj._id] = obj.name;
|
||||||
|
}, {});
|
||||||
|
res(names);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
create: createIdentity,
|
||||||
|
get: Object.assign(getIdentity, {
|
||||||
|
all: getAllIdentities
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue