Skip to content

Commit 595da65

Browse files
committed
Initial release
0 parents  commit 595da65

13 files changed

Lines changed: 1765 additions & 0 deletions

.eslintrc.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2015": true
5+
},
6+
"globals":{
7+
"ENV": true
8+
},
9+
"parser": "babel-eslint",
10+
"extends": "eslint:recommended",
11+
"parserOptions": {
12+
"ecmaVersion": 6,
13+
"sourceType": "module"
14+
},
15+
"rules": {
16+
"indent": [
17+
"error",
18+
2
19+
],
20+
"linebreak-style": [
21+
"error",
22+
"unix"
23+
],
24+
"quotes": [
25+
"error",
26+
"double"
27+
],
28+
"semi": [
29+
"error",
30+
"always"
31+
]
32+
}
33+
}

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
logs/
2+
cert/
3+
.vs/
4+
*.log
5+
*.so
6+
*.node
7+
*cfg.json
8+
node_modules/
9+
psub/node_modules/
10+
npm-debug.log*
11+
typings.json
12+
pids/
13+
release/
14+
*.pid
15+
*.seed
16+
lib-cov/
17+
coverage/
18+
*.nyc_output
19+
*.grunt
20+
*.lock-wscript
21+
build/Release/
22+
jspm_packages/
23+
typings/
24+
*.npm
25+
*.node_repl_history
26+
__pycache__/
27+
venv/
28+
package-lock.json

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## 1.0.1
4+
5+
* Initial release.
6+

