public code v1
This commit is contained in:
+133
@@ -0,0 +1,133 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# database
|
||||
phonendo_db
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Sinbad2 - Francisco Moya
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,177 @@
|
||||
|
||||
<!-- PROJECT SHIELDS -->
|
||||
<!--
|
||||
*** I'm using markdown "reference style" links for readability.
|
||||
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
||||
*** See the bottom of this document for the declaration of the reference variables
|
||||
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
||||
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
||||
-->
|
||||
[![Contributors][contributors-shield]][contributors-url]
|
||||
[![Forks][forks-shield]][forks-url]
|
||||
[![Stargazers][stars-shield]][stars-url]
|
||||
[![Issues][issues-shield]][issues-url]
|
||||
[![MIT License][license-shield]][license-url]
|
||||
[![LinkedIn][linkedin-shield]][linkedin-url]
|
||||
|
||||
|
||||
|
||||
<!-- PROJECT LOGO -->
|
||||
<br />
|
||||
<div align="center">
|
||||
|
||||
<h1 align="center">Phonendo</h1>
|
||||
|
||||
<p align="center">
|
||||
Phonendo is a platform consisting of several software services that manages the entire data lifecycle from wearable device data collection to publishing them on IOTA.
|
||||
<br />
|
||||
<br />
|
||||
Phonendo is published on Wireless Networks https://link.springer.com/article/10.1007/s11276-023-03458-7 and can be cited:
|
||||
|
||||
Moya, F., Quesada, F.J., Martínez, L. et al.
|
||||
Phonendo: a platform for publishing wearable data on distributed ledger technologies.
|
||||
Wireless Netw (2023).
|
||||
https://doi.org/10.1007/s11276-023-03458-7
|
||||
<br />
|
||||
<br />
|
||||
<a href="https://github.com/sinbad2-ujaen/phonendo/blob/main/demo/phonendo_demo.mp4">View Demo</a>
|
||||
·
|
||||
<a href="https://github.com/sinbad2-ujaen/phonendo/issues">Report Bug / Request Feature</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
<details>
|
||||
<summary>Table of Contents</summary>
|
||||
<ol>
|
||||
<li>
|
||||
<a href="#about-the-project">About The Project</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#getting-started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||
<li><a href="#installation">Installation</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#usage">Usage</a></li>
|
||||
<li><a href="#contributing">Contributing</a></li>
|
||||
<li><a href="#license">License</a></li>
|
||||
</ol>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<!-- ABOUT THE PROJECT -->
|
||||
## About The Project
|
||||
|
||||
[![Phonendo][product-screenshot]](https://github.com/sinbad2-ujaen/phonendo)
|
||||
|
||||
The Phonendo architecture adopts a microservice event-driven approach, consisting of five key components: Reader, Manager, Storage, Verifier, and Publisher. The diagram below depicts the interconnectedness of these components and highlights their primary functions. This architectural design prioritizes flexibility, scalability, and adaptability across various applications.
|
||||
|
||||
To facilitate rapid prototyping and leverage the extensive support within the developer community, we opted for the Node.js framework and JavaScript programming language in the development of Phonendo. HTTP was chosen as the communication protocol due to its simplicity in facilitating seamless data transfer between services.
|
||||
|
||||
During the implementation phase, we employed the Pine Time smartwatch (available at [https://www.pine64.org/pinetime/](https://www.pine64.org/pinetime/)) as a reference device. This choice allowed us to ensure compatibility and evaluate the integration of Phonendo with a real-world wearable device. By doing so, we were able to validate the platform's functionality and its capacity to handle data from smartwatches, which are commonly used in healthcare and fitness applications.
|
||||
|
||||
It is essential to acknowledge that the current implementation of Phonendo serves as a foundation for further research and development. As we continue refining the platform and exploring additional use cases, we anticipate introducing enhancements and optimizations based on empirical experimentation and user feedback.
|
||||
|
||||
<!-- GETTING STARTED -->
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
This is an example of how to list things you need to use the software and how to install them.
|
||||
* npm
|
||||
```sh
|
||||
npm install npm@latest -g
|
||||
```
|
||||
|
||||
* pm2
|
||||
```sh
|
||||
npm install -g pm2
|
||||
```
|
||||
|
||||
### Installation
|
||||
|
||||
1. Clone the repo
|
||||
```sh
|
||||
git clone https://github.com/sinbad2-ujaen/phonendo.git
|
||||
```
|
||||
2. Install NPM packages
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
3. Start project
|
||||
```sh
|
||||
npm run infra:up
|
||||
```
|
||||
|
||||
|
||||
|
||||
<!-- USAGE EXAMPLES -->
|
||||
## Usage
|
||||
|
||||
- To start the project
|
||||
```sh
|
||||
npm run infra:up
|
||||
```
|
||||
- To stop the project
|
||||
```sh
|
||||
npm run infra:down
|
||||
```
|
||||
- To clean all resources
|
||||
```sh
|
||||
npm run infra:clean
|
||||
```
|
||||
- To restart all services
|
||||
```sh
|
||||
npm run infra:restart
|
||||
```
|
||||
|
||||
Once all services are up, next step is to register a device using the Reader endpoint
|
||||
```
|
||||
curl --location 'http://127.0.0.1:3003/register' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'device=XXXXXXXXXX' \ --data-urlencode 'serialNumber=XXX' \ --data-urlencode 'deviceType=SMARTWATCH'
|
||||
```
|
||||
|
||||
Once the device is registered, Phonendo will automatically detect, connect and start listening events. In particular, it captures heartbeat events.
|
||||
|
||||
<!-- CONTRIBUTING -->
|
||||
## Contributing
|
||||
|
||||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
||||
|
||||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
||||
Don't forget to give the project a star! Thanks again!
|
||||
|
||||
1. Fork the Project
|
||||
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
||||
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
||||
5. Open a Pull Request
|
||||
|
||||
|
||||
|
||||
<!-- LICENSE -->
|
||||
## License
|
||||
|
||||
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
||||
|
||||
|
||||
|
||||
<!-- MARKDOWN LINKS & IMAGES -->
|
||||
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
||||
[contributors-shield]: https://img.shields.io/github/contributors/sinbad2-ujaen/phonendo.svg?style=for-the-badge
|
||||
[contributors-url]: https://github.com/sinbad2-ujaen/phonendo/graphs/contributors
|
||||
[forks-shield]: https://img.shields.io/github/forks/sinbad2-ujaen/phonendo.svg?style=for-the-badge
|
||||
[forks-url]: https://github.com/sinbad2-ujaen/phonendo/network/members
|
||||
[stars-shield]: https://img.shields.io/github/stars/sinbad2-ujaen/phonendo.svg?style=for-the-badge
|
||||
[stars-url]: https://github.com/sinbad2-ujaen/phonendo/stargazers
|
||||
[issues-shield]: https://img.shields.io/github/issues/sinbad2-ujaen/phonendo.svg?style=for-the-badge
|
||||
[issues-url]: https://github.com/sinbad2-ujaen/phonendo/issues
|
||||
[license-shield]: https://img.shields.io/github/license/sinbad2-ujaen/phonendo.svg?style=for-the-badge
|
||||
[license-url]: https://github.com/sinbad2-ujaen/phonendo/LICENSE.txt
|
||||
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
|
||||
[linkedin-url]: https://www.linkedin.com/in/francisco-moya/
|
||||
[product-screenshot]: images/system.jpg
|
||||
@@ -0,0 +1,33 @@
|
||||
const express = require("express");
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
class Express {
|
||||
#app;
|
||||
#name;
|
||||
#port;
|
||||
|
||||
constructor(port, name = "Service") {
|
||||
this.#app = express();
|
||||
this.#app.use(bodyParser.json());
|
||||
this.#app.use(bodyParser.urlencoded({ extended: true }));
|
||||
this.#name = name;
|
||||
this.#port = port;
|
||||
}
|
||||
|
||||
get app() {
|
||||
return this.#app;
|
||||
}
|
||||
|
||||
get = (path, f) => this.#app.get(path, f);
|
||||
post = (path, f) => this.#app.post(path, f);
|
||||
put = (path, f) => this.#app.put(path, f);
|
||||
delete = (path, f) => this.#app.delete(path, f);
|
||||
|
||||
run = () => {
|
||||
this.#app.listen(this.#port, () =>
|
||||
console.log(`${this.#name} listening on port ${this.#port}`)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Express = Express;
|
||||
@@ -0,0 +1,56 @@
|
||||
const axios = require("axios");
|
||||
|
||||
function promiseGetRequest(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(url)
|
||||
axios.get(url)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function promisePostRequest(url, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.post(url, body)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function promisePutRequest(url, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.put(url, body)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function promiseDeleteRequest(url, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios.delete(url, { data: body })
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {promiseGetRequest, promisePostRequest, promiseDeleteRequest}
|
||||
Generated
+1019
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "core",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.20.1",
|
||||
"express": "^4.18.2"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
module.exports = {
|
||||
apps: [{
|
||||
name: "manager",
|
||||
script: "./manager/index.js",
|
||||
watch: true
|
||||
},
|
||||
{
|
||||
name: "verifier",
|
||||
script: "./verifier/index.js",
|
||||
watch: true
|
||||
},
|
||||
{
|
||||
name: "storage",
|
||||
script: "./storage/index.js",
|
||||
ignore_watch: ["phonendo_db"],
|
||||
watch: true
|
||||
},
|
||||
{
|
||||
name: "reader",
|
||||
script: "./reader/index.js",
|
||||
watch: true
|
||||
},
|
||||
{
|
||||
name: "publisher",
|
||||
script: "./publisher/index.js",
|
||||
watch: true
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 367 KiB |
Symlink
+1
@@ -0,0 +1 @@
|
||||
../core
|
||||
@@ -0,0 +1,116 @@
|
||||
require('dotenv').config()
|
||||
const { Express } = require("./core/Express");
|
||||
const { promisePostRequest, promiseDeleteRequest } = require('./core/httpClient')
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const { generateKeyPairSync, createHash } = require("node:crypto");
|
||||
const toBytes = (string) => Array.from(Buffer.from(string, 'utf8'));
|
||||
|
||||
|
||||
const express = new Express(process.env.PORT_MANAGER, "Manager")
|
||||
express.get('/', async (_, res) => {
|
||||
res.send('Service is alive')
|
||||
});
|
||||
|
||||
express.post('/registerDevice', (req, res) => {
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_MANAGER) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
let device = req.body.device;
|
||||
let type = req.body.type;
|
||||
let serialNumber = req.body.serialNumber;
|
||||
let creationDatetime = req.body.creationDatetime;
|
||||
|
||||
if (device) {
|
||||
console.log("New device received: " + device);
|
||||
// send to storage
|
||||
let message = {
|
||||
key: device,
|
||||
value: {
|
||||
device: device,
|
||||
type: type,
|
||||
serialNumber: serialNumber,
|
||||
creationDatetime: creationDatetime
|
||||
}
|
||||
};
|
||||
|
||||
let body = {
|
||||
token: process.env.API_TOKEN_STORAGE,
|
||||
message: message
|
||||
};
|
||||
|
||||
promisePostRequest(process.env.INTERNAL_URL_STORAGE_DEVICES, body);
|
||||
|
||||
res.status(200).send("Successfully registered");
|
||||
|
||||
} else {
|
||||
res.status(403).send("Bad request");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
express.post('/newEvent',async (req, res) => {
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_MANAGER) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
let type = req.body.type;
|
||||
let value = req.body.value;
|
||||
let device = req.body.device;
|
||||
|
||||
console.log("New event received: " + type + " // " + value + " // " + device);
|
||||
|
||||
let message = {
|
||||
key: uuidv4(),
|
||||
value: {
|
||||
type: type,
|
||||
value: value,
|
||||
device: device,
|
||||
creationDatetime: new Date().getTime()
|
||||
}
|
||||
};
|
||||
|
||||
message = signDataSource(message);
|
||||
|
||||
// Store event on Storage as Captured
|
||||
let body = {
|
||||
token: process.env.API_TOKEN_STORAGE,
|
||||
message: message
|
||||
};
|
||||
|
||||
let storedMessage = await promisePostRequest(process.env.INTERNAL_URL_STORAGE_EVENTS, body);
|
||||
|
||||
// Verify event
|
||||
body.message = storedMessage;
|
||||
body.token = process.env.API_TOKEN_VERIFIER;
|
||||
|
||||
let verifiedMessage = await promisePostRequest(process.env.INTERNAL_URL_VERIFIER_VERIFY, body);
|
||||
|
||||
// Store event on Storage as Verified
|
||||
body.message = verifiedMessage;
|
||||
body.token = process.env.API_TOKEN_STORAGE;
|
||||
|
||||
let storedVerifiedMessage = await promisePostRequest(process.env.INTERNAL_URL_STORAGE_EVENTS, body);
|
||||
|
||||
// Publish event
|
||||
body.message = storedVerifiedMessage;
|
||||
body.token = process.env.API_TOKEN_PUBLISHER;
|
||||
let publishedMessage = await promisePostRequest(process.env.INTERNAL_URL_PUBLISHER_PUBLISH, body);
|
||||
|
||||
body.token = process.env.API_TOKEN_STORAGE;
|
||||
|
||||
// Delete event from Storage
|
||||
promiseDeleteRequest(process.env.INTERNAL_URL_STORAGE_EVENTS + "/" + publishedMessage.key, body);
|
||||
|
||||
res.status(200).send('Event processed');
|
||||
}
|
||||
});
|
||||
|
||||
function signDataSource(message) {
|
||||
|
||||
const hash = createHash('sha256').update(message.value.device + 'Phonendo').digest('hex');
|
||||
|
||||
const bytes = toBytes(hash);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
express.run();
|
||||
Generated
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "manager",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "manager",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.3",
|
||||
"uuid4": "^2.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid4": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid4/-/uuid4-2.0.3.tgz",
|
||||
"integrity": "sha512-CTpAkEVXMNJl2ojgtpLXHgz23dh8z81u6/HEPiQFOvBc/c2pde6TVHmH4uwY0d/GLF3tb7+VDAj4+2eJaQSdZQ=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||
},
|
||||
"uuid4": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid4/-/uuid4-2.0.3.tgz",
|
||||
"integrity": "sha512-CTpAkEVXMNJl2ojgtpLXHgz23dh8z81u6/HEPiQFOvBc/c2pde6TVHmH4uwY0d/GLF3tb7+VDAj4+2eJaQSdZQ=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "manager",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.3",
|
||||
"uuid4": "^2.0.3"
|
||||
}
|
||||
}
|
||||
Generated
+185
@@ -0,0 +1,185 @@
|
||||
{
|
||||
"name": "experiment",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "experiment",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.4.0",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz",
|
||||
"integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/axios/node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"axios": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz",
|
||||
"integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"requires": {
|
||||
"mime-db": "1.52.0"
|
||||
}
|
||||
},
|
||||
"proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "experiment",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"infra:up": "./wizard start2",
|
||||
"infra:down": "./wizard stop",
|
||||
"infra:clean": "./wizard teardown",
|
||||
"infra:restart": "./wizard restart"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.4.0",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../core
|
||||
@@ -0,0 +1,41 @@
|
||||
require('dotenv').config();
|
||||
const { Express } = require("./core/Express");
|
||||
const { ClientBuilder } = require('@iota/client');
|
||||
var lastMessageId = "";
|
||||
|
||||
const client = new ClientBuilder()
|
||||
//.node('https://api.lb-0.h.chrysalis-devnet.iota.cafe')
|
||||
.build();
|
||||
|
||||
const express = new Express(process.env.PORT_PUBLISHER, "Publisher")
|
||||
express.get('/', (_, res) => {
|
||||
client.getInfo().then(console.log).catch(console.error);
|
||||
res.send('Service is alive')
|
||||
});
|
||||
|
||||
express.post('/publish', async (req, res) => {
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_PUBLISHER) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
if (!req.body.message) {
|
||||
res.status(403).send("Bad request");
|
||||
} else {
|
||||
console.log(lastMessageId)
|
||||
let iotaBuilder = client.message()
|
||||
.index('PHONENDO')
|
||||
.data(JSON.stringify(req.body.message));
|
||||
|
||||
if (lastMessageId) {
|
||||
iotaBuilder.parents([lastMessageId])
|
||||
}
|
||||
|
||||
const iotaMessage = await iotaBuilder.submit();
|
||||
|
||||
lastMessageId = iotaMessage.messageId;
|
||||
console.log("Event published on IOTA" + JSON.stringify(iotaMessage));
|
||||
res.status(200).send(req.body.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
express.run();
|
||||
Generated
+2420
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "publisher",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@iota/client": "^2.2.4",
|
||||
"dotenv": "^16.0.3"
|
||||
}
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../core
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
require('dotenv').config();
|
||||
const {Express} = require("./core/Express");
|
||||
const {promisePostRequest} = require('./core/httpClient')
|
||||
const noble = require('@abandonware/noble');
|
||||
|
||||
const EVENT_TYPE = {
|
||||
Heartrate: "HEART_RATE"
|
||||
}
|
||||
|
||||
let discoverableDevices = [];
|
||||
let listenablePeripherals = [];
|
||||
let listeningPeripherals = [];
|
||||
|
||||
initBluetooth();
|
||||
listenHeartrateEvents();
|
||||
|
||||
const express = new Express(process.env.PORT_READER, "Reader")
|
||||
express.get('/', (_, res) => {
|
||||
res.send('Service is alive')
|
||||
});
|
||||
|
||||
express.post('/register', (req, res) => {
|
||||
let device = req.body.device;
|
||||
let serialNumber = req.body.serialNumber;
|
||||
let deviceType = req.body.deviceType;
|
||||
|
||||
if (device) {
|
||||
console.log("New device received: " + device);
|
||||
discoverableDevices.push(device);
|
||||
let body = {
|
||||
token: process.env.API_TOKEN_MANAGER,
|
||||
device: device,
|
||||
type: deviceType,
|
||||
serialNumber: serialNumber,
|
||||
creationDatetime: new Date().getTime()
|
||||
};
|
||||
|
||||
promisePostRequest(process.env.INTERNAL_URL_MANAGER_REGISTER_DEVICE, body);
|
||||
|
||||
res.status(200).send("Successfully registered");
|
||||
|
||||
} else {
|
||||
res.status(403).send("Bad request");
|
||||
}
|
||||
});
|
||||
|
||||
async function initBluetooth() {
|
||||
noble.on('stateChange', async (state) => {
|
||||
if (state === 'poweredOn') {
|
||||
await noble.startScanningAsync([], true);
|
||||
}
|
||||
});
|
||||
|
||||
noble.on('discover', async (peripheral) => {
|
||||
|
||||
const isDiscoverable = discoverableDevices.some(device => device === peripheral.id);
|
||||
|
||||
if (isDiscoverable) {
|
||||
listenablePeripherals.push(peripheral);
|
||||
discoverableDevices = discoverableDevices.filter(device => device !== peripheral.id && device !== peripheral.address);
|
||||
await peripheral.connectAsync();
|
||||
console.log('Connected to peripheral:', peripheral.address);
|
||||
console.log('Peripheral name:', peripheral.advertisement.localName);
|
||||
console.log('Peripheral advertisement data:', peripheral.advertisement);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function listenHeartrateEvents() {
|
||||
|
||||
setInterval(function () {
|
||||
const devicesToListen = listenablePeripherals.filter(item => !listeningPeripherals.includes(item));
|
||||
|
||||
devicesToListen.every(async peripheral => {
|
||||
const {characteristics} = await peripheral.discoverSomeServicesAndCharacteristicsAsync(['180D'], ['2A37']);
|
||||
|
||||
characteristics.forEach(function (characteristic) {
|
||||
characteristic.on('data', function (data, isNotification) {
|
||||
|
||||
let body = {
|
||||
token: process.env.API_TOKEN_MANAGER,
|
||||
type: EVENT_TYPE.Heartrate,
|
||||
value: parseInt(data.toString('hex'), 16),
|
||||
device: peripheral.id,
|
||||
creationDatetime: new Date().getTime()
|
||||
};
|
||||
|
||||
promisePostRequest(process.env.INTERNAL_URL_MANAGER_NEW_EVENT, body);
|
||||
|
||||
});
|
||||
|
||||
characteristic.subscribe(function (error) {
|
||||
// Handle the subscription error
|
||||
console.error("Error", error);
|
||||
});
|
||||
});
|
||||
listeningPeripherals.push(peripheral);
|
||||
});
|
||||
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
express.run();
|
||||
Generated
+4494
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "reader",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@abandonware/noble": "^1.9.2-21",
|
||||
"bluetooth": "^3.0.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"noble": "^1.9.1",
|
||||
"noble-mac": "https://github.com/Timeular/noble-mac.git",
|
||||
"node-gyp": "^9.3.1"
|
||||
}
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../core
|
||||
@@ -0,0 +1,76 @@
|
||||
const { Level } = require("level");
|
||||
|
||||
const db = new Level("phonendo_db", { valueEncoding: "json" });
|
||||
|
||||
|
||||
const write = async (key, value) => {
|
||||
try {
|
||||
await db.get(key);
|
||||
} catch (error) {
|
||||
await db.put(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
const read = async (key) => {
|
||||
let result = "";
|
||||
try {
|
||||
result = await db.get(key);
|
||||
} catch (error) {
|
||||
console.warn(`DB ${key} not found`);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const update = async (key, value) => {
|
||||
await del(key);
|
||||
await write(key, value);
|
||||
};
|
||||
|
||||
const del = async (key) => {
|
||||
let result = "";
|
||||
try {
|
||||
result = await db.del(key);
|
||||
} catch (error) {f
|
||||
console.warn(`DB ${key} not found`);
|
||||
}
|
||||
};
|
||||
|
||||
const getAllCapturedItems = async () => {
|
||||
|
||||
let capturedItems = [];
|
||||
|
||||
try {
|
||||
for await (const data of db.iterator()) {
|
||||
const [key, value] = data;
|
||||
if (value.status === "Captured") {
|
||||
capturedItems.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
return capturedItems;
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
return capturedItems;
|
||||
}
|
||||
};
|
||||
|
||||
const getAllItems = async () => {
|
||||
|
||||
let capturedItems = [];
|
||||
|
||||
try {
|
||||
for await (const data of db.iterator()) {
|
||||
const [key, value] = data;
|
||||
capturedItems.push(data);
|
||||
}
|
||||
|
||||
return capturedItems;
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
return capturedItems;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { write, read, update, del, getAllCapturedItems, getAllItems };
|
||||
@@ -0,0 +1,83 @@
|
||||
require('dotenv').config()
|
||||
const {Express} = require("./core/Express");
|
||||
const {write, getAllItems, del, update} = require("./db.js");
|
||||
|
||||
|
||||
const express = new Express(process.env.PORT_STORAGE, "Storage")
|
||||
express.get('/', async (_, res) => {
|
||||
|
||||
let data = await getAllItems();
|
||||
|
||||
console.log(data);
|
||||
|
||||
res.send('Service is alive')
|
||||
});
|
||||
|
||||
express.post('/devices', async (req, res) => {
|
||||
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_STORAGE) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
if (!req.body.message) {
|
||||
res.status(403).send("Bad request");
|
||||
} else {
|
||||
let message = req.body.message;
|
||||
await write(message.key, message.value);
|
||||
console.log("Device registered on db: " + message.key);
|
||||
res.status(200).send("ok");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
express.post('/events', async (req, res) => {
|
||||
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_STORAGE) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
if (!req.body.message) {
|
||||
res.status(403).send("Bad request");
|
||||
} else {
|
||||
let message = req.body.message;
|
||||
message.value.status = "Captured";
|
||||
|
||||
await write(message.key, message.value);
|
||||
console.log("Event Captured on db");
|
||||
res.status(200).send(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
express.put('/events', async (req, res) => {
|
||||
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_STORAGE) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
if (!req.body.message) {
|
||||
res.status(403).send("Bad request");
|
||||
} else {
|
||||
let message = req.body.message;
|
||||
message.value.status = "Verified";
|
||||
|
||||
await update(message.key, message.value);
|
||||
console.log("Event updated to Verified on db");
|
||||
res.status(200).send(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
express.delete('/events/:id', (req, res) => {
|
||||
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_STORAGE) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
if (!req.params.id) {
|
||||
res.status(403).send("Bad request");
|
||||
} else {
|
||||
del(req.params.id)
|
||||
|
||||
console.log("Event deleted from db");
|
||||
res.status(200).send("ok");
|
||||
}
|
||||
}
|
||||
})
|
||||
express.run();
|
||||
Generated
+384
@@ -0,0 +1,384 @@
|
||||
{
|
||||
"name": "storage",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "storage",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.3",
|
||||
"level": "^8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/abstract-level": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/abstract-level/-/abstract-level-1.0.3.tgz",
|
||||
"integrity": "sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA==",
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"catering": "^2.1.0",
|
||||
"is-buffer": "^2.0.5",
|
||||
"level-supports": "^4.0.0",
|
||||
"level-transcoder": "^1.0.1",
|
||||
"module-error": "^1.0.1",
|
||||
"queue-microtask": "^1.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/browser-level": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/browser-level/-/browser-level-1.0.1.tgz",
|
||||
"integrity": "sha512-XECYKJ+Dbzw0lbydyQuJzwNXtOpbMSq737qxJN11sIRTErOMShvDpbzTlgju7orJKvx4epULolZAuJGLzCmWRQ==",
|
||||
"dependencies": {
|
||||
"abstract-level": "^1.0.2",
|
||||
"catering": "^2.1.1",
|
||||
"module-error": "^1.0.2",
|
||||
"run-parallel-limit": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/catering": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz",
|
||||
"integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/classic-level": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/classic-level/-/classic-level-1.2.0.tgz",
|
||||
"integrity": "sha512-qw5B31ANxSluWz9xBzklRWTUAJ1SXIdaVKTVS7HcTGKOAmExx65Wo5BUICW+YGORe2FOUaDghoI9ZDxj82QcFg==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"abstract-level": "^1.0.2",
|
||||
"catering": "^2.1.0",
|
||||
"module-error": "^1.0.1",
|
||||
"napi-macros": "~2.0.0",
|
||||
"node-gyp-build": "^4.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ieee754": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/is-buffer": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz",
|
||||
"integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/level": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/level/-/level-8.0.0.tgz",
|
||||
"integrity": "sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ==",
|
||||
"dependencies": {
|
||||
"browser-level": "^1.0.1",
|
||||
"classic-level": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/level"
|
||||
}
|
||||
},
|
||||
"node_modules/level-supports": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-supports/-/level-supports-4.0.1.tgz",
|
||||
"integrity": "sha512-PbXpve8rKeNcZ9C1mUicC9auIYFyGpkV9/i6g76tLgANwWhtG2v7I4xNBUlkn3lE2/dZF3Pi0ygYGtLc4RXXdA==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/level-transcoder": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-transcoder/-/level-transcoder-1.0.1.tgz",
|
||||
"integrity": "sha512-t7bFwFtsQeD8cl8NIoQ2iwxA0CL/9IFw7/9gAjOonH0PWTTiRfY7Hq+Ejbsxh86tXobDQ6IOiddjNYIfOBs06w==",
|
||||
"dependencies": {
|
||||
"buffer": "^6.0.3",
|
||||
"module-error": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/module-error": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz",
|
||||
"integrity": "sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/napi-macros": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.0.0.tgz",
|
||||
"integrity": "sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg=="
|
||||
},
|
||||
"node_modules/node-gyp-build": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz",
|
||||
"integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==",
|
||||
"bin": {
|
||||
"node-gyp-build": "bin.js",
|
||||
"node-gyp-build-optional": "optional.js",
|
||||
"node-gyp-build-test": "build-test.js"
|
||||
}
|
||||
},
|
||||
"node_modules/queue-microtask": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
||||
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/run-parallel-limit": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz",
|
||||
"integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"queue-microtask": "^1.2.2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"abstract-level": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/abstract-level/-/abstract-level-1.0.3.tgz",
|
||||
"integrity": "sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA==",
|
||||
"requires": {
|
||||
"buffer": "^6.0.3",
|
||||
"catering": "^2.1.0",
|
||||
"is-buffer": "^2.0.5",
|
||||
"level-supports": "^4.0.0",
|
||||
"level-transcoder": "^1.0.1",
|
||||
"module-error": "^1.0.1",
|
||||
"queue-microtask": "^1.2.3"
|
||||
}
|
||||
},
|
||||
"base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
|
||||
},
|
||||
"browser-level": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/browser-level/-/browser-level-1.0.1.tgz",
|
||||
"integrity": "sha512-XECYKJ+Dbzw0lbydyQuJzwNXtOpbMSq737qxJN11sIRTErOMShvDpbzTlgju7orJKvx4epULolZAuJGLzCmWRQ==",
|
||||
"requires": {
|
||||
"abstract-level": "^1.0.2",
|
||||
"catering": "^2.1.1",
|
||||
"module-error": "^1.0.2",
|
||||
"run-parallel-limit": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"requires": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"catering": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz",
|
||||
"integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w=="
|
||||
},
|
||||
"classic-level": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/classic-level/-/classic-level-1.2.0.tgz",
|
||||
"integrity": "sha512-qw5B31ANxSluWz9xBzklRWTUAJ1SXIdaVKTVS7HcTGKOAmExx65Wo5BUICW+YGORe2FOUaDghoI9ZDxj82QcFg==",
|
||||
"requires": {
|
||||
"abstract-level": "^1.0.2",
|
||||
"catering": "^2.1.0",
|
||||
"module-error": "^1.0.1",
|
||||
"napi-macros": "~2.0.0",
|
||||
"node-gyp-build": "^4.3.0"
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||
},
|
||||
"ieee754": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz",
|
||||
"integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ=="
|
||||
},
|
||||
"level": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/level/-/level-8.0.0.tgz",
|
||||
"integrity": "sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ==",
|
||||
"requires": {
|
||||
"browser-level": "^1.0.1",
|
||||
"classic-level": "^1.2.0"
|
||||
}
|
||||
},
|
||||
"level-supports": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-supports/-/level-supports-4.0.1.tgz",
|
||||
"integrity": "sha512-PbXpve8rKeNcZ9C1mUicC9auIYFyGpkV9/i6g76tLgANwWhtG2v7I4xNBUlkn3lE2/dZF3Pi0ygYGtLc4RXXdA=="
|
||||
},
|
||||
"level-transcoder": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/level-transcoder/-/level-transcoder-1.0.1.tgz",
|
||||
"integrity": "sha512-t7bFwFtsQeD8cl8NIoQ2iwxA0CL/9IFw7/9gAjOonH0PWTTiRfY7Hq+Ejbsxh86tXobDQ6IOiddjNYIfOBs06w==",
|
||||
"requires": {
|
||||
"buffer": "^6.0.3",
|
||||
"module-error": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"module-error": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz",
|
||||
"integrity": "sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA=="
|
||||
},
|
||||
"napi-macros": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.0.0.tgz",
|
||||
"integrity": "sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg=="
|
||||
},
|
||||
"node-gyp-build": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz",
|
||||
"integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ=="
|
||||
},
|
||||
"queue-microtask": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
||||
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="
|
||||
},
|
||||
"run-parallel-limit": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz",
|
||||
"integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==",
|
||||
"requires": {
|
||||
"queue-microtask": "^1.2.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "storage",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.3",
|
||||
"level": "^8.0.0"
|
||||
}
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../core
|
||||
@@ -0,0 +1,41 @@
|
||||
require('dotenv').config()
|
||||
const {Express} = require("./core/Express");
|
||||
const { createSign, createPrivateKey, createPublicKey, generateKeyPairSync } = require("node:crypto");
|
||||
|
||||
// Import keys
|
||||
const fs = require('fs');
|
||||
let keys = JSON.parse(fs.readFileSync(__dirname+"/keys.json", 'utf8'));
|
||||
privateKey = createPrivateKey({
|
||||
key: keys.privateKey,
|
||||
type: "pkcs8",
|
||||
format: "pem",
|
||||
});
|
||||
|
||||
const express = new Express(process.env.PORT_VERIFIER, "Verifier")
|
||||
express.get('/', (_, res) => {
|
||||
res.send('Service is alive')
|
||||
});
|
||||
|
||||
express.post('/verify', (req, res) => {
|
||||
|
||||
if (!req.body.token || req.body.token !== process.env.API_TOKEN_VERIFIER) {
|
||||
res.status(401).send('Not authorized');
|
||||
} else {
|
||||
if (!req.body.message) {
|
||||
res.status(403).send("Bad request");
|
||||
} else {
|
||||
let message = req.body.message;
|
||||
|
||||
const sign = createSign("SHA256");
|
||||
sign.write(JSON.stringify(message));
|
||||
sign.end();
|
||||
const signature = sign.sign(privateKey, "hex");
|
||||
message.value.verifierSign = signature;
|
||||
message.value.verifierSignDatetime = new Date().getTime();
|
||||
|
||||
console.log("Event Verified with signature: " + signature);
|
||||
res.status(200).send(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
express.run();
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"privateKey": "-----BEGIN PRIVATE KEY-----\nMH4CAQAwEAYHKoZIzj0CAQYFK4EEAAMEZzBlAgEBBB4ZmdYNf803bxRz3xL1xnDS\nXv1v+Dfwc6wRRLbJ+FehQAM+AAQuAPvrX/vQiNsm0yQvMZET1nA0jfJBLo2c0ygE\nlPNNIra6yO5Y+PjFa+rCIlDH8W+s894BJLH9ylJWai4=\n-----END PRIVATE KEY-----\n",
|
||||
"publicKey": "-----BEGIN PUBLIC KEY-----\nMFIwEAYHKoZIzj0CAQYFK4EEAAMDPgAELgD761/70IjbJtMkLzGRE9ZwNI3yQS6N\nnNMoBJTzTSK2usjuWPj4xWvqwiJQx/FvrPPeASSx/cpSVmou\n-----END PUBLIC KEY-----\n"
|
||||
}
|
||||
Generated
+31
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "verifier",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "verifier",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "verifier",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.0.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
services=( manager verifier storage reader publisher )
|
||||
|
||||
teardown_service() {
|
||||
pushd $1; pm2 stop $1; pm2 delete $1; rm -rf node_modules; popd
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
pm2 stop $1
|
||||
}
|
||||
|
||||
start_service() {
|
||||
pushd $1; npm i; pm2 start index.js --name $1 --watch; popd
|
||||
}
|
||||
|
||||
stop() {
|
||||
for s in ${services[@]}
|
||||
do
|
||||
stop_service $s
|
||||
done
|
||||
pm2 flush
|
||||
}
|
||||
|
||||
start() {
|
||||
pushd core; npm i; popd
|
||||
for s in ${services[@]}
|
||||
do
|
||||
start_service $s
|
||||
done
|
||||
}
|
||||
|
||||
start2() {
|
||||
pushd core; npm i; popd
|
||||
for s in ${services[@]}
|
||||
do
|
||||
installDeps $s
|
||||
done
|
||||
|
||||
pm2 start ecosystem.config.js;
|
||||
pm2 logs;
|
||||
}
|
||||
|
||||
installDeps() {
|
||||
pushd $1; npm i; popd
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start2
|
||||
}
|
||||
|
||||
teardown() {
|
||||
for s in ${services[@]}
|
||||
do
|
||||
teardown_service $s
|
||||
done
|
||||
pushd core; rm -rf node_modules; popd
|
||||
}
|
||||
$@
|
||||
Reference in New Issue
Block a user