We need to enhance the Gatekeeper API to support querying for DIDs that have been updated within a specified time window. This functionality is analogous to querying blockchain transactions within a block range. Since MDIP does not utilize blocks, we will use time-based arguments to achieve similar functionality.
Requirements:
New API Endpoint: Create a new endpoint in the Gatekeeper API to return DIDs that have been updated within a specified time window.
Database Query Optimization: Implement MongoDB queries to efficiently filter and return documents based on the events.time field within the specified range within the events array.
Implementation Details:
1. Update db-mongodb.js:
Add a new method to filter DIDs based on the events.time field within a specified time window.
export async function getDIDsUpdatedWithinTimeWindow(startTime, endTime) {
if (!startTime || !endTime) {
throw "Invalid time window";
}
const updatedDIDs = await db.collection('dids').find({
events: {
$elemMatch: {
time: { $gte: new Date(startTime), $lte: new Date(endTime) }
}
}
}).toArray();
return updatedDIDs.map(doc => doc.id);
}
2. Update gatekeeper-lib.js:
Add a new function to use the above method and resolve the DIDs accordingly.
import * as db from './db-mongodb.js'; // Ensure MongoDB is the default db
import * as cipher from './cipher-lib.js';
import config from './config.js';
export async function getDIDsUpdatedWithinTimeWindow(startTime, endTime) {
if (!startTime || !endTime) {
throw "Invalid time window";
}
const dids = await db.getDIDsUpdatedWithinTimeWindow(startTime, endTime);
const resolvedDIDs = [];
for (const did of dids) {
const resolvedDID = await resolveDID(did, endTime);
resolvedDIDs.push(resolvedDID);
}
return resolvedDIDs;
}
3. Update gatekeeper-api.js:
Add a new route to handle the request for querying DIDs within the specified time window.
This feature is essential for enhancing the Gatekeeper API's functionality, enabling users to query DIDs based on their update time, similar to querying transactions within a block range in blockchain systems. It provides a time-based filtering mechanism necessary for applications that need to track changes over specific periods.
Impact:
This change will improve the flexibility and usability of the Gatekeeper API, making it more powerful and aligned with common practices in blockchain-based systems. It will also provide a robust method for querying DID updates, enhancing data retrieval and analysis capabilities within the MDIP ecosystem.
Overview:
We need to enhance the Gatekeeper API to support querying for DIDs that have been updated within a specified time window. This functionality is analogous to querying blockchain transactions within a block range. Since MDIP does not utilize blocks, we will use time-based arguments to achieve similar functionality.
Requirements:
events.time
field within the specified range within theevents
array.Implementation Details:
1. Update
db-mongodb.js
:Add a new method to filter DIDs based on the
events.time
field within a specified time window.2. Update
gatekeeper-lib.js
:Add a new function to use the above method and resolve the DIDs accordingly.
3. Update
gatekeeper-api.js
:Add a new route to handle the request for querying DIDs within the specified time window.
Justification:
This feature is essential for enhancing the Gatekeeper API's functionality, enabling users to query DIDs based on their update time, similar to querying transactions within a block range in blockchain systems. It provides a time-based filtering mechanism necessary for applications that need to track changes over specific periods.
Impact:
This change will improve the flexibility and usability of the Gatekeeper API, making it more powerful and aligned with common practices in blockchain-based systems. It will also provide a robust method for querying DID updates, enhancing data retrieval and analysis capabilities within the MDIP ecosystem.