diff --git a/src/.npmrc b/src/.npmrc deleted file mode 100644 index ffad955..0000000 --- a/src/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -registry=http://95.211.3.251:8081/repository/i3m-npm-proxy -@i3m:registry=http://95.211.3.251:8081/repository/i3m-npm-registry \ No newline at end of file diff --git a/src/openapi/openapi.yaml b/src/openapi/openapi.yaml index f7f6b7a..df4415f 100644 --- a/src/openapi/openapi.yaml +++ b/src/openapi/openapi.yaml @@ -8,10 +8,10 @@ info: version: 1.0.0 servers: - url: / - - url: http://95.211.3.244:3333 - - url: http://95.211.3.249:3333 - - url: http://95.211.3.250:3333 - - url: http://95.211.3.251:3333 + - url: process.env.BACKPLANE_URL0 + - url: process.env.BACKPLANE_URL + - url: process.env.BACKPLANE_URL2 + - url: process.env.BACKPLANE_URL3 variables: {} security: - bearerAuth: [] @@ -251,7 +251,7 @@ paths: /deploy_signed_transaction: post: tags: - - Deploy signed Transaction + - Agreement summary: Deploy signed transaction requestBody: content: @@ -268,26 +268,6 @@ paths: $ref: '#/components/schemas/transaction_object' security: - bearerAuth: [] - /provide_signed_resolution: - post: - tags: - - Conflict Resolutionn - summary: Verify a signed resolution - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/signed_resolution' - required: true - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/transaction_object' - security: - - bearerAuth: [] components: schemas: state: @@ -433,7 +413,7 @@ components: type: object properties: IntendedUse: - type: boolean + type: object properties: processData: type: boolean @@ -519,13 +499,6 @@ components: type: integer issuerId: type: string - signed_resolution: - type: object - properties: - proof: - type: string - example: - proof: 'eyJhbGciOiJFUzI1NiJ9.eyJwcm9vZlR5cGUiOiJyZXNvbHV0aW9uIiwiZGF0YUV4Y2hhbmdlSWQiOiJTTmg5eUtYYjJlaGxWSFJZQkllay16Z1pVaDJtU1NvMWpwbGg3SWEtNHlRIiwiaWF0IjoxNjQ2OTUxNjM1LCJpc3MiOiJ7XCJhbGdcIjpcIkVTMjU2XCIsXCJjcnZcIjpcIlAtMjU2XCIsXCJkXCI6XCJ1Z1NpSTlJTEdnTWM1TmMwbkFhM3FGTjNBTjBvR2JhMzNJQWFrSHFkdm1nXCIsXCJrdHlcIjpcIkVDXCIsXCJ4XCI6XCJMNldmVlhHYkgwaW82SnBtOTRTMWxwZGk2eUd0VDFPbVo2NUFfa1NfaGs4XCIsXCJ5XCI6XCI2WUUwb1BPcFdCcUM3NURfanRKVWZ5NWxzWGxHak81ZzZRWGl2RHdNREtjXCJ9Iiwic3ViIjoie1wiYWxnXCI6XCJFUzI1NlwiLFwiY3J2XCI6XCJQLTI1NlwiLFwia3R5XCI6XCJFQ1wiLFwieFwiOlwiVlhzQnVPWndWamhvZkpWNGtBaGJhNnduMUVZRHdVSWtnWGIyZlZuTDh4Y1wiLFwieVwiOlwiaDRmTDVRdjRFWXQ3WGRLcWRJeTFaSnM0X1FXWURrWTF6VXpTb0k2MU43WVwifSIsInJlc29sdXRpb24iOiJkZW5pZWQiLCJ0eXBlIjoiZGlzcHV0ZSJ9.TtxUm3E6LfmwEI74cr6RO4-nw-xcFaeARYOZ4z1dBVlc_JU0mCv0Ftr9tCDhggfLiJqb4RIPiNfIytFZMUbx-g' active_agreements: type: array items: @@ -537,218 +510,3 @@ components: bearerFormat: JWT - # /create_agreement: - # post: - # tags: - # - Agreement - # summary: Create agreement - # requestBody: - # content: - # application/json: - # schema: - # $ref: '#/components/schemas/template' - # required: true - # responses: - # '200': - # description: OK - # content: - # application/json: - # schema: - # $ref: '#/components/schemas/agreement_id' - # security: - # - bearerAuth: [] - # /update_agreement/{agreement_id}: - # post: - # tags: - # - Agreement - # summary: Update agreement - # parameters: - # - name: agreement_id - # in: path - # required: true - # style: simple - # explode: false - # schema: - # type: string - # requestBody: - # content: - # application/json: - # schema: - # $ref: '#/components/schemas/template' - # required: true - # responses: - # '200': - # description: OK - # content: - # application/json: - # schema: - # $ref: '#/components/schemas/update_msg' - # security: - # - bearerAuth: [] - # /sign_agreement/{agreement_id}/{consumer_id}/{provider_id}: - # get: - # tags: - # - Agreement - # summary: Sign agreement - # parameters: - # - name: agreement_id - # in: path - # required: true - # style: simple - # explode: false - # schema: - # type: string - # - name: consumer_id - # in: path - # required: true - # style: simple - # explode: false - # schema: - # type: string - # - name: provider_id - # in: path - # required: true - # style: simple - # explode: false - # schema: - # type: string - # responses: - # '200': - # description: OK - # content: - # application/json: - # schema: - # $ref: '#/components/schemas/sign_msg' - # security: - # - bearerAuth: [] -# --------------------------------------------------------openapi.json -# "/create_agreement": { -# "post": { -# "tags": [ -# "Agreement" -# ], -# "summary": "Create agreement", -# "requestBody": { -# "content": { -# "application/json": { -# "schema": { -# "$ref": "#/components/schemas/template" -# } -# } -# }, -# "required": true -# }, -# "responses": { -# "200": { -# "description": "OK", -# "content": { -# "application/json": { -# "schema": { -# "$ref": "#/components/schemas/agreement_id" -# } -# } -# } -# } -# }, -# "security": [ -# { -# "bearerAuth": [] -# } -# ] -# } -# }, -# "/update_agreement/{agreement_id}": { -# "post": { -# "tags": [ -# "Agreement" -# ], -# "summary": "Update agreement", -# "parameters": [ -# { -# "name": "agreement_id", -# "in": "path", -# "required": true, -# "style": "simple", -# "explode": false, -# "schema": { -# "type": "string" -# } -# } -# ], -# "requestBody": { -# "content": { -# "application/json": { -# "schema": { -# "$ref": "#/components/schemas/template" -# } -# } -# }, -# "required": true -# }, -# "responses": { -# "200": { -# "description": "OK", -# "content": { -# "application/json": { -# "schema": { -# "$ref": "#/components/schemas/update_msg" -# } -# } -# } -# } -# }, -# "security": [ -# { -# "bearerAuth": [] -# } -# ] -# } -# }, -# , -# "/sign_agreement/{agreement_id}/{consumer_id}": { -# "get": { -# "tags": [ -# "Agreement" -# ], -# "summary": "Sign agreement", -# "parameters": [ -# { -# "name": "agreement_id", -# "in": "path", -# "required": true, -# "style": "simple", -# "explode": false, -# "schema": { -# "type": "string" -# } -# }, -# { -# "name": "consumer_id", -# "in": "path", -# "required": true, -# "style": "simple", -# "explode": false, -# "schema": { -# "type": "string" -# } -# } -# ], -# "responses": { -# "200": { -# "description": "OK", -# "content": { -# "application/json": { -# "schema": { -# "$ref": "#/components/schemas/sign_msg" -# } -# } -# } -# } -# }, -# "security": [ -# { -# "bearerAuth": [] -# } -# ] -# } -# } diff --git a/src/package-lock.json b/src/package-lock.json index 7b17859..9f6ee3e 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -3987,9 +3987,9 @@ "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" }, "node-fetch": { - "version": "2.6.5", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz", - "integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==", + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", "requires": { "whatwg-url": "^5.0.0" } diff --git a/src/routes/routes.ts b/src/routes/routes.ts index a549d3e..597bf05 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -4,12 +4,10 @@ import * as fs from 'fs'; import * as _fetch from 'isomorphic-fetch' import { ConvertToTemplate, Template } from "../template"; import { ConvertToStaticParametersTemplate, StaticParametersTemplate } from "../staticParametersTemplate"; -import { getTemplate, /*createAgreements,*/ processTemplate, formatAgreement, notify, getState, formatTransaction, formatTransactionReceipt, parseHex } from "../common"; +import { getTemplate, processTemplate, formatAgreement, notify, getState, formatTransaction, formatTransactionReceipt, parseHex } from "../common"; import { ethers } from 'ethers'; import * as path from 'path'; -import * as nonRepudiationLibrary from '@i3m/non-repudiation-library' -import { DisputeRequestPayload } from '@i3m/non-repudiation-library'; const dotenv = require('dotenv').config({ path: path.resolve(__dirname, '../../.env') }) @@ -78,110 +76,7 @@ export default async (): Promise => { } }) - // router.post('/create_agreement', async (req ,res, next) => { - // try { - // const template = ConvertToTemplate.toTemplate(JSON.stringify(req.body)) - // const processedTemplate = processTemplate(template) - - // // process input data - // const dataOfferingId = processedTemplate.dataOfferingId - // const purpose = processedTemplate.purpose - // const providerId = processedTemplate.providerId - // const consumerId = processedTemplate.consumerId - // const dates = processedTemplate.dates - // const descriptionOfData = processedTemplate.descriptionOfData - // const intendedUse = processedTemplate.intendedUse - // const licenseGrant = processedTemplate.licenseGrant - // const dataStream = processedTemplate.dataStream - - // const agreementId = await createAgreements(contract, dataOfferingId, purpose, providerId, consumerId, dates, descriptionOfData, intendedUse, licenseGrant, dataStream) - - // const origin = "scm" - // const predefined = true - // const type = "agreement.pending" - // const message = {msg: "Agreement created"} - // const status = "pending" - - // await notify(origin, predefined, type, `${consumerId}`, message, status) - // await notify(origin, predefined, type, `${providerId}`, message, status) - - // res.status(200).send({agreement_id: `${agreementId}`}) - - // } catch (error) { - // if (error instanceof Error) { - // console.log(`${error.message}`) - // res.status(500).send({name: `${error.name}`, message: `${error.message}`}) - // } - // } - // }) - - // router.post('/update_agreement/:agreement_id', async(req,res) => { - - // try { - // const agreementId = req.params.agreement_id - // const template = ConvertToTemplate.toTemplate(JSON.stringify(req.body)) - // const processedTemplate = processTemplate(template) - - // // process input data - // const dataOfferingId = processedTemplate.dataOfferingId - // const purpose = processedTemplate.purpose - // const providerId = processedTemplate.providerId - // const consumerId = processedTemplate.consumerId - // const dates = processedTemplate.dates - // const descriptionOfData = processedTemplate.descriptionOfData - // const intendedUse = processedTemplate.intendedUse - // const licenseGrant = processedTemplate.licenseGrant - // const dataStream = processedTemplate.dataStream - - // const update = await contract.updateAgreement(agreementId ,dataOfferingId, purpose, providerId, consumerId, dates, descriptionOfData, intendedUse, licenseGrant, dataStream) - - // const origin = "scm" - // const predefined = true - // const type = "agreement.update" - // const message = {msg: "Agreement updated"} - // const status = "update" - - // await notify(origin, predefined, type, `${consumerId}`, message, status) - // await notify(origin, predefined, type, `${providerId}`, message, status) - - // res.status(200).send({msg: `Agreement with id ${agreementId} was updated`}) - - // } catch (error) { - // if (error instanceof Error) { - // console.log(`${error.message}`) - // res.status(500).send({name: `${error.name}`, message: `${error.message}`}) - // } - // } - - // }) - - // router.get('/sign_agreement/:agreement_id/:consumer_id/:provider_id', async(req,res) => { - - // try { - // const agreementId = req.params.agreement_id - // const consumerId = req.params.consumer_id - // const providerId = req.params.provider_id - - // const signAgreement = await contract.signAgreement(agreementId, consumerId, {gasLimit: gasLimit}); - - // const origin = "scm" - // const predefined = true - // const type = "agreement.accepted" - // const message = {msg: "Agreement signed"} - // const status = "accepted" - - // await notify(origin, predefined, type, `${consumerId}`, message, status) - // await notify(origin, predefined, type, `${providerId}`, message, status) - - // res.status(200).send({msg: `Agreement with id ${agreementId} was signed`}) - // } catch (error) { - // if(error instanceof Error){ - // console.log(`${error.message}`) - // res.status(500).send({name: `${error.name}`, message: `${error.message}`}) - // } - // } - // }) - + router.get('/get_agreement/:agreement_id', async (req, res) => { try { @@ -453,53 +348,6 @@ router.put('/sign_agreement_raw_transaction/:agreement_id/:consumer_id/:sender_a } }) -router.post('/provide_signed_resolution', async (req, res, next) => { - try { - const signedResolution = req.body.proof - console.log(signedResolution) - const decodedResolution = await nonRepudiationLibrary.ConflictResolution.verifyResolution(signedResolution) - - //const resolutionPayload = await nonRepudiationLibrary.ConflictResolution.verifyResolution(signedResolution) - - // proofType: 'resolution' - // type: 'dispute' - // resolution: 'accepted' | 'denied' // resolution is 'denied' if the cipherblock can be properly decrypted; otherwise is 'accepted' - // dataExchangeId: string // the unique id of this data exchange - // iat: number // unix timestamp stating when it was resolved - // iss: string // the public key of the CRS in JWK - // sub: string // the public key (JWK) of the entity that requested a resolution - - // // We will receive a signed resolution. Let us assume that is in variable disputeResolution - // const resolutionPayload = await nonRepudiationLibrary.ConflictResolution.verifyResolution(disputeResolution) - // if (resolutionPayload.resolution === 'accepted') { - // // We were right about our claim: the cipherblock cannot be decrypted and we can't be invoiced for it. - // } else { // resolutionPayload.resolution === 'denied' - // // The cipherblock can be decrypted with the published secret, so either we had a malicious intention or we have an issue with our software. - // } - - const trustedIssuers = [ - '{"alg":"ES256","crv":"P-256","d":"ugSiI9ILGgMc5Nc0nAa3qFN3AN0oGba33IAakHqdvmg","kty":"EC","x":"L6WfVXGbH0io6Jpm94S1lpdi6yGtT1OmZ65A_kS_hk8","y":"6YE0oPOpWBqC75D_jtJUfy5lsXlGjO5g6QXivDwMDKc"}' - ] - const proofType = decodedResolution.payload.proofType - const type = decodedResolution.payload.type - const resolution = decodedResolution.payload.resolution - const dataExchangeId = decodedResolution.payload.dataExchangeId - const iat = decodedResolution.payload.iat - const iss = decodedResolution.payload.iss - if (!trustedIssuers.includes(iss)) { - throw new Error('untrusted issuer') - } - const sub = decodedResolution.payload.sub - - res.status(200).send(decodedResolution.payload) - - } catch (error) { - if (error instanceof Error) { - console.log(`${error.message}`) - res.status(500).send({ name: `${error.name}`, message: `${error.message}` }) - } - } -}) return router; } diff --git a/template.env b/template.env index 44eb3fa..a72cc4e 100644 --- a/template.env +++ b/template.env @@ -2,7 +2,7 @@ NODE_ENV=development # or production APP_NAME=express-sc-manager -BACKPLANE_URL=http://95.211.3.244:3000 -NOTIFICATION_MANAGER_URL=http://95.211.3.244:10010 +BACKPLANE_URL= + ADDRESS=0.0.0.0 PORT=3000