Dependencies.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# External Dependencies
2+
3+
This file lists the dependencies used in this repository.
4+
5+
| Dependency | License |
6+
| --------------------- | ---------- |
7+
| tweetnacl@(^1.0.3) | Unlicense |
8+
| tweetnacl-util@(^0.15.1) | Unlicense |

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
Copyright 2022 Optomate Technologies Private Limited.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining
5+
a copy of this software and associated documentation files (the
6+
"Software"), to deal in the Software without restriction, including
7+
without limitation the rights to use, copy, modify, merge, publish,
8+
distribute, sublicense, and/or sell copies of the Software, and to
9+
permit persons to whom the Software is furnished to do so, subject to
10+
the following conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
![](https://img.shields.io/badge/Licence-MIT-green.svg)![](https://shields.io/badge/node.js-%3E=10.0%20LTS-blue)
2+
3+
# Databridges JavaScript NaCl Wrapper Library
4+
5+
Databridges NACL wrapper gives you a simple write and read function using implementation of the secretbox encryption standard defined in NaCl.
6+
7+
Databridges NACL wrapper is available for
8+
9+
- [JavaScript](https://github.com/databridges-io/lib.javascript.nacl.wrapper.git)
10+
- [NodeJS](https://github.com/databridges-io/lib.nodejs.nacl.wrapper.git)
11+
- [C#](https://github.com/databridges-io/lib.csharp.nacl.wrapper.git)
12+
- [Python](https://github.com/databridges-io/lib.python.nacl.wrapper.git)
13+
- [Java for Android](https://github.com/databridges-io/lib.android.nacl.wrapper.git)
14+
- [iOS Swift](https://github.com/databridges-io/lib.ios.nacl.wrapper.git)
15+
16+
The above wrappers can be used to send encrypted messages between them.
17+
18+
> The Databridges NACL wrapper for JavaScript Language binding uses `tweetnacl` to deliver implementation of the secretbox encryption standard defined in NaCl.
19+
20+
## Usage Overview
21+
22+
The following topics are covered:
23+
24+
- [Supported platforms](#supported-platforms)
25+
- [Installation.](#installation)
26+
- [Initialization](#initialization)
27+
- [Global Configuration](#global-configuration)
28+
- [How to use with Databridges JavaScript Library](#how-to-use-with-databridges-javascript-library)
29+
- [Change Log](#change-log)
30+
- [License](#license)
31+
32+
## Supported platforms
33+
34+
| Android | Firefox | Chrome | Edge |
35+
| :-----: | :-----: | :----: | :--: |
36+
| 5.1+ | 78+ | 84+ | 99+ |
37+
38+
39+
## Initialization
40+
41+
Include databridges NaCl wrapper library from any of below CDN:
42+
43+
- **jsDelivr** :
44+
45+
```html
46+
<script src="https://cdn.jsdelivr.net/npm/databridges-js-nacl-wrapper@1.0.1/dist/databridges.nacl.wrapper.min.js" integrity="sha384-O34Ik4FhdcikoNSke8zZHqyXO1JjAn/Jw/pKdp/PYlVQcBB19JdPKZn0uz+wtd5t" crossorigin="anonymous"></script>
47+
```
48+
49+
- **unpkg** :
50+
51+
```html
52+
<script src="https://unpkg.com/databridges-js-nacl-wrapper@1.0.1/dist/databridges.nacl.wrapper.min.js" integrity="sha384-O34Ik4FhdcikoNSke8zZHqyXO1JjAn/Jw/pKdp/PYlVQcBB19JdPKZn0uz+wtd5t" crossorigin="anonymous"></script>
53+
```
54+
55+
Now initialize databridges object in your script.
56+
57+
```js
58+
const secretData = new dbNaClWrapper();
59+
```
60+
61+
## Global Configuration
62+
63+
### Required
64+
65+
The following is the required properties before using to dataBridges NaCl wrapper.
66+
67+
```javascript
68+
secretData.secret = '32 char alphanumeric string';
69+
```
70+
71+
| Properties | Description |
72+
| ---------- | ------------------------------------------------------------ |
73+
| `secret` | *(string)* 32 char alpha numeric string. NaCl encryption secret. |
74+
75+
## Encrypt data
76+
77+
To encrypt data using NaCl, databridges wrapper exposes a method named `write`, This will return encrypted data if successful else it will throw error.
78+
79+
#### write()
80+
81+
```javascript
82+
try {
83+
const encData = secretData.write("Your Data..");
84+
console.log('Encrypted:', encData);
85+
} catch (err) {
86+
console.log('Errors:', err.source, err.code, err.message);
87+
}
88+
```
89+
90+
| Parameter | Description |
91+
| --------- | ---------------------------------- |
92+
| `data` | *(string)* *data* to be encrypted. |
93+
94+
| Return Values | Description |
95+
| ------------- | ------------------ |
96+
| `string` | Encrypted string. |
97+
98+
##### Exceptions:
99+
100+
| Source | Code | Description |
101+
| ------------------ | -------------- | ---------------------------------------------- |
102+
| DBLIB_NACL_WRAPPER | INVALID_SECRET | `secret` is not set with the wrapper instance. |
103+
| DBLIB_NACL_WRAPPER | INVALID_DATA | If `data` is not passed to the function. |
104+
| DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |
105+
106+
## Decrypt data
107+
108+
To decrypt data using NaCl, databridges wrapper exposes a method named `read`, This will return decrypted data if successful else it will throw error.
109+
110+
#### read()
111+
112+
```javascript
113+
try {
114+
const decData = secretData.read("<Encrypted data.>");
115+
console.log('Decrypted:', decData);
116+
} catch (err) {
117+
console.log('Errors', err.source, err.code, err.message);
118+
}
119+
```
120+
121+
| Parameter | Description |
122+
| --------- | ---------------------------------- |
123+
| `data` | *(string)* *data* to be encrypted. |
124+
125+
| Return Values | Description |
126+
| ------------- | ------------------ |
127+
| `string` | Encrypted string. |
128+
129+
##### Exceptions:
130+
131+
| Source | Code | Description |
132+
| ------------------ | ------------------- | ------------------------------------------------------------ |
133+
| DBLIB_NACL_WRAPPER | INVALID_SECRET | `secret` is not set with the wrapper instance. |
134+
| DBLIB_NACL_WRAPPER | INVALID_DATA | If `data` is not passed to the function OR `data` is not a valid encrypted string. |
135+
| DBLIB_NACL_WRAPPER | NACL_EXCEPTION | Exceptions generated by NaCl library. |
136+
| DBLIB_NACL_WRAPPER | NACL_DECRYPT_FAILED | If decryption fails due to invalid secret or manipulated data. |
137+
138+
## How to use with Databridges JavaScript Library
139+
140+
Below code shows how to integrate the NaCl wrapper with the Databridges library. After initialize you can use the wrapper library to encrypt and decrypt the data when publishing and receiving events.
141+
142+
```javascript
143+
// Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
144+
const dBridges = require('databridges-sio-client-lib');
145+
const dbNaClWrapper = require('databridges-nacl-wrapper');
146+
147+
const dbridge = new dBridges();
148+
const secretData = new dbNaClWrapper();
149+
secretData.secret = "Your32 char secret.";
150+
151+
// .... Your databridges code comes here.
152+
153+
// On Subscription success event.
154+
subscribeChannel.bind("dbridges:subscribe.success", (payload, metadata) => {
155+
console.log('Channel subscribe => bind', metadata.eventname, payload, JSON.stringify(metadata));
156+
try {
157+
// Encrypt data to publish.
158+
const encData = secretData.write("Your Data..");
159+
subscribeChannel.publish("eventName", encData, "1")
160+
} catch (err) {
161+
console.log('Error:', err.source, err.code, err.message);
162+
}
163+
});
164+
165+
// On payload Received event.
166+
subscribeChannel.bind("eventName", (payload, metadata) => {
167+
console.log('eventName=> bind', metadata.eventname, payload, JSON.stringify(metadata));
168+
try {
169+
// Decrypt data received in the event.
170+
const decData = secretData.read(payload);
171+
console.log('Decrypted:', decData);
172+
} catch (err) {
173+
console.log('Error:', err.source, err.code, err.message);
174+
}
175+
});
176+
```
177+
178+
179+
180+
## Change Log
181+
* [Change log](CHANGELOG.md): Changes in the recent versions
182+
183+
## License
184+
185+
DataBridges NaCl Wrapper is released under the [MIT license](LICENSE).
186+
187+
```
188+
Copyright 2022 Optomate Technologies Private Limited.
189+
190+
Permission is hereby granted, free of charge, to any person obtaining
191+
a copy of this software and associated documentation files (the
192+
"Software"), to deal in the Software without restriction, including
193+
without limitation the rights to use, copy, modify, merge, publish,
194+
distribute, sublicense, and/or sell copies of the Software, and to
195+
permit persons to whom the Software is furnished to do so, subject to
196+
the following conditions:
197+
198+
The above copyright notice and this permission notice shall be
199+
included in all copies or substantial portions of the Software.
200+
201+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
202+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
203+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
204+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
205+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
206+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
207+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
208+
```
209+

dist/databridges.nacl.wrapper.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/databridges.nacl.wrapper.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "databridges-js-nacl-wrapper",
3+
"version": "1.0.1",
4+
"description": "DataBridges JavaScript NaCl wrapper for databridges library.",
5+
"keywords": [
6+
"optomate",
7+
"databridges",
8+
"pubsub",
9+
"rpc",
10+
"websocket",
11+
"socket.io",
12+
"ws",
13+
"events",
14+
"realtime",
15+
"real-time",
16+
"nacl",
17+
"encryption"
18+
],
19+
"private": false,
20+
"engines": {
21+
"node": ">= 4.2.6"
22+
},
23+
"author": {
24+
"name": "Optomate Technologies Private Limited.",
25+
"email": "tech@optomate.io",
26+
"url": "https://www.optomate.io"
27+
},
28+
"main": "src/databridges.nacl.wrapper.js",
29+
"license": "MIT",
30+
"repository": {
31+
"type": "git",
32+
"url": "https://github.com/databridges-io/lib.nodejs.nacl.wrapper.git"
33+
},
34+
"homepage": "https://github.com/databridges-io/lib.nodejs.nacl.wrapper",
35+
"deprecated": false,
36+
"devDependencies": {
37+
"@rollup/plugin-commonjs": "^22.0.1",
38+
"@rollup/plugin-json": "^4.1.0",
39+
"@rollup/plugin-node-resolve": "^13.3.0",
40+
"rollup-plugin-node-polyfills": "^0.2.1",
41+
"rollup-plugin-terser": "^7.0.2"
42+
},
43+
"dependencies": {
44+
"crypto": "^1.0.1"
45+
}
46+
}

0 commit comments

Comments
 (0)