Browse Source

write improved README

Kieran Gibb 2 years ago
parent
commit
1ae74ec9fb
No known key found for this signature in database
2 changed files with 65 additions and 1 deletions
  1. 22
    1
      README.md
  2. 43
    0
      example.js

+ 22
- 1
README.md View File

@@ -1,5 +1,26 @@
1 1
 # cobox-admin-group
2 2
 
3
-An admin group is like a special kind of cobox-group. Rather than managing an archive of files together, it represents the group who manage a cobox hardware device, allowing them to control which groups it replicates.
3
+An admin group is like a special kind of `cobox-group`. Rather than managing an archive of files together, it represents the group who manage a cobox hardware device, the admin group, allowing them to control which groups it replicates.
4 4
 
5 5
 This is done by sending encrypted messages to [cobox-hub](https://ledger-git.dyne.org/CoBox/cobox-hub).
6
+
7
+An admin group simply contains a `cobox-log` which uses a `kappa-core` and `multifeed` instance, inherited from `cobox-replicator`, `kappa-view-query` for querying the log, and wraps it all with a cryptographic value encoder so the log is fully encrypted.
8
+
9
+```js
10
+const crypto = require('cobox-crypto')
11
+const Admin = require('./')
12
+
13
+const storage = tmp()
14
+const address = crypto.address()
15
+const encryptionKey = crypto.encryptionKey()
16
+const admin = Admin(storage, address, { encryptionKey })
17
+
18
+let query = { $filter: { value: { type: 'peer/about' } } }
19
+let stream = admin.log.read({ query })
20
+stream.on('data', console.log)
21
+
22
+admin.log.publish({ type: 'peer/about', content: { name: 'Magpie' } })
23
+admin.swarm()
24
+```
25
+
26
+## Contributions

+ 43
- 0
example.js View File

@@ -0,0 +1,43 @@
1
+const crypto = require('cobox-crypto')
2
+const Admin = require('./')
3
+const tmpdir = require('tmp').dirSync
4
+const mkdirp = require('mkdirp')
5
+const { encodings } = require('cobox-schemas')
6
+
7
+const PeerAbout = encodings.peer.about
8
+
9
+function tmp () {
10
+  var path = '.'+tmpdir().name
11
+  mkdirp.sync(path)
12
+  return path
13
+}
14
+
15
+function hex (buf) {
16
+  if (Buffer.isBuffer(buf)) return buf.toString('hex')
17
+  else return buf
18
+}
19
+
20
+async function Application () {
21
+  const storage = tmp()
22
+  const address = crypto.address()
23
+  const encryptionKey = crypto.encryptionKey()
24
+  const identity = crypto.boxKeyPair()
25
+  const admin = Admin(storage, address, { encryptionKey, identity })
26
+
27
+  await admin.ready()
28
+
29
+  let query = [{ $filter: { value: { type: 'peer/about', timestamp: { gt: 0 } } } }]
30
+
31
+  admin.log.read({ query }).on('data', console.log)
32
+
33
+  await admin.log.publish(PeerAbout.encode({
34
+    type: 'peer/about',
35
+    author: hex(identity.publicKey),
36
+    timestamp: Date.now(),
37
+    content: { name: 'magpie' }
38
+  }))
39
+
40
+  admin.swarm()
41
+}
42
+
43
+Application()