Note: This repo is obsolete, instead see:
https://github.com/digitalbazaar/edv-client https://github.com/digitalbazaar/bedrock-web-pouch-edv
A Javascript library for Bedrock web apps, for interfacing with a remote Data Hub server
This library is a client that Bedrock web apps can use to interface with remote Data Hub servers (for example, it's used by the Bedrock VC Store lib).
It consists of two main classes:
DataHubService
- stores and managesDataHub
configs with a remote Data Hub storage server. Used to create or fetchDataHub
instances.DataHub
- provides a CRUD (+ find) interface to a specific Data Hub. Also ensures appropriate db indexes are set up, and provides some key management under the hood.
To install locally (for development):
git clone https://github.com/digitalbazaar/bedrock-web-data-hub.git
cd bedrock-web-data-hub
npm install
(Optional) Also install test dependencies:
cd test
npm install
cd ..
First, create a DataHubService
instance:
import {AccountMasterKey, KmsService} from 'bedrock-web-kms';
import {DataHub, DataHubService} from 'bedrock-web-data-hub';
// Create a `DataHubService` instance (which can be used to create DataHub instances)
const dhs = new DataHubService();
Although you can use Data Hubs while doing your own key management, we
recommend that you set up a Key Management Service
(bedrock-web-kms
) instance
first.
Optional:
// Create a Master Key (via a key management service)
const kmsService = new KmsService();
// TODO: Explain kmsPlugin and accountId
const masterKey = await AccountMasterKey.fromSecret({secret, accountId, kmsService, kmsPlugin});
// Use the Master Key to create KEK and HMAC keys
const kek = await masterKey.generateKey({type: 'kek'}); // Key Encryption Key
const hmac = await masterKey.generateKey({type: 'hmac'});
Now you can create and register a new DataHub
configuration:
const controller = 'account id goes here';
const primary = true; // TODO: Explain what a primary data hub is
const config = {
sequence: 0, // TODO: is sequence required?
controller,
primary,
kek: {id: kek.id, algorithm: kek.algorithm},
hmac: {id: hmac.id, algorithm: hmac.algorithm}
};
const remoteConfig = await dhs.create({config}); // sends a POST request to the remote service
const hub = new DataHub({config: remoteConfig, kek, hmac});
If you have previously registered a DataHub config (via create()
), and you
know its id
, you can fetch its config via get()
:
// previously registered config
const {id} = await dhs.create({config});
// later, it can be fetched via the id
const remoteConfig = await dhs.get({id});
const hub = new DataHub({config: remoteConfig, kek, hmac});
If you know a controller/accountId
but do not know a specific hub id
, you can
request "primary registered data hub for a given account":
const remoteConfig = await dhs.getPrimary({controller: accountId});
const hub = new DataHub({config: remoteConfig, kek, hmac});
See the API section below.
See the contribute file!
PRs accepted.
If editing the Readme, please conform to the standard-readme specification.
Commercial support for this library is available upon request from Digital Bazaar: [email protected]
Bedrock Non-Commercial License v1.0 © Digital Bazaar