Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 1ef784d

Browse files
authored
Merge pull request #13 from orbitdb/feat/identity
Database identity.
2 parents 9e60b20 + 52e1316 commit 1ef784d

File tree

3 files changed

+98
-44
lines changed

3 files changed

+98
-44
lines changed

README.md

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@
1818
- [Modulus Query](#modulus-query)
1919
- [Range Query](#range-query)
2020
- [GET /db/:dbname/:item](#get-dbdbnameitem)
21-
- [POST /db/:dbname](#post-dbdbname)
2221
- [GET /db/:dbname/iterator](#get-dbdbnameiterator)
2322
- [GET /db/:dbname/index](#get-dbdbnameindex)
23+
- [GET /identity](#get-identity)
24+
- [POST /db/:dbname](#post-dbdbname)
25+
- [POST|PUT /db/:dbname/add](#post-put-dbdbnameadd)
26+
- [POST|PUT /db/:dbname/put](#post-put-dbdbnameput)
27+
- [POST|PUT /db/:dbname/inc](#post-put-dbdbnameinc)
28+
- [POST|PUT /db/:dbname/inc/:val](#post-put-dbdbnameincval)
29+
- [DELETE /db/:dbname](#delete-dbdbname)
30+
- [DELETE /db/:dbname/:item](#delete-dbdbnameitem)
31+
- [Contribute](#contribute)
32+
- [License](#license)
2433

2534
## Install
2635

@@ -185,49 +194,6 @@ curl -X GET http://localhost:3000/db/docstore/1
185194
[{"_id":1, "value": "test"}]
186195
```
187196

188-
### POST /db/:dbname
189-
190-
Creates a new database and returns information about the newly created database
191-
or opens an existing database with the same name.
192-
193-
Returns information about the database as a JSON object.
194-
195-
The OrbitDB options ```create=true``` and ```type=eventlog|feed|docstore|keyvalue|counter```
196-
must be sent with the POST otherwise an error is thrown.
197-
198-
```shell
199-
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore"
200-
```
201-
202-
```json
203-
{"address":{"root":"zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq","path":"docstore"},"dbname":"docstore","id":"/orbitdb/zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq/docstore","options":{"create":"true","indexBy":"_id","localOnly":false,"maxHistory":-1,"overwrite":true,"replicate":true},"type":"docstore"}
204-
```
205-
206-
Additional OrbitDB-specific flags can also be passed. For example, if the index
207-
field must be changed then the indexBy flag can be specified as an additional
208-
POST param (this would apply to type docstore only):
209-
210-
```shell
211-
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore" -d "indexBy=name"
212-
```
213-
214-
To open an existing database, specify the address of the database. If the
215-
database does not exist locally it will be fetched from the swarm.
216-
217-
The address MUST be URL escaped.
218-
219-
```shell
220-
curl -X POST http://localhost:3000/db/zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq%2Fdocstore
221-
```
222-
223-
By default, OrbitDB will open the database if one already exists with the same
224-
name. To always overwrite the existing database with a new one, pass the
225-
overwrite flag:
226-
227-
```shell
228-
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore" -d "overwrite=true"
229-
```
230-
231197
### GET /db/:dbname/iterator
232198

233199
Gets items from an eventlog or feed database :dbname.
@@ -292,6 +258,70 @@ The counter data store returns information about the current counter value:
292258
{"id":"04e6de9dd0e8d0069bcc6d8f3ef11cefe63bba6129c32f2cd422a0394814bc6723b26eb62731ee466020b0394d01dd08e4a5123eaad45e4d0840fd796652a22e42","counters":{"04e6de9dd0e8d0069bcc6d8f3ef11cefe63bba6129c32f2cd422a0394814bc6723b26eb62731ee466020b0394d01dd08e4a5123eaad45e4d0840fd796652a22e42":15}}
293259
```
294260

261+
### GET /identity
262+
263+
Gets the identity information.
264+
265+
Returns identity as a JSON object.
266+
267+
```shell
268+
curl -X GET http://localhost:3000/identity
269+
```
270+
271+
```json
272+
{"id":"03fc293ea95bdb5dea71d5d21cbbae2a57f2d2002c9966f0d5c7b0bda232d5934d","publicKey":"048161d9685991dc87f3e049aa04b1da461fdc5f8a280ed6234fa41c0f9bc98a1ce91f07494584a45b97160ac818e100a6b27777e0b1b09e6ba4795dcc797a6d8b","signatures":{"id":"3045022100e40ab2dcc83dde17c939d5515ce322e7f81bf47536ab342582db8c35f28d2a720220228e418cc3d2f3e0004d5f4292c0d2cf7975c93073e0cc831f0cb849e4ac920a","publicKey":"3045022100ad18ba66006e19e2952eabc9ffb532dd69d60593f90448a05d6f4903c2931e3502204009975030b839522c668cd693d357bf1f3d0423d604a6bc10645425a0a3dd1b"},"type":"orbitdb"}
273+
```
274+
275+
### POST /db/:dbname
276+
277+
Creates a new database and returns information about the newly created database
278+
or opens an existing database with the same name.
279+
280+
Returns information about the database as a JSON object.
281+
282+
The OrbitDB options ```create=true``` and ```type=eventlog|feed|docstore|keyvalue|counter```
283+
must be sent with the POST otherwise an error is thrown.
284+
285+
```shell
286+
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore"
287+
```
288+
289+
```json
290+
{"address":{"root":"zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq","path":"docstore"},"dbname":"docstore","id":"/orbitdb/zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq/docstore","options":{"create":"true","indexBy":"_id","localOnly":false,"maxHistory":-1,"overwrite":true,"replicate":true},"type":"docstore"}
291+
```
292+
293+
Additional OrbitDB-specific flags can also be passed. For example, if the index
294+
field must be changed then the indexBy flag can be specified as an additional
295+
POST param (this would apply to type docstore only):
296+
297+
```shell
298+
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore" -d "indexBy=name"
299+
```
300+
301+
Parameters can also be passed as JSON. This is useful if additional parameters
302+
such as accessController need to be specified:
303+
304+
```shell
305+
curl -H "Content-Type: application/json" --data '{"create":"true","type":"feed","accessController":{"type": "orbitdb","write": ["1234"]}}'
306+
```
307+
308+
To open an existing database, specify the address of the database. If the
309+
database does not exist locally it will be fetched from the swarm.
310+
311+
The address MUST be URL escaped.
312+
313+
```shell
314+
curl -X POST http://localhost:3000/db/zdpuAmnfJZ6UTssG5Ns3o8ALXZJXVx5eTLTxf7gfFzHxurbJq%2Fdocstore
315+
```
316+
317+
By default, OrbitDB will open the database if one already exists with the same
318+
name. To always overwrite the existing database with a new one, pass the
319+
overwrite flag:
320+
321+
```shell
322+
curl http://localhost:3000/db/docstore -d "create=true" -d "type=docstore" -d "overwrite=true"
323+
```
324+
295325
### POST|PUT /db/:dbname/add
296326

297327
Adds a new entry to the eventlog or feed database :dbname.

src/lib/db-manager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class DBManager {
8484
)
8585
};
8686
};
87+
88+
this.identity = () => {
89+
return orbitdb.identity;
90+
};
8791
}
8892
}
8993

src/lib/orbitdb-api.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,26 @@ class OrbitdbAPI extends Express {
201201
return contents
202202
}
203203

204+
this.get('/identity', (req, res, next) => {
205+
try {
206+
const identity = dbm.identity()
207+
return res.json(identity)
208+
} catch(err) {
209+
next(err)
210+
}
211+
});
212+
213+
var db_put_write_public_key = asyncMiddleware( async (req, res, next) => {
214+
let db
215+
db = await dbm.get(req.params.dbname)
216+
await db.access.grant('write', req.body.publicKey)
217+
218+
return res.json('')
219+
});
220+
221+
this.post('/db/:dbname/access/write', db_put_write_public_key);
222+
this.put('/db/:dbname/access/write', db_put_write_public_key);
223+
204224
this.get('/db/:dbname/:item', asyncMiddleware( async (req, res, next) => {
205225
let result, contents
206226
contents = await getraw(req,res, next)

0 commit comments

Comments
 (0)