@enbox/dwn-sdk-js 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +2591 -1435
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +20 -0
- package/dist/esm/src/core/constants.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +24 -1
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +4 -4
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message.js +89 -4
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +147 -55
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +76 -0
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/records-grant-authorization.js +40 -15
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/handlers/messages-read.js +5 -5
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +109 -7
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +341 -96
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +81 -2
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +30 -0
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +3 -2
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +30 -0
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +3 -2
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +31 -0
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +36 -11
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +6 -3
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +6 -3
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/messages-sync.js +17 -3
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +5 -2
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +8 -4
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +5 -0
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +6 -2
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +5 -0
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +6 -3
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +5 -0
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +6 -3
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +28 -7
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/sync/records-projection.js +228 -0
- package/dist/esm/src/sync/records-projection.js.map +1 -0
- package/dist/esm/src/types/message-types.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/utils/permission-scope.js +37 -0
- package/dist/esm/src/utils/permission-scope.js.map +1 -0
- package/dist/esm/tests/core/grant-authorization.spec.js +26 -3
- package/dist/esm/tests/core/grant-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/records-grant-authorization.spec.js +117 -0
- package/dist/esm/tests/core/records-grant-authorization.spec.js.map +1 -0
- package/dist/esm/tests/features/permissions.spec.js +126 -0
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +345 -12
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +326 -9
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +1053 -7
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +361 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +75 -2
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +73 -0
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +75 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +15 -0
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +107 -5
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +13 -0
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +12 -0
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +10 -0
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +10 -0
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +33 -0
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/sync/records-projection.spec.js +245 -0
- package/dist/esm/tests/sync/records-projection.spec.js.map +1 -0
- package/dist/esm/tests/test-suite.js +2 -0
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/permission-scope.spec.js +66 -0
- package/dist/esm/tests/utils/permission-scope.spec.js.map +1 -0
- package/dist/esm/tests/utils/test-data-generator.js +5 -2
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +13 -0
- package/dist/types/src/core/constants.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +24 -1
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +1 -2
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/message.d.ts +41 -1
- package/dist/types/src/core/message.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +36 -4
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +12 -0
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/records-grant-authorization.d.ts +6 -0
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts +2 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-sync.d.ts +31 -0
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +3 -0
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +4 -0
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +4 -0
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +1 -0
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +6 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-read.d.ts +1 -1
- package/dist/types/src/interfaces/messages-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-sync.d.ts +4 -1
- package/dist/types/src/interfaces/messages-sync.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-count.d.ts +1 -0
- package/dist/types/src/interfaces/records-count.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-query.d.ts +1 -0
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +1 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +2 -0
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/sync/records-projection.d.ts +98 -0
- package/dist/types/src/sync/records-projection.d.ts.map +1 -0
- package/dist/types/src/types/message-types.d.ts +1 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +21 -3
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +4 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +4 -0
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/subscriptions.d.ts +18 -3
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/utils/permission-scope.d.ts +29 -0
- package/dist/types/src/utils/permission-scope.d.ts.map +1 -0
- package/dist/types/tests/core/records-grant-authorization.spec.d.ts +2 -0
- package/dist/types/tests/core/records-grant-authorization.spec.d.ts.map +1 -0
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/sync/records-projection.spec.d.ts +2 -0
- package/dist/types/tests/sync/records-projection.spec.d.ts.map +1 -0
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/permission-scope.spec.d.ts +2 -0
- package/dist/types/tests/utils/permission-scope.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts +5 -2
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/constants.ts +24 -0
- package/src/core/dwn-error.ts +24 -1
- package/src/core/grant-authorization.ts +7 -5
- package/src/core/message.ts +153 -6
- package/src/core/messages-grant-authorization.ts +282 -70
- package/src/core/protocol-authorization.ts +130 -0
- package/src/core/records-grant-authorization.ts +64 -21
- package/src/handlers/messages-read.ts +7 -5
- package/src/handlers/messages-subscribe.ts +149 -9
- package/src/handlers/messages-sync.ts +593 -102
- package/src/handlers/protocols-configure.ts +103 -2
- package/src/handlers/records-count.ts +33 -0
- package/src/handlers/records-delete.ts +3 -2
- package/src/handlers/records-query.ts +33 -0
- package/src/handlers/records-read.ts +3 -2
- package/src/handlers/records-subscribe.ts +34 -0
- package/src/handlers/records-write.ts +62 -11
- package/src/index.ts +7 -3
- package/src/interfaces/messages-read.ts +8 -5
- package/src/interfaces/messages-subscribe.ts +12 -9
- package/src/interfaces/messages-sync.ts +33 -12
- package/src/interfaces/protocols-configure.ts +8 -4
- package/src/interfaces/protocols-query.ts +13 -9
- package/src/interfaces/records-count.ts +7 -0
- package/src/interfaces/records-delete.ts +9 -5
- package/src/interfaces/records-query.ts +7 -0
- package/src/interfaces/records-read.ts +6 -3
- package/src/interfaces/records-subscribe.ts +7 -0
- package/src/interfaces/records-write.ts +25 -17
- package/src/protocols/permissions.ts +47 -9
- package/src/sync/records-projection.ts +328 -0
- package/src/types/message-types.ts +1 -0
- package/src/types/messages-types.ts +23 -3
- package/src/types/permission-types.ts +5 -1
- package/src/types/records-types.ts +5 -1
- package/src/types/subscriptions.ts +19 -3
- package/src/utils/permission-scope.ts +55 -0
|
@@ -8,4 +8,24 @@
|
|
|
8
8
|
* dependencies between `grant-authorization.ts` and `protocols/permissions.ts`.
|
|
9
9
|
*/
|
|
10
10
|
export const PERMISSIONS_REVOCATION_PATH = 'grant/revocation';
|
|
11
|
+
/**
|
|
12
|
+
* The DWN Permissions protocol URI.
|
|
13
|
+
*/
|
|
14
|
+
export const PERMISSIONS_PROTOCOL_URI = 'https://identity.foundation/dwn/permissions';
|
|
15
|
+
/**
|
|
16
|
+
* Well-known key-delivery protocol URI used for encrypted context-key records.
|
|
17
|
+
*/
|
|
18
|
+
export const KEY_DELIVERY_PROTOCOL_URI = 'https://identity.foundation/protocols/key-delivery';
|
|
19
|
+
const RECORDS_PRIMARY_PROJECTION_EXCLUDED_PROTOCOLS = new Set([
|
|
20
|
+
KEY_DELIVERY_PROTOCOL_URI,
|
|
21
|
+
PERMISSIONS_PROTOCOL_URI,
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* Returns true for infrastructure protocols whose records are dependencies or
|
|
25
|
+
* authorization metadata, not primary application records for projection roots.
|
|
26
|
+
*/
|
|
27
|
+
export function isRecordsPrimaryProjectionExcludedProtocol(protocol) {
|
|
28
|
+
return protocol !== undefined &&
|
|
29
|
+
RECORDS_PRIMARY_PROJECTION_EXCLUDED_PROTOCOLS.has(protocol);
|
|
30
|
+
}
|
|
11
31
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/core/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAE9D;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,6CAA6C,CAAC;AAEtF;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,oDAAoD,CAAC;AAE9F,MAAM,6CAA6C,GAAG,IAAI,GAAG,CAAS;IACpE,yBAAyB;IACzB,wBAAwB;CACzB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,0CAA0C,CAAC,QAA4B;IACrF,OAAO,QAAQ,KAAK,SAAS;QAC3B,6CAA6C,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -23,8 +23,14 @@ export var DwnErrorCode;
|
|
|
23
23
|
DwnErrorCode["Ed25519InvalidJwk"] = "Ed25519InvalidJwk";
|
|
24
24
|
DwnErrorCode["EventLogNotOpenError"] = "EventLogNotOpenError";
|
|
25
25
|
DwnErrorCode["EventLogProgressGap"] = "EventLogProgressGap";
|
|
26
|
-
DwnErrorCode["MessagesGrantAuthorizationMismatchedProtocol"] = "
|
|
26
|
+
DwnErrorCode["MessagesGrantAuthorizationMismatchedProtocol"] = "MessagesGrantAuthorizationMismatchedProtocol";
|
|
27
|
+
DwnErrorCode["MessagesGrantAuthorizationProjectionInfrastructureProtocol"] = "MessagesGrantAuthorizationProjectionInfrastructureProtocol";
|
|
28
|
+
DwnErrorCode["MessagesGrantAuthorizationProjectionScopeMismatch"] = "MessagesGrantAuthorizationProjectionScopeMismatch";
|
|
29
|
+
DwnErrorCode["MessagesGrantAuthorizationProtocolSyncInfrastructureProtocol"] = "MessagesGrantAuthorizationProtocolSyncInfrastructureProtocol";
|
|
30
|
+
DwnErrorCode["MessagesGrantAuthorizationSubscribeProtocolMismatch"] = "MessagesGrantAuthorizationSubscribeProtocolMismatch";
|
|
31
|
+
DwnErrorCode["MessagesGrantAuthorizationUnfilteredSubscribeProtocolScope"] = "MessagesGrantAuthorizationUnfilteredSubscribeProtocolScope";
|
|
27
32
|
DwnErrorCode["MessagesSubscribeAuthorizationFailed"] = "MessagesSubscribeAuthorizationFailed";
|
|
33
|
+
DwnErrorCode["MessagesSubscribeDeliveryAuthorizationFailed"] = "MessagesSubscribeDeliveryAuthorizationFailed";
|
|
28
34
|
DwnErrorCode["MessagesSubscribeEventLogUnimplemented"] = "MessagesSubscribeEventLogUnimplemented";
|
|
29
35
|
DwnErrorCode["GeneralJwsVerifierGetPublicKeyNotFound"] = "GeneralJwsVerifierGetPublicKeyNotFound";
|
|
30
36
|
DwnErrorCode["GeneralJwsVerifierInvalidSignature"] = "GeneralJwsVerifierInvalidSignature";
|
|
@@ -45,19 +51,31 @@ export var DwnErrorCode;
|
|
|
45
51
|
DwnErrorCode["IndexInvalidSortPropertyInMemory"] = "IndexInvalidSortPropertyInMemory";
|
|
46
52
|
DwnErrorCode["IndexMissingIndexableProperty"] = "IndexMissingIndexableProperty";
|
|
47
53
|
DwnErrorCode["JwsDecodePlainObjectPayloadInvalid"] = "JwsDecodePlainObjectPayloadInvalid";
|
|
54
|
+
DwnErrorCode["MessagePermissionGrantCreateInvocationAmbiguous"] = "MessagePermissionGrantCreateInvocationAmbiguous";
|
|
55
|
+
DwnErrorCode["MessagePermissionGrantDescriptorPayloadMismatch"] = "MessagePermissionGrantDescriptorPayloadMismatch";
|
|
56
|
+
DwnErrorCode["MessagePermissionGrantIdsDescriptorPayloadMismatch"] = "MessagePermissionGrantIdsDescriptorPayloadMismatch";
|
|
57
|
+
DwnErrorCode["MessagePermissionGrantIdsEmpty"] = "MessagePermissionGrantIdsEmpty";
|
|
58
|
+
DwnErrorCode["MessagePermissionGrantIdsNotCanonical"] = "MessagePermissionGrantIdsNotCanonical";
|
|
59
|
+
DwnErrorCode["MessagePermissionGrantValidateInvocationAmbiguous"] = "MessagePermissionGrantValidateInvocationAmbiguous";
|
|
48
60
|
DwnErrorCode["MessagesReadInvalidCid"] = "MessagesReadInvalidCid";
|
|
49
61
|
DwnErrorCode["MessagesReadAuthorizationFailed"] = "MessagesReadAuthorizationFailed";
|
|
50
62
|
DwnErrorCode["MessageGetInvalidCid"] = "MessageGetInvalidCid";
|
|
51
63
|
DwnErrorCode["MessagesReadVerifyScopeFailed"] = "MessagesReadVerifyScopeFailed";
|
|
52
64
|
DwnErrorCode["MessagesSyncAuthorizationFailed"] = "MessagesSyncAuthorizationFailed";
|
|
53
65
|
DwnErrorCode["MessagesSyncInvalidPrefix"] = "MessagesSyncInvalidPrefix";
|
|
66
|
+
DwnErrorCode["MessagesSyncUnsupportedProjectionRootVersion"] = "MessagesSyncUnsupportedProjectionRootVersion";
|
|
54
67
|
DwnErrorCode["ParseCidCodecNotSupported"] = "ParseCidCodecNotSupported";
|
|
55
68
|
DwnErrorCode["ParseCidMultihashNotSupported"] = "ParseCidMultihashNotSupported";
|
|
69
|
+
DwnErrorCode["PermissionsProtocolCreateGrantScopeContextIdProtocolPathConflict"] = "PermissionsProtocolCreateGrantScopeContextIdProtocolPathConflict";
|
|
56
70
|
DwnErrorCode["PermissionsProtocolCreateGrantRecordsScopeMissingProtocol"] = "PermissionsProtocolCreateGrantRecordsScopeMissingProtocol";
|
|
71
|
+
DwnErrorCode["PermissionsProtocolCreateGrantSubtreeScopeMissingProtocol"] = "PermissionsProtocolCreateGrantSubtreeScopeMissingProtocol";
|
|
72
|
+
DwnErrorCode["PermissionsProtocolCreateRequestScopeContextIdProtocolPathConflict"] = "PermissionsProtocolCreateRequestScopeContextIdProtocolPathConflict";
|
|
57
73
|
DwnErrorCode["PermissionsProtocolCreateRequestRecordsScopeMissingProtocol"] = "PermissionsProtocolCreateRequestRecordsScopeMissingProtocol";
|
|
74
|
+
DwnErrorCode["PermissionsProtocolCreateRequestSubtreeScopeMissingProtocol"] = "PermissionsProtocolCreateRequestSubtreeScopeMissingProtocol";
|
|
58
75
|
DwnErrorCode["PermissionsProtocolGetScopeInvalidProtocol"] = "PermissionsProtocolGetScopeInvalidProtocol";
|
|
59
76
|
DwnErrorCode["PermissionsProtocolValidateSchemaUnexpectedRecord"] = "PermissionsProtocolValidateSchemaUnexpectedRecord";
|
|
60
77
|
DwnErrorCode["PermissionsProtocolValidateScopeContextIdProhibitedProperties"] = "PermissionsProtocolValidateScopeContextIdProhibitedProperties";
|
|
78
|
+
DwnErrorCode["PermissionsProtocolValidateScopeSubtreeScopeMissingProtocol"] = "PermissionsProtocolValidateScopeSubtreeScopeMissingProtocol";
|
|
61
79
|
DwnErrorCode["PermissionsProtocolValidateScopeProtocolMismatch"] = "PermissionsProtocolValidateScopeProtocolMismatch";
|
|
62
80
|
DwnErrorCode["PermissionsProtocolValidateScopeMissingProtocolTag"] = "PermissionsProtocolValidateScopeMissingProtocolTag";
|
|
63
81
|
DwnErrorCode["PermissionsProtocolValidateRevocationProtocolTagMismatch"] = "PermissionsProtocolValidateRevocationProtocolTagMismatch";
|
|
@@ -78,6 +96,7 @@ export var DwnErrorCode;
|
|
|
78
96
|
DwnErrorCode["ProtocolAuthorizationIncorrectDataFormat"] = "ProtocolAuthorizationIncorrectDataFormat";
|
|
79
97
|
DwnErrorCode["ProtocolAuthorizationIncorrectContextId"] = "ProtocolAuthorizationIncorrectContextId";
|
|
80
98
|
DwnErrorCode["ProtocolAuthorizationIncorrectProtocolPath"] = "ProtocolAuthorizationIncorrectProtocolPath";
|
|
99
|
+
DwnErrorCode["ProtocolAuthorizationInitialWriteRevalidationNotInitial"] = "ProtocolAuthorizationInitialWriteRevalidationNotInitial";
|
|
81
100
|
DwnErrorCode["ProtocolAuthorizationDuplicateRoleRecipient"] = "ProtocolAuthorizationDuplicateRoleRecipient";
|
|
82
101
|
DwnErrorCode["ProtocolAuthorizationEncryptionRequired"] = "ProtocolAuthorizationEncryptionRequired";
|
|
83
102
|
DwnErrorCode["ProtocolAuthorizationImmutableRecord"] = "ProtocolAuthorizationImmutableRecord";
|
|
@@ -91,6 +110,9 @@ export var DwnErrorCode;
|
|
|
91
110
|
DwnErrorCode["ProtocolAuthorizationSquashNotEnabled"] = "ProtocolAuthorizationSquashNotEnabled";
|
|
92
111
|
DwnErrorCode["ProtocolAuthorizationSquashNotInitialWrite"] = "ProtocolAuthorizationSquashNotInitialWrite";
|
|
93
112
|
DwnErrorCode["ProtocolAuthorizationSquashBackstop"] = "ProtocolAuthorizationSquashBackstop";
|
|
113
|
+
DwnErrorCode["ProtocolAuthorizationStoredInitialWriteActionNotAllowed"] = "ProtocolAuthorizationStoredInitialWriteActionNotAllowed";
|
|
114
|
+
DwnErrorCode["ProtocolAuthorizationStoredInitialWriteActionRulesNotFound"] = "ProtocolAuthorizationStoredInitialWriteActionRulesNotFound";
|
|
115
|
+
DwnErrorCode["ProtocolAuthorizationStoredInitialWriteRoleMissingRecipient"] = "ProtocolAuthorizationStoredInitialWriteRoleMissingRecipient";
|
|
94
116
|
DwnErrorCode["ProtocolAuthorizationMissingContextId"] = "ProtocolAuthorizationMissingContextId";
|
|
95
117
|
DwnErrorCode["ProtocolAuthorizationMissingRuleSet"] = "ProtocolAuthorizationMissingRuleSet";
|
|
96
118
|
DwnErrorCode["ProtocolAuthorizationParentlessIncorrectProtocolPath"] = "ProtocolAuthorizationParentlessIncorrectProtocolPath";
|
|
@@ -142,6 +164,7 @@ export var DwnErrorCode;
|
|
|
142
164
|
DwnErrorCode["RecordsGrantAuthorizationDeleteProtocolScopeMismatch"] = "RecordsGrantAuthorizationDeleteProtocolScopeMismatch";
|
|
143
165
|
DwnErrorCode["RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch"] = "RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch";
|
|
144
166
|
DwnErrorCode["RecordsGrantAuthorizationScopeContextIdMismatch"] = "RecordsGrantAuthorizationScopeContextIdMismatch";
|
|
167
|
+
DwnErrorCode["RecordsGrantAuthorizationScopeMismatch"] = "RecordsGrantAuthorizationScopeMismatch";
|
|
145
168
|
DwnErrorCode["RecordsGrantAuthorizationScopeProtocolMismatch"] = "RecordsGrantAuthorizationScopeProtocolMismatch";
|
|
146
169
|
DwnErrorCode["RecordsGrantAuthorizationScopeProtocolPathMismatch"] = "RecordsGrantAuthorizationScopeProtocolPathMismatch";
|
|
147
170
|
DwnErrorCode["RecordsDerivePrivateKeyUnSupportedCurve"] = "RecordsDerivePrivateKeyUnSupportedCurve";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dwn-error.js","sourceRoot":"","sources":["../../../../src/core/dwn-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACb;IAApB,YAAoB,IAAY,EAAE,OAAe;QAC/C,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QADX,SAAI,GAAJ,IAAI,CAAQ;QAG9B,IAAI,CAAC,IAAI,GAAG,UAAU,C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AA;IACrG,+FAA+E,CAAA;IAC/E,6IAA6H,CAAA;IAC7H,6GAA6F,CAAA;IAE7F,2GAA2F,CAAA;IAE3F,2GAA2F,CAAA;IAC3F,yGAAyF,CAAA;IACzF,+FAA+E,CAAA;IAC/E,mHAAmG,CAAA;IAEnG,6HAA6G,CAAA;IAC7G,+HAA+G,CAAA;IAC/G,iIAAiH,CAAA;IAEjH,mFAAmE,CAAA;IACnE,uHAAuG,CAAA;IACvG,+HAA+G,CAAA;IAC/G,uFAAuE,CAAA;IACvE,2EAA2D,CAAA;IAC3D,6EAA6D,CAAA;IAC7D,+FAA+E,CAAA;IAC/E,qGAAqF,CAAA;IACrF,2FAA2E,CAAA;IAC3E,6FAA6E,CAAA;IAC7E,uEAAuD,CAAA;IACvD,uFAAuE,CAAA;IACvE,qGAAqF,CAAA;IACrF,+EAA+D,CAAA;IAE/D,uFAAuE,CAAA;IACvE,yFAAyE,CAAA;IACzE,6GAA6F,CAAA;IAC7F,6FAA6E,CAAA;IAC7E,qHAAqG,CAAA;IACrG,iHAAiG,CAAA;IACjG,uJAAuI,CAAA;IACvI,qHAAqG,CAAA;IACrG,yHAAyG,CAAA;IACzG,uHAAuG,CAAA;IACvG,2GAA2F,CAAA;IAC3F,iEAAiD,CAAA;IACjD,+EAA+D,CAAA;IAC/D,6GAA6F,CAAA;IAC7F,6DAA6C,CAAA;IAC7C,6DAA6C,CAAA;IAC7C,qDAAqC,CAAA;IACrC,qEAAqD,CAAA;IACrD,yEAAyD,CAAA;IACzD,iEAAiD,CAAA;IACjD,mFAAmE,CAAA;AACrE,CAAC,EAjNW,YAAY,KAAZ,YAAY,QAiNvB;AAAA,CAAC"}
|
|
@@ -71,8 +71,7 @@ export class GrantAuthorization {
|
|
|
71
71
|
* Verify that the `interface` and `method` grant scopes match the incoming message.
|
|
72
72
|
*
|
|
73
73
|
* For the Messages interface, a `Read` scope is treated as a unified scope that also authorizes
|
|
74
|
-
* `Subscribe` and `Sync` operations.
|
|
75
|
-
* unified action covering read, query, subscribe, and count.
|
|
74
|
+
* `Subscribe` and `Sync` operations.
|
|
76
75
|
*
|
|
77
76
|
* @throws {DwnError} if the `interface` and `method` of the incoming message do not match the scope of the permission grant.
|
|
78
77
|
*/
|
|
@@ -81,7 +80,7 @@ export class GrantAuthorization {
|
|
|
81
80
|
throw new DwnError(DwnErrorCode.GrantAuthorizationInterfaceMismatch, `DWN Interface of incoming message is outside the scope of permission grant with ID ${permissionGrant.id}`);
|
|
82
81
|
}
|
|
83
82
|
// Messages.Read is the only valid Messages scope and covers Read, Subscribe, and Sync operations.
|
|
84
|
-
// Reject any Messages grant with method !== Read
|
|
83
|
+
// Reject any Messages grant with method !== Read.
|
|
85
84
|
if (dwnInterface === DwnInterfaceName.Messages) {
|
|
86
85
|
if (permissionGrant.scope.method !== DwnMethodName.Read) {
|
|
87
86
|
throw new DwnError(DwnErrorCode.GrantAuthorizationMethodMismatch, `messages permission grant must have method 'Read', got '${permissionGrant.scope.method}' for grant ${permissionGrant.id}`);
|
|
@@ -90,8 +89,9 @@ export class GrantAuthorization {
|
|
|
90
89
|
if (!allowedMethods.includes(dwnMethod)) {
|
|
91
90
|
throw new DwnError(DwnErrorCode.GrantAuthorizationMethodMismatch, `DWN Method of incoming message is outside the scope of permission grant with ID ${permissionGrant.id}`);
|
|
92
91
|
}
|
|
92
|
+
return;
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
if (dwnMethod !== permissionGrant.scope.method) {
|
|
95
95
|
throw new DwnError(DwnErrorCode.GrantAuthorizationMethodMismatch, `DWN Method of incoming message is outside the scope of permission grant with ID ${permissionGrant.id}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grant-authorization.js","sourceRoot":"","sources":["../../../../src/core/grant-authorization.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAA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AAC,KAAK,CAAC,SAAS,EAAE,CAAC;YACrD,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,mCAAmC,EAChD,sFAAsF,eAAe,CAAC,EAAE,EAAE,CAC3G,CAAC;QACJ,CAAC;QAED,kGAAkG;QAClG,kDAAkD;QAClD,IAAI,YAAY,KAAK,gBAAgB,CAAC,QAAQ,EAAE,CAAC;YAC/C,IAAI,eAAe,CAAC,KAAK,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI,EAAE,CAAC;gBACxD,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,gCAAgC,EAC7C,2DAA2D,eAAe,CAAC,KAAK,CAAC,MAAM,eAAe,eAAe,CAAC,EAAE,EAAE,CAC3H,CAAC;YACJ,CAAC;YACD,MAAM,cAAc,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;YACzF,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,SAA0B,CAAC,EAAE,CAAC;gBACzD,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,gCAAgC,EAC7C,mFAAmF,eAAe,CAAC,EAAE,EAAE,CACxG,CAAC;YACJ,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,SAAS,KAAK,eAAe,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC/C,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,gCAAgC,EAC7C,mFAAmF,eAAe,CAAC,EAAE,EAAE,CACxG,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -80,12 +80,12 @@ export class Message {
|
|
|
80
80
|
* @returns {AuthorizationModel} used as an `authorization` property.
|
|
81
81
|
*/
|
|
82
82
|
static async createAuthorization(input) {
|
|
83
|
-
const { descriptor, signer, delegatedGrant, permissionGrantId, protocolRole } = input;
|
|
83
|
+
const { descriptor, signer, delegatedGrant, permissionGrantId, permissionGrantIds, protocolRole } = input;
|
|
84
84
|
let delegatedGrantId;
|
|
85
85
|
if (delegatedGrant !== undefined) {
|
|
86
86
|
delegatedGrantId = await Message.getCid(delegatedGrant);
|
|
87
87
|
}
|
|
88
|
-
const signature = await Message.createSignature(descriptor, signer, { delegatedGrantId, permissionGrantId, protocolRole });
|
|
88
|
+
const signature = await Message.createSignature(descriptor, signer, { delegatedGrantId, permissionGrantId, permissionGrantIds, protocolRole });
|
|
89
89
|
const authorization = {
|
|
90
90
|
signature
|
|
91
91
|
};
|
|
@@ -100,13 +100,59 @@ export class Message {
|
|
|
100
100
|
*/
|
|
101
101
|
static async createSignature(descriptor, signer, additionalPayloadProperties) {
|
|
102
102
|
const descriptorCid = await Cid.computeCid(descriptor);
|
|
103
|
-
const
|
|
103
|
+
const { delegatedGrantId, permissionGrantId, permissionGrantIds, protocolRole } = additionalPayloadProperties ?? {};
|
|
104
|
+
const permissionGrantInvocation = Message.normalizePermissionGrantInvocation({ permissionGrantId, permissionGrantIds });
|
|
105
|
+
const signaturePayload = {
|
|
106
|
+
descriptorCid,
|
|
107
|
+
delegatedGrantId,
|
|
108
|
+
protocolRole,
|
|
109
|
+
...permissionGrantInvocation
|
|
110
|
+
};
|
|
104
111
|
removeUndefinedProperties(signaturePayload);
|
|
105
112
|
const signaturePayloadBytes = Encoder.objectToBytes(signaturePayload);
|
|
106
113
|
const builder = await GeneralJwsBuilder.create(signaturePayloadBytes, [signer]);
|
|
107
114
|
const signature = builder.getJws();
|
|
108
115
|
return signature;
|
|
109
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Normalizes permission grant invocation before it is written into a descriptor
|
|
119
|
+
* and signed payload.
|
|
120
|
+
*
|
|
121
|
+
* Direct operation messages use `permissionGrantId`; Messages operations use
|
|
122
|
+
* canonicalized `permissionGrantIds` so a request can invoke a grant set.
|
|
123
|
+
*/
|
|
124
|
+
static normalizePermissionGrantInvocation(input) {
|
|
125
|
+
if (input.permissionGrantId !== undefined && input.permissionGrantIds !== undefined) {
|
|
126
|
+
throw new DwnError(DwnErrorCode.MessagePermissionGrantCreateInvocationAmbiguous, 'permission grant invocation must use either `permissionGrantId` or `permissionGrantIds`, not both');
|
|
127
|
+
}
|
|
128
|
+
if (input.permissionGrantId !== undefined) {
|
|
129
|
+
return { permissionGrantId: input.permissionGrantId };
|
|
130
|
+
}
|
|
131
|
+
if (input.permissionGrantIds === undefined) {
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
const permissionGrantIds = Message.normalizePermissionGrantIds(input);
|
|
135
|
+
return { permissionGrantIds };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Returns the permission grant ID carried by a direct operation signature payload.
|
|
139
|
+
*/
|
|
140
|
+
static getPermissionGrantId(signaturePayload) {
|
|
141
|
+
return signaturePayload.permissionGrantId;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns all permission grant IDs invoked by a signature payload.
|
|
145
|
+
*
|
|
146
|
+
* Direct Records/Protocols operations carry a single `permissionGrantId`.
|
|
147
|
+
* Messages operations carry `permissionGrantIds`. Generic cleanup and
|
|
148
|
+
* revocation code uses this helper across both wire shapes.
|
|
149
|
+
*/
|
|
150
|
+
static getPermissionGrantIds(signaturePayload) {
|
|
151
|
+
if (signaturePayload.permissionGrantId !== undefined) {
|
|
152
|
+
return [signaturePayload.permissionGrantId];
|
|
153
|
+
}
|
|
154
|
+
return signaturePayload.permissionGrantIds ?? [];
|
|
155
|
+
}
|
|
110
156
|
/**
|
|
111
157
|
* @returns newest message in the array. `undefined` if given array is empty.
|
|
112
158
|
*/
|
|
@@ -181,9 +227,10 @@ export class Message {
|
|
|
181
227
|
* 3. The `descriptorCid` property matches the CID of the message descriptor
|
|
182
228
|
* NOTE: signature is NOT verified.
|
|
183
229
|
* @param payloadJsonSchemaKey The key to look up the JSON schema referenced in `compile-validators.js` and perform payload schema validation on.
|
|
230
|
+
* @param options Additional structural validation controls.
|
|
184
231
|
* @returns the parsed JSON payload object if validation succeeds.
|
|
185
232
|
*/
|
|
186
|
-
static async validateSignatureStructure(messageSignature, messageDescriptor, payloadJsonSchemaKey = 'GenericSignaturePayload') {
|
|
233
|
+
static async validateSignatureStructure(messageSignature, messageDescriptor, payloadJsonSchemaKey = 'GenericSignaturePayload', options = {}) {
|
|
187
234
|
if (messageSignature.signatures.length !== 1) {
|
|
188
235
|
throw new DwnError(DwnErrorCode.AuthenticationMoreThanOneSignatureNotSupported, 'expected no more than 1 signature for authorization purpose');
|
|
189
236
|
}
|
|
@@ -196,7 +243,45 @@ export class Message {
|
|
|
196
243
|
if (descriptorCid !== expectedDescriptorCid) {
|
|
197
244
|
throw new DwnError(DwnErrorCode.AuthenticateDescriptorCidMismatch, `provided descriptorCid ${descriptorCid} does not match expected CID ${expectedDescriptorCid}`);
|
|
198
245
|
}
|
|
246
|
+
if (options.validatePermissionGrantInvocation !== false) {
|
|
247
|
+
Message.validatePermissionGrantInvocationMatchesPayload(messageDescriptor, payloadJson);
|
|
248
|
+
}
|
|
199
249
|
return payloadJson;
|
|
200
250
|
}
|
|
251
|
+
static normalizePermissionGrantIds(input) {
|
|
252
|
+
if (input.permissionGrantIds === undefined) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
if (input.permissionGrantIds.length === 0) {
|
|
256
|
+
throw new DwnError(DwnErrorCode.MessagePermissionGrantIdsEmpty, '`permissionGrantIds` must contain at least one grant ID');
|
|
257
|
+
}
|
|
258
|
+
return [...new Set(input.permissionGrantIds)].sort(lexicographicalCompare);
|
|
259
|
+
}
|
|
260
|
+
static validatePermissionGrantInvocationCanonical(input) {
|
|
261
|
+
if (input.permissionGrantId !== undefined && input.permissionGrantIds !== undefined) {
|
|
262
|
+
throw new DwnError(DwnErrorCode.MessagePermissionGrantValidateInvocationAmbiguous, 'permission grant invocation must use either `permissionGrantId` or `permissionGrantIds`, not both');
|
|
263
|
+
}
|
|
264
|
+
if (input.permissionGrantId !== undefined) {
|
|
265
|
+
return [input.permissionGrantId];
|
|
266
|
+
}
|
|
267
|
+
const normalizedPermissionGrantIds = Message.normalizePermissionGrantIds(input);
|
|
268
|
+
if (input.permissionGrantIds !== undefined && !Message.areStringArraysEqual(input.permissionGrantIds, normalizedPermissionGrantIds)) {
|
|
269
|
+
throw new DwnError(DwnErrorCode.MessagePermissionGrantIdsNotCanonical, '`permissionGrantIds` must be sorted and deduplicated');
|
|
270
|
+
}
|
|
271
|
+
return normalizedPermissionGrantIds;
|
|
272
|
+
}
|
|
273
|
+
static validatePermissionGrantInvocationMatchesPayload(descriptor, signaturePayload) {
|
|
274
|
+
if (descriptor.permissionGrantId !== signaturePayload.permissionGrantId) {
|
|
275
|
+
throw new DwnError(DwnErrorCode.MessagePermissionGrantDescriptorPayloadMismatch, 'permission grant invocation in descriptor does not match signature payload');
|
|
276
|
+
}
|
|
277
|
+
const descriptorPermissionGrantIds = Message.validatePermissionGrantInvocationCanonical(descriptor);
|
|
278
|
+
const payloadPermissionGrantIds = Message.validatePermissionGrantInvocationCanonical(signaturePayload);
|
|
279
|
+
if (!Message.areStringArraysEqual(descriptorPermissionGrantIds, payloadPermissionGrantIds)) {
|
|
280
|
+
throw new DwnError(DwnErrorCode.MessagePermissionGrantIdsDescriptorPayloadMismatch, 'permission grant invocation in descriptor does not match signature payload');
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
static areStringArraysEqual(a, b) {
|
|
284
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
285
|
+
}
|
|
201
286
|
}
|
|
202
287
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/core/message.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,MAAM,iB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EAAE,4BAA4B,CAAC,EAAE,CAAC;YACpI,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,qCAAqC,EAClD,sDAAsD,CACvD,CAAC;QACJ,CAAC;QAED,OAAO,4BAA4B,CAAC;IACtC,CAAC;IAEO,MAAM,CAAC,+CAA+C,CAC5D,UAAkD,EAClD,gBAAyC;QAEzC,IAAI,UAAU,CAAC,iBAAiB,KAAK,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;YACxE,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,+CAA+C,EAC5D,4EAA4E,CAC7E,CAAC;QACJ,CAAC;QAED,MAAM,4BAA4B,GAAG,OAAO,CAAC,0CAA0C,CAAC,UAAU,CAAC,CAAC;QACpG,MAAM,yBAAyB,GAAG,OAAO,CAAC,0CAA0C,CAAC,gBAAgB,CAAC,CAAC;QAEvG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,4BAA4B,EAAE,yBAAyB,CAAC,EAAE,CAAC;YAC3F,MAAM,IAAI,QAAQ,CAChB,YAAY,CAAC,kDAAkD,EAC/D,4EAA4E,CAC7E,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,CAAW,EAAE,CAAW;QAC1D,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAChF,CAAC;CACF"}
|
|
@@ -1,97 +1,189 @@
|
|
|
1
1
|
import { DwnInterfaceName } from '../enums/dwn-interface-method.js';
|
|
2
2
|
import { GrantAuthorization } from './grant-authorization.js';
|
|
3
|
+
import { isRecordsPrimaryProjectionExcludedProtocol } from './constants.js';
|
|
4
|
+
import { PermissionScopeMatcher } from '../utils/permission-scope.js';
|
|
3
5
|
import { PermissionsProtocol } from '../protocols/permissions.js';
|
|
4
6
|
import { Records } from '../utils/records.js';
|
|
5
7
|
import { RecordsWrite } from '../interfaces/records-write.js';
|
|
6
8
|
import { DwnError, DwnErrorCode } from './dwn-error.js';
|
|
7
9
|
export class MessagesGrantAuthorization {
|
|
10
|
+
static async fetchPermissionGrants(tenant, messageStore, permissionGrantIds) {
|
|
11
|
+
return Promise.all(permissionGrantIds.map(permissionGrantId => PermissionsProtocol.fetchGrant(tenant, messageStore, permissionGrantId)));
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* Authorizes a MessagesReadMessage using the given permission grant.
|
|
10
15
|
* @param messageStore Used to check if the given grant has been revoked; and to fetch related RecordsWrites if needed.
|
|
11
16
|
*/
|
|
12
17
|
static async authorizeMessagesRead(input) {
|
|
13
|
-
const { messagesReadMessage, messageToRead, expectedGrantor, expectedGrantee,
|
|
14
|
-
await
|
|
18
|
+
const { messagesReadMessage, messageToRead, expectedGrantor, expectedGrantee, permissionGrants, messageStore } = input;
|
|
19
|
+
await MessagesGrantAuthorization.performBaseValidationForGrantSet({
|
|
15
20
|
incomingMessage: messagesReadMessage,
|
|
16
21
|
expectedGrantor,
|
|
17
22
|
expectedGrantee,
|
|
18
|
-
|
|
23
|
+
permissionGrants,
|
|
19
24
|
messageStore
|
|
20
25
|
});
|
|
21
|
-
const
|
|
22
|
-
|
|
26
|
+
for (const permissionGrant of permissionGrants) {
|
|
27
|
+
const scope = permissionGrant.scope;
|
|
28
|
+
if (await MessagesGrantAuthorization.isScopeAuthorized(expectedGrantor, messageToRead, scope, messageStore)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw new DwnError(DwnErrorCode.MessagesReadVerifyScopeFailed, 'record message failed scope authorization');
|
|
23
33
|
}
|
|
24
34
|
/**
|
|
25
35
|
* Authorizes the scope of a permission grant for MessagesSubscribe or MessagesSync.
|
|
26
36
|
* @param messageStore Used to check if the grant has been revoked.
|
|
27
37
|
*/
|
|
28
38
|
static async authorizeSubscribeOrSync(input) {
|
|
29
|
-
const { incomingMessage, expectedGrantor, expectedGrantee,
|
|
30
|
-
await
|
|
39
|
+
const { incomingMessage, expectedGrantor, expectedGrantee, permissionGrants, messageStore } = input;
|
|
40
|
+
await MessagesGrantAuthorization.performBaseValidationForGrantSet({
|
|
31
41
|
incomingMessage,
|
|
32
42
|
expectedGrantor,
|
|
33
43
|
expectedGrantee,
|
|
34
|
-
|
|
44
|
+
permissionGrants,
|
|
35
45
|
messageStore
|
|
36
46
|
});
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
const scopes = permissionGrants.map(permissionGrant => permissionGrant.scope);
|
|
48
|
+
if ('action' in incomingMessage.descriptor) {
|
|
49
|
+
MessagesGrantAuthorization.authorizeSyncScope(incomingMessage, scopes);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
MessagesGrantAuthorization.authorizeSubscribeScope(incomingMessage, scopes);
|
|
53
|
+
}
|
|
54
|
+
static authorizeSyncScope(syncMessage, scopes) {
|
|
55
|
+
const { projectionScopes, protocol } = syncMessage.descriptor;
|
|
56
|
+
if (projectionScopes === undefined) {
|
|
57
|
+
MessagesGrantAuthorization.authorizeProtocolSyncScope(scopes, protocol);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
MessagesGrantAuthorization.authorizeProjectionScopes(scopes, projectionScopes);
|
|
61
|
+
}
|
|
62
|
+
static authorizeProtocolSyncScope(scopes, protocol) {
|
|
63
|
+
if (isRecordsPrimaryProjectionExcludedProtocol(protocol)) {
|
|
64
|
+
throw new DwnError(DwnErrorCode.MessagesGrantAuthorizationProtocolSyncInfrastructureProtocol, `Protocol-scoped MessagesSync cannot authorize infrastructure protocol ${protocol}`);
|
|
65
|
+
}
|
|
66
|
+
if (!MessagesGrantAuthorization.someScopeMatches(scopes, { protocol })) {
|
|
67
|
+
throw new DwnError(DwnErrorCode.MessagesGrantAuthorizationMismatchedProtocol, `No permission grant scope matches protocol ${protocol}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
static authorizeProjectionScopes(scopes, projectionScopes) {
|
|
71
|
+
for (const projectionScope of projectionScopes) {
|
|
72
|
+
if (isRecordsPrimaryProjectionExcludedProtocol(projectionScope.protocol)) {
|
|
73
|
+
throw new DwnError(DwnErrorCode.MessagesGrantAuthorizationProjectionInfrastructureProtocol, `Projected MessagesSync cannot authorize infrastructure protocol ${projectionScope.protocol}`);
|
|
74
|
+
}
|
|
75
|
+
if (MessagesGrantAuthorization.someScopeMatches(scopes, projectionScope)) {
|
|
76
|
+
continue;
|
|
46
77
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
78
|
+
throw new DwnError(DwnErrorCode.MessagesGrantAuthorizationProjectionScopeMismatch, `No permission grant scope matches projection scope ${JSON.stringify(projectionScope)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static authorizeSubscribeScope(subscribeMessage, scopes) {
|
|
82
|
+
const { filters } = subscribeMessage.descriptor;
|
|
83
|
+
if (filters.length === 0 && !MessagesGrantAuthorization.hasUnscopedGrant(scopes)) {
|
|
84
|
+
throw new DwnError(DwnErrorCode.MessagesGrantAuthorizationUnfilteredSubscribeProtocolScope, `A protocol-scoped grant cannot authorize an unfiltered subscription`);
|
|
85
|
+
}
|
|
86
|
+
for (const filter of filters) {
|
|
87
|
+
if (MessagesGrantAuthorization.someScopeMatches(scopes, { protocol: filter.protocol })) {
|
|
88
|
+
continue;
|
|
55
89
|
}
|
|
90
|
+
throw new DwnError(DwnErrorCode.MessagesGrantAuthorizationSubscribeProtocolMismatch, `No permission grant scope matches protocol ${filter.protocol}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
static someScopeMatches(scopes, target) {
|
|
94
|
+
return scopes.some(scope => PermissionScopeMatcher.matches(scope, target));
|
|
95
|
+
}
|
|
96
|
+
static hasUnscopedGrant(scopes) {
|
|
97
|
+
return scopes.some(scope => scope.protocol === undefined);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Revalidates an already-open delegated MessagesSubscribe grant set at event
|
|
101
|
+
* delivery time. Subscription messages are signed at open time, but grant
|
|
102
|
+
* expiry and revocation must stop future delivery after the grant set becomes
|
|
103
|
+
* invalid.
|
|
104
|
+
*/
|
|
105
|
+
static async authorizeSubscribeDelivery(input) {
|
|
106
|
+
const { messagesSubscribeMessage, expectedGrantor, expectedGrantee, permissionGrants, messageStore, deliveryTimestamp, } = input;
|
|
107
|
+
const deliveryMessage = {
|
|
108
|
+
...messagesSubscribeMessage,
|
|
109
|
+
descriptor: {
|
|
110
|
+
...messagesSubscribeMessage.descriptor,
|
|
111
|
+
messageTimestamp: deliveryTimestamp,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
await MessagesGrantAuthorization.authorizeSubscribeOrSync({
|
|
115
|
+
incomingMessage: deliveryMessage,
|
|
116
|
+
expectedGrantor,
|
|
117
|
+
expectedGrantee,
|
|
118
|
+
permissionGrants,
|
|
119
|
+
messageStore,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Performs base validation on every invoked grant. The grant set is all-or-nothing:
|
|
124
|
+
* unresolved, revoked, expired, or interface/method-mismatched grants fail the request.
|
|
125
|
+
*/
|
|
126
|
+
static async performBaseValidationForGrantSet(input) {
|
|
127
|
+
const { incomingMessage, expectedGrantor, expectedGrantee, permissionGrants, messageStore } = input;
|
|
128
|
+
for (const permissionGrant of permissionGrants) {
|
|
129
|
+
await GrantAuthorization.performBaseValidation({
|
|
130
|
+
incomingMessage,
|
|
131
|
+
expectedGrantor,
|
|
132
|
+
expectedGrantee,
|
|
133
|
+
permissionGrant,
|
|
134
|
+
messageStore
|
|
135
|
+
});
|
|
56
136
|
}
|
|
57
137
|
}
|
|
58
138
|
/**
|
|
59
|
-
*
|
|
139
|
+
* Determines whether the given record is inside a grant scope.
|
|
60
140
|
*/
|
|
61
|
-
static async
|
|
141
|
+
static async isScopeAuthorized(tenant, messageToGet, incomingScope, messageStore) {
|
|
62
142
|
if (incomingScope.protocol === undefined) {
|
|
63
|
-
|
|
64
|
-
return;
|
|
143
|
+
return true;
|
|
65
144
|
}
|
|
66
145
|
if (messageToGet.descriptor.interface === DwnInterfaceName.Records) {
|
|
67
|
-
|
|
68
|
-
const recordsMessage = messageToGet;
|
|
69
|
-
const recordsWriteMessage = Records.isRecordsWrite(recordsMessage) ? recordsMessage :
|
|
70
|
-
await RecordsWrite.fetchNewestRecordsWrite(messageStore, tenant, recordsMessage.descriptor.recordId);
|
|
71
|
-
if (recordsWriteMessage.descriptor.protocol === incomingScope.protocol) {
|
|
72
|
-
// the record protocol matches the incoming scope protocol
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// we check if the protocol is the internal PermissionsProtocol for further validation
|
|
76
|
-
if (recordsWriteMessage.descriptor.protocol === PermissionsProtocol.uri) {
|
|
77
|
-
// get the permission scope from the permission message
|
|
78
|
-
const permissionScope = await PermissionsProtocol.getScopeFromPermissionRecord(tenant, messageStore, recordsWriteMessage);
|
|
79
|
-
if (PermissionsProtocol.hasProtocolScope(permissionScope) && permissionScope.protocol === incomingScope.protocol) {
|
|
80
|
-
// the permissions record scoped protocol matches the incoming scope protocol
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
146
|
+
return MessagesGrantAuthorization.isRecordsMessageScopeAuthorized(tenant, messageToGet, incomingScope, messageStore);
|
|
84
147
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const protocolsConfigureMessage = messageToGet;
|
|
88
|
-
const configureProtocol = protocolsConfigureMessage.descriptor.definition.protocol;
|
|
89
|
-
if (configureProtocol === incomingScope.protocol) {
|
|
90
|
-
// the configured protocol matches the incoming scope protocol
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
148
|
+
if (messageToGet.descriptor.interface === DwnInterfaceName.Protocols) {
|
|
149
|
+
return MessagesGrantAuthorization.isProtocolsConfigureScopeAuthorized(messageToGet, incomingScope);
|
|
93
150
|
}
|
|
94
|
-
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
static async isRecordsMessageScopeAuthorized(tenant, recordsMessage, incomingScope, messageStore) {
|
|
154
|
+
const recordsWriteMessage = await MessagesGrantAuthorization.getAssociatedRecordsWrite(tenant, recordsMessage, messageStore);
|
|
155
|
+
if (recordsWriteMessage.descriptor.protocol === PermissionsProtocol.uri) {
|
|
156
|
+
return MessagesGrantAuthorization.isPermissionRecordScopeAuthorized(tenant, recordsWriteMessage, incomingScope, messageStore);
|
|
157
|
+
}
|
|
158
|
+
return PermissionScopeMatcher.matches(incomingScope, MessagesGrantAuthorization.getRecordsScopeTarget(recordsWriteMessage));
|
|
159
|
+
}
|
|
160
|
+
static async isPermissionRecordScopeAuthorized(tenant, recordsWriteMessage, incomingScope, messageStore) {
|
|
161
|
+
if (MessagesGrantAuthorization.isSubtreeScope(incomingScope)) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const permissionScope = await PermissionsProtocol.getScopeFromPermissionRecord(tenant, messageStore, recordsWriteMessage);
|
|
165
|
+
return PermissionsProtocol.hasProtocolScope(permissionScope)
|
|
166
|
+
&& PermissionScopeMatcher.matches(incomingScope, permissionScope);
|
|
167
|
+
}
|
|
168
|
+
static isProtocolsConfigureScopeAuthorized(protocolsConfigureMessage, incomingScope) {
|
|
169
|
+
// A delegate with any Messages.Read grant inside a protocol needs that
|
|
170
|
+
// protocol definition to interpret and validate the records it can read.
|
|
171
|
+
return incomingScope.protocol !== undefined &&
|
|
172
|
+
incomingScope.protocol === protocolsConfigureMessage.descriptor.definition.protocol;
|
|
173
|
+
}
|
|
174
|
+
static async getAssociatedRecordsWrite(tenant, recordsMessage, messageStore) {
|
|
175
|
+
if (Records.isRecordsWrite(recordsMessage)) {
|
|
176
|
+
return recordsMessage;
|
|
177
|
+
}
|
|
178
|
+
return RecordsWrite.fetchNewestRecordsWrite(messageStore, tenant, recordsMessage.descriptor.recordId);
|
|
179
|
+
}
|
|
180
|
+
static getRecordsScopeTarget(recordsWriteMessage) {
|
|
181
|
+
const { protocol, protocolPath } = recordsWriteMessage.descriptor;
|
|
182
|
+
const { contextId } = recordsWriteMessage;
|
|
183
|
+
return { protocol, protocolPath, contextId };
|
|
184
|
+
}
|
|
185
|
+
static isSubtreeScope(scope) {
|
|
186
|
+
return scope.protocolPath !== undefined || scope.contextId !== undefined;
|
|
95
187
|
}
|
|
96
188
|
}
|
|
97
189
|
//# sourceMappingURL=messages-grant-authorization.js.map
|