Skip to content

Commit 6c7ef1e

Browse files
author
Bnonni
committed
fetch and merge upsteam changes
1 parent 43fdbc9 commit 6c7ef1e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/core/dwn-error.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export enum DwnErrorCode {
5555
PrivateKeySignerUnsupportedCurve = 'PrivateKeySignerUnsupportedCurve',
5656
ProtocolAuthorizationActionNotAllowed = 'ProtocolAuthorizationActionNotAllowed',
5757
ProtocolAuthorizationActionRulesNotFound = 'ProtocolAuthorizationActionRulesNotFound',
58+
ProtocolAuthorizationExpiryReached = 'ProtocolAuthorizationExpiryReached',
5859
ProtocolAuthorizationIncorrectDataFormat = 'ProtocolAuthorizationIncorrectDataFormat',
5960
ProtocolAuthorizationIncorrectContextId = 'ProtocolAuthorizationIncorrectContextId',
6061
ProtocolAuthorizationIncorrectProtocolPath = 'ProtocolAuthorizationIncorrectProtocolPath',
@@ -75,6 +76,7 @@ export enum DwnErrorCode {
7576
ProtocolAuthorizationTagsInvalidSchema = 'ProtocolAuthorizationTagsInvalidSchema',
7677
ProtocolsConfigureDuplicateActorInRuleSet = 'ProtocolsConfigureDuplicateActorInRuleSet',
7778
ProtocolsConfigureDuplicateRoleInRuleSet = 'ProtocolsConfigureDuplicateRoleInRuleSet',
79+
ProtocolsConfigureInvalidExpiry = 'ProtocolsConfigureInvalidExpiry',
7880
ProtocolsConfigureInvalidSize = 'ProtocolsConfigureInvalidSize',
7981
ProtocolsConfigureInvalidActionMissingOf = 'ProtocolsConfigureInvalidActionMissingOf',
8082
ProtocolsConfigureInvalidActionOfNotAllowed = 'ProtocolsConfigureInvalidActionOfNotAllowed',

src/core/protocol-authorization.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ export class ProtocolAuthorization {
161161
ancestorMessageChain,
162162
messageStore,
163163
);
164+
165+
// Verify expiry
166+
ProtocolAuthorization.verifyExpiry(incomingMessage, ruleSet)
164167
}
165168

166169
public static async authorizeQueryOrSubscribe(
@@ -726,6 +729,31 @@ export class ProtocolAuthorization {
726729
}
727730
}
728731

732+
/**
733+
* Verifies that reads adhere to the $expiry constraint if provided
734+
* @throws {Error} if expiry date is passed.
735+
*/
736+
private static verifyExpiry(
737+
incomingMessage: RecordsRead,
738+
ruleSet: ProtocolRuleSet
739+
): void {
740+
const ruleExpiry = ruleSet.$expiry;
741+
if (!ruleExpiry) {
742+
return;
743+
}
744+
745+
const dateCreated = incomingMessage.message.descriptor.filter?.dateCreated;
746+
if (!dateCreated) {
747+
return;
748+
}
749+
750+
const dateExpiry = dateCreated + ruleExpiry;
751+
if (Date.now() > dateExpiry) {
752+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationExpiryReached, `dateExpiry ${dateExpiry} has passed`);
753+
}
754+
755+
}
756+
729757
/**
730758
* If the given RecordsWrite is not a role record, this method does nothing and succeeds immediately.
731759
*

src/interfaces/protocols-configure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
132132
): void {
133133
const { ruleSet, ruleSetProtocolPath, recordTypes, roles } = input;
134134

135-
// Validate $actions in the rule set
135+
// Validate $size in the rule set
136136
if (ruleSet.$size !== undefined) {
137137
const { min = 0, max } = ruleSet.$size;
138138

0 commit comments

Comments
 (0)