Installation
This guide will help you set up Gatekeeper and Keymaster for Sign In With Yourself (SIWYS).
Gatekeeper is a service that manages identity keys and enforces security policies. Keymaster is a node.js client library that interacts with Gatekeeper to handle identity operations.
Prerequisites
This guide is written for a Linux or MacOS environment. Windows users may need to adapt some commands accordingly. Ensure you have the following prerequisites installed:
- Git
- Node.js (version 20 or higher)
- npm or Yarn
- Docker
Gatekeeper
-
Clone and download the keychain repository:
git clone https://github.com/KeychainMDIP/kc -
Navigate to the Gatekeeper directory and install dependencies:
cd kc/packages/gatekeeper
npm i -
Build packages & services:
npm run build -
Start Gatekeeper Services:
./start-node
This will start the Gatekeeper service on the default port (3000). You can configure the port and other settings in the config file located in the kc/packages/gatekeeper directory.
Keymaster
NOTE: The Keymaster SDK is available for further review here before creating an attestation.
Add Keymaster to Your Project
- NPM
- Yarn
npm i @yourself_id/siwys-api-js
yarn add @yourself_id/siwys-api-js
Usage
import { Keymaster } from "@yourself_id/siwys-api-js";
const WALLET_PASSPHRASE = process.env.WALLET_PASSPHRASE;
const GATEKEEPER_URL = process.env.GATEKEEPER_URL;
export class Wallet {
async saveWallet(wallet: StoredWallet, overwrite = false): Promise<boolean> {
// save wallet data to configured location - fs, Cloud Storage, S3, etc
}
async loadWallet(): Promise<WalletFile | null> {
// retrieve wallet data from configured location - fs, Cloud Storage, S3, etc
}
}
export async function startKeymaster(): Promise<void> {
if (!GATEKEEPER_URL) {
throw new Error("GATEKEEPER_URL not configured");
}
try {
const wallet = new Wallet();
if (!WALLET_PASSPHRASE) {
throw new Error("WALLET_PASSPHRASE not configured");
}
Keymaster.initialize({
gatekeeperConfig: { GATEKEEPER_URL },
walletConfig: { id: "<YOUR_WALLET_ID>", registry: "hyperswarm" },
walletDb: wallet,
passphrase: WALLET_PASSPHRASE,
});
log(`Starting Keymaster service.`);
await Keymaster.start();
log(`Keymaster service ready.`);
} catch (e: any) {
log("Error starting Keymaster service", e);
throw new Error(e.toString());
}
}