Skip to content

Commit

Permalink
update connected permissions processing of grants, and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Aug 10, 2024
1 parent a63adea commit fed1e93
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 33 deletions.
1 change: 0 additions & 1 deletion packages/agent/src/permissions-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ export class AgentPermissionsApi implements PermissionsApi {
protocol : PermissionsProtocol.uri,
protocolPath : PermissionsProtocol.grantPath,
dataFormat : 'application/json',
data : permissionsGrantBytes,
tags
};

Expand Down
27 changes: 7 additions & 20 deletions packages/agent/tests/connected-permissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DwnInterfaceName, DwnMethodName, Jws, Message, ProtocolDefinition, Time
import type { BearerIdentity } from '../src/bearer-identity.js';

import { TestAgent } from './utils/test-agent.js';
import { DwnInterface, ProcessDwnRequest } from '../src/types/dwn.js';
import { DwnInterface } from '../src/types/dwn.js';
import { testDwnUrl } from './utils/test-config.js';
import { PlatformAgentTestHarness } from '../src/test-harness.js';

Expand Down Expand Up @@ -101,25 +101,15 @@ describe('Connect Flow Permissions', () => {

// alice creates a permission grant
const messagesQueryGrant = await aliceAgent.agent.permissions.createGrant({
store : false,
store : true,
author : alice.did.uri,
grantedTo : appX.did.uri,
dateExpires : Time.createOffsetTimestamp({ seconds: 60 }),
scope : { interface: DwnInterfaceName.Messages, method: DwnMethodName.Query }
});

// alice stores and processes the permission grant on her DWN
const { encodedData: messagesQueryGrantData, ...messagesQueryGrantMessage } = messagesQueryGrant.message;
const { reply: aliceGrantReply } = await aliceAgent.agent.dwn.processRequest({
messageType : DwnInterface.RecordsWrite,
rawMessage : messagesQueryGrantMessage,
author : alice.did.uri,
target : alice.did.uri,
dataStream : new Blob([ Convert.base64Url(messagesQueryGrantData).toUint8Array() ]),
});
expect(aliceGrantReply.status.code).to.equal(202);

// The App processes the permission grant given by Alice, so it can be accessible when using it
const { encodedData: messagesQueryGrantData, ...messagesQueryGrantMessage } = messagesQueryGrant.message;
const { reply: appAgentGrantReply } = await appAgent.agent.dwn.processRequest({
messageType : DwnInterface.RecordsWrite,
rawMessage : messagesQueryGrantMessage,
Expand All @@ -129,28 +119,25 @@ describe('Connect Flow Permissions', () => {
});
expect(appAgentGrantReply.status.code).to.equal(202);

const writeGrantToGrantee: ProcessDwnRequest<DwnInterface.RecordsWrite> = {
const { reply: importGrantReply } = await appAgent.agent.dwn.processRequest({
messageType : DwnInterface.RecordsWrite,
rawMessage : messagesQueryGrantMessage,
author : appX.did.uri,
target : appX.did.uri,
dataStream : new Blob([ Convert.base64Url(messagesQueryGrantData).toUint8Array() ]),
signAsOwner : true
};

const { reply: importGrantReply } = await appAgent.agent.dwn.processRequest(writeGrantToGrantee);
});
expect(importGrantReply.status.code).to.equal(202);

// Attempt to process the MessagesQuery locally using the permission grant.
const { message: queryMessage, reply } = await appAgent.agent.dwn.processRequest({
author : alice.did.uri,
author : appX.did.uri,
target : alice.did.uri,
messageType : DwnInterface.MessagesQuery,
messageParams : {
filters : [],
permissionGrantId : messagesQueryGrant.message.recordId
},
granteeDid: appX.did.uri,
}
});
const messageSignature = queryMessage!.authorization.signature.signatures[0];
const signatureDid = Jws.getSignerDid(messageSignature);
Expand Down
12 changes: 0 additions & 12 deletions packages/agent/tests/dwn-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,18 +767,6 @@ describe('AgentDwnApi', () => {
scope : { interface: DwnInterfaceName.Records, method: DwnMethodName.Write, protocol: protocolDefinition.protocol }
});

// process the grant on alice's DWN
const { encodedData: recordsWriteGrantData, ...recordsWriteGrantMessage } = recordsWriteDelegateGrant.message;
let { reply: { status: grantStatus } } = await testHarness.agent.dwn.processRequest({
author : alice.did.uri,
target : alice.did.uri,
messageType : DwnInterface.RecordsWrite,
rawMessage : recordsWriteGrantMessage,
dataStream : new Blob([ Convert.base64Url(recordsWriteGrantData).toUint8Array() ]),
});
expect(grantStatus.code).to.equal(202, 'grant write');


// bob authors a public record to his dwn
const dataStream = new Blob([ Convert.string('Hello, world!').toUint8Array() ]);

Expand Down

0 comments on commit fed1e93

Please sign in to comment.