thingy-crypto-node 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +57 -0
- package/index.js +44 -0
- package/package.json +24 -0
- package/unbreaker.js +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
|
|
3
|
+
|
|
4
|
+
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and
|
|
5
|
+
successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
|
|
6
|
+
|
|
7
|
+
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 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.
|
|
8
|
+
|
|
9
|
+
For more information, please refer to <http://unlicense.org/>
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# thingy-crypto-node
|
|
2
|
+
|
|
3
|
+
# Background
|
|
4
|
+
Thingy Nodes usually have an assymetric keypair - this way all authentication works between the nodes in the thingy-ecosystem.
|
|
5
|
+
The thingy-crypto-node is the keeper of the keypair of this node - implementing all basic crypto functionality for this specific keypair.
|
|
6
|
+
|
|
7
|
+
# Usage
|
|
8
|
+
Current Functionality
|
|
9
|
+
---------------------
|
|
10
|
+
```coffescript
|
|
11
|
+
import { ThingyCryptoNode } from "thingy-crypto-node"
|
|
12
|
+
|
|
13
|
+
options = {
|
|
14
|
+
secretKeyHex: "..." # required
|
|
15
|
+
publicKeyHex: "..." # required
|
|
16
|
+
context: "..." # optional
|
|
17
|
+
}
|
|
18
|
+
cryptoNode = new ThingyCryptoNode(options)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Signing and Verifiying
|
|
22
|
+
content = STRING
|
|
23
|
+
signatureHex = await cryptoNode.sign(content)
|
|
24
|
+
signatureHex = STRINGHEX
|
|
25
|
+
|
|
26
|
+
true = await cryptoNode.verify(signatureHex, content)
|
|
27
|
+
|
|
28
|
+
## Encrypting and Decrypting
|
|
29
|
+
content = STRING
|
|
30
|
+
secretsObject = await cryptoNode.encrypt(content)
|
|
31
|
+
secretsObject = { referencePointHex, encryptedContentHex }
|
|
32
|
+
secretsObject = { STRINGHEX, STRINGHEX }
|
|
33
|
+
|
|
34
|
+
content = await cryptoNode.decrypt(secretsObject)
|
|
35
|
+
|
|
36
|
+
## DiffieHellman For shared secret with specific foreign node
|
|
37
|
+
id = STRINGHEX64
|
|
38
|
+
salt = STRING
|
|
39
|
+
timestamp = NUMBER
|
|
40
|
+
sharedSecretHex = await cryptoNode.diffieHellmanFor(id, salt, timestamp)
|
|
41
|
+
sharedSecretHex = STRINGHEX128
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
# Further steps
|
|
48
|
+
|
|
49
|
+
- Add more features when the requirement pops up.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
All sorts of inputs are welcome, thanks!
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
# License
|
|
57
|
+
[Unlicense JhonnyJason style](https://hackmd.io/nCpLO3gxRlSmKVG3Zxy2hA?view)
|
package/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
|
2
|
+
//###########################################################
|
|
3
|
+
var defaultContext;
|
|
4
|
+
|
|
5
|
+
import * as secUtl from "secret-manager-crypto-utils";
|
|
6
|
+
|
|
7
|
+
//###########################################################
|
|
8
|
+
defaultContext = "standard ThingyCryptoNode";
|
|
9
|
+
|
|
10
|
+
//###########################################################
|
|
11
|
+
export var ThingyCryptoNode = class ThingyCryptoNode {
|
|
12
|
+
constructor(o) {
|
|
13
|
+
this.key = o.secretKeyHex;
|
|
14
|
+
this.id = o.publicKeyHex;
|
|
15
|
+
this.ctx = o.context;
|
|
16
|
+
if (this.ctx == null) {
|
|
17
|
+
this.ctx = defaultContext;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#######################################################
|
|
22
|
+
async sign(content) {
|
|
23
|
+
return (await secUtl.createSignatureHex(content, this.key));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async verify(sig, content) {
|
|
27
|
+
return (await secUtl.verifyHex(sig, this.id, content));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async encrypt(content) {
|
|
31
|
+
return (await secUtl.asymmetricEncryptHex(content, this.id));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async decrypt(secretsObj) {
|
|
35
|
+
return (await secUtl.asymmetricDecryptHex(secretsObj, this.key));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async diffieHellmanFor(id, salt, timestamp) {
|
|
39
|
+
var context;
|
|
40
|
+
context = `${salt}:${this.ctx}_${timestamp}`;
|
|
41
|
+
return (await secUtl.diffieHellmanSecretHashHex(this.key, id, context));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "thingy-crypto-node",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The thingy-crypto-node is the keeper of an ed25519 keypair, implementing all basic crypto functionality for this specific keypair",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": ["thingy", "crypto", "encryption", "signature", "ed25519", "el-gamal","diffie-hellman"],
|
|
10
|
+
"author": "Lenard Frommelt lenard@frommelt.dev",
|
|
11
|
+
"license": "Unlicense",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/JhonnyJason/thingy-crypto-node.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/JhonnyJason/thingy-crypto-node/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/JhonnyJason/thingy-crypto-node-output#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"secret-manager-crypto-utils": "^0.3.0"
|
|
22
|
+
},
|
|
23
|
+
"type": "module"
|
|
24
|
+
}
|
package/unbreaker.js
ADDED