From 0884e5923119a2884c5b37e8550cd0f0dde3610f Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Thu, 29 Aug 2024 17:07:00 -0400 Subject: [PATCH] fix update --- packages/api/src/record.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/api/src/record.ts b/packages/api/src/record.ts index f1cbb4ca0..a374ee8b8 100644 --- a/packages/api/src/record.ts +++ b/packages/api/src/record.ts @@ -741,13 +741,28 @@ export class Record implements RecordModel { delete updateMessage.datePublished; } - const agentResponse = await this._agent.processDwnRequest({ + const requestOptions: ProcessDwnRequest = { author : this._connectedDid, dataStream : dataBlob, messageParams : { ...updateMessage }, messageType : DwnInterface.RecordsWrite, target : this._connectedDid, - }); + }; + if (this._delegateDid) { + // if an app is scoped down to a specific protocolPath or contextId, it must include those filters in the read request + const { rawMessage: delegatedGrant } = await this.findPermissionGrantForMessage({ + messageParams: { + messageType : DwnInterface.RecordsWrite, + protocol : this.protocol, + } + }); + + // set the required delegated grant and grantee DID for the read operation + requestOptions.messageParams.delegatedGrant = delegatedGrant; + requestOptions.granteeDid = this._delegateDid; + } + + const agentResponse = await this._agent.processDwnRequest(requestOptions); const { message, reply: { status } } = agentResponse; const responseMessage = message;