Skip to content

Commit 4603908

Browse files
committed
temporary change in protocols configure/query behavior
1 parent 761a21f commit 4603908

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

packages/api/src/dwn-api.ts

+4-18
Original file line numberDiff line numberDiff line change
@@ -437,25 +437,9 @@ export class DwnApi {
437437

438438
if (this.delegateDid) {
439439
// NOTE: currently protocol configure only allows normal permission grants, not delegated grants.
440-
// However, protocol grants should be used in a delegated scenario as they modify state.
441-
// Additionally currently ProtocolConfigure does not scope to specific protocols, which it should.
442440
// TODO: Add Delegate Grants to ProtocolConfigure https://github.com/TBD54566975/dwn-sdk-js/issues/801
443441
// TODO: Scope Protocol Permissions to a specific protocol. https://github.com/TBD54566975/dwn-sdk-js/issues/802
444-
445-
const { grant: { id: permissionGrantId }} = await this.permissionsApi.getPermissionForRequest({
446-
connectedDid : this.connectedDid,
447-
delegateDid : this.delegateDid,
448-
delegate : true,
449-
cached : true,
450-
messageType : agentRequest.messageType
451-
});
452-
453-
agentRequest.messageParams = {
454-
...agentRequest.messageParams,
455-
permissionGrantId
456-
};
457-
458-
agentRequest.granteeDid = this.delegateDid;
442+
throw new Error('Delegated grants are not yet supported for protocol configuration: https://github.com/TBD54566975/dwn-sdk-js/issues/801');
459443
}
460444

461445
const agentResponse = await this.agent.processDwnRequest(agentRequest);
@@ -487,12 +471,14 @@ export class DwnApi {
487471
// If the protocol is public, the query should be successful. This allows the app to query for public protocols without having a grant.
488472

489473
try {
474+
const protocolFromRequest = request.message.filter?.protocol;
475+
490476
// NOTE: Currently protocol permissions are not scoped to specific protocols.
491477
// TODO: Scope Protocol Permissions to a specific protocol. https://github.com/TBD54566975/dwn-sdk-js/issues/802
492-
493478
const { grant: { id: permissionGrantId } } = await this.permissionsApi.getPermissionForRequest({
494479
connectedDid : this.connectedDid,
495480
delegateDid : this.delegateDid,
481+
protocol : protocolFromRequest,
496482
delegate : true,
497483
cached : true,
498484
messageType : agentRequest.messageType

packages/api/tests/web5.spec.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,16 @@ describe('web5 api', () => {
553553
delegateDid,
554554
});
555555

556+
// attempt to query using the grant
557+
let queryResult = await web5.dwn.records.query({
558+
protocol : protocol.protocol,
559+
message : {
560+
filter: { protocol: protocol.protocol }
561+
}
562+
});
563+
expect(queryResult.status.code).to.equal(200);
564+
expect(queryResult.records).to.have.lengthOf(1);
565+
556566
// attempt to delete using the grant
557567
const deleteResult = await web5.dwn.records.delete({
558568
protocol : protocol.protocol,
@@ -562,15 +572,15 @@ describe('web5 api', () => {
562572
});
563573
expect(deleteResult.status.code).to.equal(202);
564574

565-
// attempt to query using the grant
566-
const queryResult = await web5.dwn.records.query({
575+
// query again after the deletion
576+
queryResult = await web5.dwn.records.query({
567577
protocol : protocol.protocol,
568578
message : {
569579
filter: { protocol: protocol.protocol }
570580
}
571581
});
572582
expect(queryResult.status.code).to.equal(200);
573-
expect(queryResult.records).to.have.lengthOf(0); // record has been deleted
583+
expect(queryResult.records).to.have.lengthOf(0); // deleted
574584

575585
// connecting a 2nd time will return the same connectedDID and delegatedDID
576586
const { did: did2, delegateDid: delegateDid2 } = await Web5.connect();

0 commit comments

Comments
 (0)