Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha DID format #47

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import dotenv from 'dotenv';
dotenv.config();

const config = {
gatekeeperPort: process.env.GATEKEEPER_PORT || 4224,
gatekeeperURL: process.env.GATEKEEPER_URL || 'http://localhost',
didPrefix: process.env.KC_DID_PREFIX || "did:mdip:test",
gatekeeperPort: process.env.KC_GATEKEEPER_PORT || 4224,
gatekeeperURL: process.env.KC_GATEKEEPER_URL || 'http://localhost',
};

export default config;
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ services:
dockerfile: Dockerfile.hyperswarm
image: macterra/hyperswarm-mediator
environment:
- GATEKEEPER_URL=http://gatekeeper
- GATEKEEPER_PORT=4224
- KC_GATEKEEPER_URL=http://gatekeeper
- KC_GATEKEEPER_PORT=4224
volumes:
- ./data:/app/data
depends_on:
Expand Down
11 changes: 6 additions & 5 deletions gatekeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FsBlockstore } from 'blockstore-fs';
import { performance } from 'perf_hooks';

import * as cipher from './cipher.js';
import config from './config.js';

const dataFolder = 'data';
export const dbName = `${dataFolder}/mdip.json`;
Expand Down Expand Up @@ -47,6 +48,10 @@ export async function verifyDb() {
for (const did of dids) {
n += 1;
try {
if (!did.startsWith(config.didPrefix)) {
throw "Invalid DID";
}

const doc = await resolveDID(did, null, true);
console.log(`${n} ${did} OK`);
}
Expand Down Expand Up @@ -123,7 +128,7 @@ export async function anchorSeed(seed) {
// console.log("Adding seed to IPFS took " + (t1 - t0) + " milliseconds.");

const cid = await ipfs.add(JSON.parse(canonicalize(seed)));
const did = `did:mdip:${cid.toString(base58btc)}`;
const did = `${config.didPrefix}:${cid.toString(base58btc)}`;
const db = loadDb();

if (!db.anchors) {
Expand Down Expand Up @@ -228,10 +233,6 @@ export async function createDID(operation) {
}

async function getAnchor(did) {
// const suffix = did.split(':').pop(); // everything after "did:mdip:"
// const cid = CID.parse(suffix);
// const docSeed = await ipfs.get(cid);

const db = loadDb();
const docSeed = db.anchors[did];

Expand Down
4 changes: 0 additions & 4 deletions gatekeeper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('generateDid', () => {
};
const did = await gatekeeper.generateDID(mockTxn);

expect(did.length).toBe(60);
expect(did.startsWith('did:mdip:'));
});

Expand Down Expand Up @@ -143,7 +142,6 @@ describe('createDID', () => {

const did = await gatekeeper.createDID(agentTxn);

expect(did.length).toBe(60);
expect(did.startsWith('did:mdip:'));
});

Expand All @@ -155,7 +153,6 @@ describe('createDID', () => {

const did = await gatekeeper.createDID(agentTxn);

expect(did.length).toBe(60);
expect(did.startsWith('did:mdip:'));
});

Expand Down Expand Up @@ -197,7 +194,6 @@ describe('createDID', () => {

const did = await gatekeeper.createDID(assetTxn);

expect(did.length).toBe(60);
expect(did.startsWith('did:mdip:'));
});
});
Expand Down
2 changes: 1 addition & 1 deletion hyperswarm-mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import config from './config.js';
import { EventEmitter } from 'events';
EventEmitter.defaultMaxListeners = 100;

const protocol = '/MDIP/v22.03.20';
const protocol = '/MDIP/v22.03.21';

const swarm = new Hyperswarm();
const peerName = b4a.toString(swarm.keyPair.publicKey, 'hex');
Expand Down
Loading