Browse Source

add a README

Kieran Gibb 3 years ago
parent
commit
a5eb6a79f8
No account linked to committer's email address
1 changed files with 66 additions and 0 deletions
  1. 66
    0
      README.md

+ 66
- 0
README.md View File

@@ -0,0 +1,66 @@
1
+# cobox-crypto
2
+
3
+The crypto primitives used in cobox, extracted into a separate module
4
+
5
+```
6
+npm install cobox-crypto
7
+```
8
+
9
+## Usage
10
+
11
+```
12
+const Crypto = require('cobox-crypto')
13
+const crypto = Crypto()
14
+
15
+const accessKey = crypto.accessKey()
16
+```
17
+
18
+## API
19
+
20
+```js
21
+keyPair = crypto.keyPair()
22
+```
23
+
24
+Returns an `ed25519` keypair that can used for tree signing.
25
+
26
+```js
27
+const symKey = crypto.symmetricKey()
28
+```
29
+
30
+Returns an `ed25519` symmetric key used for shared secret encryption
31
+
32
+```js
33
+const accessKey = crypto.accessKey()
34
+
35
+// OR
36
+
37
+const accessKey = crypto.pack(pubKey, symKey)
38
+```
39
+
40
+Returns an access key, which consists of an `ed25519` public key, packed together with an `ed25519` symmetric key
41
+
42
+```js
43
+const keys = crypto.unpack(key)
44
+```
45
+
46
+Returns an object containing a public key, and a shared secret if accessible. Public key alone is used for blind replication. The shared secret can then be used for decryption.
47
+
48
+```js
49
+const valueEncoding = crypto.encoder(encryptionKey, {})
50
+```
51
+
52
+Returns a message encoder used for encrypting messages in hypercore. Can be passed to hypercore doing the following:
53
+
54
+```
55
+const accessKey = crypto.accessKey
56
+const keys = crypto.unpack(accessKey)
57
+var feed = hypercore(storage, keys.publicKey, {
58
+  valueEncoding: crypto.encoder(keys.symmetricKey, { valueEncoding: 'utf-8' })
59
+})
60
+
61
+feed.ready(() => {
62
+  feed.append("this is going to be encrypted", (err, seq) => {
63
+    // do other stuff...
64
+  })
65
+})
66
+```