@mdip/gatekeeper
v2.2.0
Published
MDIP Gatekeeper
Readme
MDIP Gatekeeper
Gatekeeper is a node library for the MDIP. It manages a local database of DIDs on the MDIP network. Gatekeeper functions are used to Create, Read, Update, and Delete DIDs (CRUD).
Installation
npm install @mdip/gatekeeperUsage
Library
Construct the library with one of the supported database adapters:
- JSON - @mdip/gatekeeper/db/json
- JSON with memory cache - @mdip/gatekeeper/db/json-cache
- SQLite - @mdip/gatekeeper/db/sqlite
- MongoDB - @mdip/gatekeeper/db/mongo
- Redis - @mdip/gatekeeper/db/redis
- PostgreSQL - @mdip/gatekeeper/db/postgres
The MongoDB adapter requires a replica set or sharded cluster because DID/block writes and index cursor writes are committed in MongoDB transactions. For local Docker Compose usage, the repository starts MongoDB as a single-node replica set named rs0. Standalone MongoDB deployments must be updated before using the adapter.
import Gatekeeper from '@mdip/gatekeeper';
import DbRedis from '@mdip/gatekeeper/db/redis';
const db_redis = new DbRedis('mdip-test');
await db_redis.start();
const gatekeeper = new Gatekeeper({ db: db_redis, ipfsEnabled: false });
const did = 'did:test:z3v8AuaTV5VKcT9MJoSHkSTRLpXDoqcgqiKkwGBNSV4nVzb6kLk';
const docs = await gatekeeper.resolveDID(did);
console.log(JSON.stringify(docs, null, 4));Client
The GatekeeperClient is used to communicate with a Gatekeeper REST API service.
import GatekeeperClient from '@mdip/gatekeeper/client';
// Try connecting to the gatekeeper service every second,
// and start reporting (chatty) if not connected after 5 attempts
const gatekeeper = new GatekeeperClient();
await gatekeeper.connect({
url: 'http://gatekeeper-host:4224',
waitUntilReady: true,
intervalSeconds: 1,
chatty: false,
becomeChattyAfter: 5
});
const did = 'did:test:z3v8AuaTV5VKcT9MJoSHkSTRLpXDoqcgqiKkwGBNSV4nVzb6kLk';
const docs = await gatekeeper.resolveDID(did);
console.log(JSON.stringify(docs, null, 4));