File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ const Path = require('path')
22const debug = require ( 'debug' ) ( 'test.service-compile' )
33const Dataparty = require ( '../src' )
44
5- //const {VM, NodeVM, VMScript} = require('vm2')
6-
75process . 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 {
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ const Path = require('path')
22const debug = require ( 'debug' ) ( 'test.server-db' )
33const 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
1414async function main ( ) {
1515
You can’t perform that action at this time.
0 commit comments