Skip to content

Commit 145aad8

Browse files
committed
service runner snapshot
1 parent b90a247 commit 145aad8

4 files changed

Lines changed: 60 additions & 17 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const Joi = require('@hapi/joi')
2+
const Hoek = require('@hapi/hoek')
3+
const {Message, Routines} = require('@dataparty/crypto')
4+
const debug = require('debug')('roshub.middleware.pre.decrypt')
5+
6+
const IMiddleware = require('../../imiddleware')
7+
8+
module.exports = class Decrypt extends IMiddleware {
9+
10+
static get Name(){
11+
return 'decrypt'
12+
}
13+
14+
static get Type(){
15+
return 'pre'
16+
}
17+
18+
static get Description(){
19+
return 'Decrypt inbound data'
20+
}
21+
22+
static get ConfigSchema(){
23+
return Joi.boolean()
24+
}
25+
26+
static async run(ctx, static_ctx){
27+
28+
if (!Hoek.reach(ctx, 'endpoint.MiddlewareConfig.pre.decrypt', false)){
29+
return
30+
}
31+
32+
33+
const msg = new Message(ctx.input)
34+
const jsonContent = await msg.decrpyt(this.serviceParty.privateIdentity)
35+
const publicKeys = Routines.extractPublicKeys(msg.enc)
36+
37+
ctx.setInputSession(jsonContent.session)
38+
39+
return {
40+
input: Hoek.reach(content, 'data'),
41+
sender: {
42+
type: 'ecdsa',
43+
public: publicKeys
44+
}
45+
}
46+
}
47+
}

src/service/middleware/pre/decrypt.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ module.exports = class Decrypt extends IMiddleware {
1111
return 'decrypt'
1212
}
1313

14-
static get Type(){
15-
return 'pre'
16-
}
17-
1814
static get Description(){
1915
return 'Decrypt inbound data'
2016
}
2117

22-
static get ConfigSchema(){
23-
return Joi.boolean()
18+
static get MiddlewareConfig(){
19+
throw new Error('not implemented')
20+
}
21+
22+
static async start(party){
23+
2424
}
2525

26-
static async run(ctx, static_ctx){
26+
static async run(context){
2727

2828
if (!Hoek.reach(ctx, 'endpoint.MiddlewareConfig.pre.decrypt', false)){
2929
return

test/test-service-compile.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ const Path = require('path')
22
const debug = require('debug')('test.service-compile')
33
const Dataparty = require('../src')
44

5-
//const {VM, NodeVM, VMScript} = require('vm2')
6-
75
process.on('uncaughtException', (err) => {
86
console.error('Asynchronous error caught.', err);
97
})
@@ -26,8 +24,6 @@ async function main(){
2624

2725
const build = await service.compile(Path.join(__dirname,'../dataparty'), false)
2826

29-
//debug(build.middleware.pre.decrypt)
30-
3127
let decryptInfo = new Dataparty.MiddlewareInfoSandbox(build.middleware.pre.decrypt.code)
3228

3329
try{

test/test-service-host.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ const Path = require('path')
22
const debug = require('debug')('test.server-db')
33
const Dataparty = require('../src')
44

5-
/*class ExampleService extends Dataparty.IService {
6-
constructor(opts){
7-
super(opts)
5+
class ExampleService extends Dataparty.IService {
6+
constructor(opts){
7+
super(opts)
88

9-
this.addMiddleware(Dataparty.middleware_paths.pre.decrypt)
10-
}
9+
this.addMiddleware(Dataparty.middleware_paths.pre.decrypt)
10+
}
1111

12-
}*/
12+
}
1313

1414
async function main(){
1515

0 commit comments

Comments
 (0)