@enbox/dwn-sdk-js 0.0.7 → 0.1.0
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 +817 -911
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +11 -0
- package/dist/esm/src/core/constants.js.map +1 -0
- package/dist/esm/src/core/core-protocol.js +44 -0
- package/dist/esm/src/core/core-protocol.js.map +1 -0
- package/dist/esm/src/core/dwn-error.js +12 -12
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +16 -3
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +5 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +91 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +53 -30
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/records-grant-authorization.js +6 -8
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +2 -0
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/dwn.js +42 -18
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +7 -11
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +22 -24
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +11 -15
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +37 -27
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +7 -11
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +10 -12
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +10 -18
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +11 -15
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +31 -26
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +39 -26
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +128 -105
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +5 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +1 -0
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +33 -3
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +1 -1
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +1 -1
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +1 -1
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +1 -1
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +2 -1
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-signing.js +1 -12
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +25 -41
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +1 -1
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +1 -1
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +113 -5
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +5 -7
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +110 -33
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level.js +42 -32
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +70 -6
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +11 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +0 -8
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/messages.js +16 -34
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/records.js +5 -43
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +2 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +32 -43
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +14 -7
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +9 -5
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +14 -7
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +12 -12
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +636 -5
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +4 -4
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +7 -7
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +4 -4
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-delivery.spec.js +236 -0
- package/dist/esm/tests/features/records-delivery.spec.js.map +1 -0
- package/dist/esm/tests/features/records-immutable.spec.js +315 -0
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +4 -4
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
- package/dist/esm/tests/features/records-squash.spec.js +1055 -0
- package/dist/esm/tests/features/records-squash.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +16 -4
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +7 -8
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +11 -5
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +169 -22
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +103 -21
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +5 -5
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +5 -5
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +9 -4
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +24 -25
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +68 -9
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +24 -138
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +175 -35
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +176 -72
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +52 -68
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +6 -6
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +4 -4
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +4 -4
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +4 -4
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +350 -5
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +4 -4
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +4 -4
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +93 -40
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +102 -41
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +12 -13
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-suite.js +10 -4
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +12 -5
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +8 -12
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +36 -2
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +37 -8
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +49 -40
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +11 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/src/core/core-protocol.d.ts +89 -0
- package/dist/types/src/core/core-protocol.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +12 -12
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +6 -2
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts +30 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +19 -11
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts +2 -1
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +19 -7
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +3 -8
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-sync.d.ts +3 -8
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts +3 -8
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +3 -6
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +3 -8
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -8
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +3 -8
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +12 -25
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +8 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-signing.d.ts +3 -4
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +11 -11
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +1 -1
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +40 -3
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
- package/dist/types/src/store/data-store-level.d.ts +20 -4
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +4 -0
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +20 -6
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +3 -3
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +12 -3
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +24 -3
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +7 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +69 -2
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +23 -6
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/subscriptions.d.ts +151 -13
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -9
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/messages.d.ts +7 -5
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -11
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-delivery.spec.d.ts +2 -0
- package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-squash.spec.d.ts +2 -0
- package/dist/types/tests/features/records-squash.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.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/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-delete.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-read.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/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +11 -12
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +19 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/core/constants.ts +11 -0
- package/src/core/core-protocol.ts +129 -0
- package/src/core/dwn-error.ts +18 -12
- package/src/core/grant-authorization.ts +20 -3
- package/src/core/protocol-authorization-action.ts +5 -0
- package/src/core/protocol-authorization-validation.ts +133 -0
- package/src/core/protocol-authorization.ts +71 -23
- package/src/core/records-grant-authorization.ts +6 -8
- package/src/core/resumable-task-manager.ts +3 -1
- package/src/dwn.ts +58 -73
- package/src/event-stream/event-emitter-event-log.ts +283 -0
- package/src/handlers/messages-read.ts +8 -9
- package/src/handlers/messages-subscribe.ts +24 -28
- package/src/handlers/messages-sync.ts +10 -16
- package/src/handlers/protocols-configure.ts +47 -32
- package/src/handlers/protocols-query.ts +6 -9
- package/src/handlers/records-count.ts +11 -10
- package/src/handlers/records-delete.ts +12 -21
- package/src/handlers/records-query.ts +12 -12
- package/src/handlers/records-read.ts +34 -22
- package/src/handlers/records-subscribe.ts +47 -26
- package/src/handlers/records-write.ts +152 -119
- package/src/index.ts +9 -5
- package/src/interfaces/messages-subscribe.ts +7 -1
- package/src/interfaces/protocols-configure.ts +51 -3
- package/src/interfaces/records-count.ts +1 -1
- package/src/interfaces/records-delete.ts +1 -1
- package/src/interfaces/records-query.ts +1 -1
- package/src/interfaces/records-read.ts +1 -1
- package/src/interfaces/records-subscribe.ts +8 -1
- package/src/interfaces/records-write-signing.ts +2 -22
- package/src/interfaces/records-write.ts +35 -48
- package/src/protocols/permission-grant.ts +1 -1
- package/src/protocols/permission-request.ts +1 -1
- package/src/protocols/permissions.ts +148 -6
- package/src/state-index/state-index-level.ts +5 -7
- package/src/store/data-store-level.ts +124 -34
- package/src/store/index-level.ts +44 -35
- package/src/store/storage-controller.ts +89 -12
- package/src/types/message-types.ts +3 -3
- package/src/types/messages-types.ts +12 -3
- package/src/types/method-handler.ts +26 -4
- package/src/types/mitt.d.ts +28 -0
- package/src/types/permission-types.ts +7 -0
- package/src/types/protocols-types.ts +78 -1
- package/src/types/records-types.ts +24 -6
- package/src/types/subscriptions.ts +178 -14
- package/src/utils/hd-key.ts +0 -9
- package/src/utils/messages.ts +17 -37
- package/src/utils/records.ts +7 -58
- package/dist/esm/src/event-stream/event-emitter-stream.js +0 -46
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -68
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +0 -114
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
- package/src/event-stream/event-emitter-stream.ts +0 -69
|
@@ -16,7 +16,7 @@ import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
|
16
16
|
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
17
17
|
import { isCrossProtocolRef, parseCrossProtocolRef } from '../utils/protocols.js';
|
|
18
18
|
import { normalizeProtocolUrl, normalizeSchemaUrl, validateProtocolUrlNormalized, validateSchemaUrlNormalized } from '../utils/url.js';
|
|
19
|
-
import { ProtocolAction, ProtocolActor } from '../types/protocols-types.js';
|
|
19
|
+
import { ProtocolAction, ProtocolActor, ProtocolRecordLimitStrategy } from '../types/protocols-types.js';
|
|
20
20
|
|
|
21
21
|
export type ProtocolsConfigureOptions = {
|
|
22
22
|
messageTimestamp?: string;
|
|
@@ -68,7 +68,7 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
68
68
|
* @param messageStore Used to check if the grant has been revoked.
|
|
69
69
|
*/
|
|
70
70
|
public async authorizeAuthorDelegate(messageStore: MessageStore): Promise<void> {
|
|
71
|
-
const delegatedGrant =
|
|
71
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization.authorDelegatedGrant!);
|
|
72
72
|
await ProtocolsGrantAuthorization.authorizeConfigure({
|
|
73
73
|
protocolsConfigureMessage : this.message,
|
|
74
74
|
expectedGrantor : this.author!,
|
|
@@ -232,6 +232,27 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
+
// Validate $recordLimit
|
|
236
|
+
if (ruleSet.$recordLimit !== undefined) {
|
|
237
|
+
const { max, strategy } = ruleSet.$recordLimit;
|
|
238
|
+
|
|
239
|
+
if (!Number.isInteger(max) || max < 1) {
|
|
240
|
+
throw new DwnError(
|
|
241
|
+
DwnErrorCode.ProtocolsConfigureInvalidRecordLimit,
|
|
242
|
+
`Invalid $recordLimit.max value ${max} at protocol path '${ruleSetProtocolPath}': must be an integer >= 1.`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const validStrategies = Object.values(ProtocolRecordLimitStrategy) as string[];
|
|
247
|
+
if (!validStrategies.includes(strategy as string)) {
|
|
248
|
+
throw new DwnError(
|
|
249
|
+
DwnErrorCode.ProtocolsConfigureInvalidRecordLimit,
|
|
250
|
+
`Invalid $recordLimit.strategy '${strategy}' at protocol path '${ruleSetProtocolPath}': ` +
|
|
251
|
+
`must be one of ${validStrategies.join(', ')}.`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
235
256
|
if (ruleSet.$tags) {
|
|
236
257
|
const ajv = new Ajv.default();
|
|
237
258
|
const { $allowUndefinedTags, $requiredTags, ...tagProperties } = ruleSet.$tags;
|
|
@@ -397,6 +418,33 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
397
418
|
}
|
|
398
419
|
}
|
|
399
420
|
|
|
421
|
+
// Warn when `$delivery` is set without `$actions`.
|
|
422
|
+
// Delivery targets are determined from `$actions` role records and actor rules.
|
|
423
|
+
// Without `$actions`, the server cannot determine who to deliver records to.
|
|
424
|
+
if (ruleSet.$delivery !== undefined && (ruleSet.$actions === undefined || ruleSet.$actions.length === 0)) {
|
|
425
|
+
console.warn(
|
|
426
|
+
`ProtocolsConfigure: protocol path '${ruleSetProtocolPath}' has $delivery: '${ruleSet.$delivery}' ` +
|
|
427
|
+
`but no $actions rules. The server uses $actions to determine delivery targets — ` +
|
|
428
|
+
`without $actions, no participants can be resolved for delivery.`
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Warn when `$immutable: true` is combined with `$actions` that include `update` or `co-update`.
|
|
433
|
+
// The `$immutable` directive overrides any update permission — updates are always rejected.
|
|
434
|
+
if (ruleSet.$immutable === true && actionRules.length > 0) {
|
|
435
|
+
const hasUpdateAction = actionRules.some(
|
|
436
|
+
(rule: ProtocolActionRule): boolean =>
|
|
437
|
+
rule.can.includes(ProtocolAction.Update) || rule.can.includes(ProtocolAction.CoUpdate)
|
|
438
|
+
);
|
|
439
|
+
if (hasUpdateAction) {
|
|
440
|
+
console.warn(
|
|
441
|
+
`ProtocolsConfigure: protocol path '${ruleSetProtocolPath}' has $immutable: true ` +
|
|
442
|
+
`but $actions include 'update' or 'co-update'. The $immutable directive takes ` +
|
|
443
|
+
`precedence — updates will always be rejected regardless of action rules.`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
400
448
|
// Validate nested rule sets
|
|
401
449
|
for (const recordType in ruleSet) {
|
|
402
450
|
if (recordType.startsWith('$')) {
|
|
@@ -457,7 +505,7 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
457
505
|
}
|
|
458
506
|
|
|
459
507
|
// validate that `$ref` nodes do not have other directives
|
|
460
|
-
const forbiddenDirectives = ['$actions', '$role', '$size', '$tags', '$encryption'] as const;
|
|
508
|
+
const forbiddenDirectives = ['$actions', '$role', '$size', '$tags', '$encryption', '$recordLimit', '$immutable', '$delivery', '$squash'] as const;
|
|
461
509
|
for (const directive of forbiddenDirectives) {
|
|
462
510
|
if (ruleSet[directive] !== undefined) {
|
|
463
511
|
throw new DwnError(
|
|
@@ -94,7 +94,7 @@ export class RecordsCount extends AbstractMessage<RecordsCountMessage> {
|
|
|
94
94
|
* @param messageStore Used to check if the grant has been revoked.
|
|
95
95
|
*/
|
|
96
96
|
public async authorizeDelegate(messageStore: MessageStore): Promise<void> {
|
|
97
|
-
const delegatedGrant =
|
|
97
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
98
98
|
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
99
99
|
incomingMessage : this.message,
|
|
100
100
|
expectedGrantor : this.author!,
|
|
@@ -110,7 +110,7 @@ export class RecordsDelete extends AbstractMessage<RecordsDeleteMessage> {
|
|
|
110
110
|
* @param messageStore Used to check if the grant has been revoked.
|
|
111
111
|
*/
|
|
112
112
|
public async authorizeDelegate(recordsWriteToDelete: RecordsWriteMessage, messageStore: MessageStore): Promise<void> {
|
|
113
|
-
const delegatedGrant =
|
|
113
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
114
114
|
await RecordsGrantAuthorization.authorizeDelete({
|
|
115
115
|
recordsDeleteMessage : this.message,
|
|
116
116
|
recordsWriteToDelete,
|
|
@@ -119,7 +119,7 @@ export class RecordsQuery extends AbstractMessage<RecordsQueryMessage> {
|
|
|
119
119
|
* @param messageStore Used to check if the grant has been revoked.
|
|
120
120
|
*/
|
|
121
121
|
public async authorizeDelegate(messageStore: MessageStore): Promise<void> {
|
|
122
|
-
const delegatedGrant =
|
|
122
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
123
123
|
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
124
124
|
incomingMessage : this.message,
|
|
125
125
|
expectedGrantee : this.signer!,
|
|
@@ -110,7 +110,7 @@ export class RecordsRead extends AbstractMessage<RecordsReadMessage> {
|
|
|
110
110
|
* @param messageStore Used to check if the grant has been revoked.
|
|
111
111
|
*/
|
|
112
112
|
public async authorizeDelegate(matchedRecordsWrite: RecordsWriteMessage, messageStore: MessageStore): Promise<void> {
|
|
113
|
-
const delegatedGrant =
|
|
113
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
114
114
|
await RecordsGrantAuthorization.authorizeRead({
|
|
115
115
|
recordsReadMessage : this.message,
|
|
116
116
|
recordsWriteMessageToBeRead : matchedRecordsWrite,
|
|
@@ -22,6 +22,12 @@ export type RecordsSubscribeOptions = {
|
|
|
22
22
|
signer?: MessageSigner;
|
|
23
23
|
protocolRole?: string;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Opaque EventLog cursor string to resume from. When provided, catch-up events are
|
|
27
|
+
* replayed from the EventLog and an EOSE marker is delivered before live events.
|
|
28
|
+
*/
|
|
29
|
+
cursor?: string;
|
|
30
|
+
|
|
25
31
|
/**
|
|
26
32
|
* The delegated grant to sign on behalf of the logical author, which is the grantor (`grantedBy`) of the delegated grant.
|
|
27
33
|
*/
|
|
@@ -68,6 +74,7 @@ export class RecordsSubscribe extends AbstractMessage<RecordsSubscribeMessage> {
|
|
|
68
74
|
filter : Records.normalizeFilter(options.filter),
|
|
69
75
|
dateSort : options.dateSort,
|
|
70
76
|
pagination : options.pagination,
|
|
77
|
+
cursor : options.cursor,
|
|
71
78
|
};
|
|
72
79
|
|
|
73
80
|
// delete all descriptor properties that are `undefined` else the code will encounter the following IPLD issue when attempting to generate CID:
|
|
@@ -97,7 +104,7 @@ export class RecordsSubscribe extends AbstractMessage<RecordsSubscribeMessage> {
|
|
|
97
104
|
* @param messageStore Used to check if the grant has been revoked.
|
|
98
105
|
*/
|
|
99
106
|
public async authorizeDelegate(messageStore: MessageStore): Promise<void> {
|
|
100
|
-
const delegatedGrant =
|
|
107
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
101
108
|
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
102
109
|
incomingMessage : this.message,
|
|
103
110
|
expectedGrantor : this.author!,
|
|
@@ -1,48 +1,28 @@
|
|
|
1
1
|
import type { GeneralJws } from '../types/jws-types.js';
|
|
2
2
|
import type { MessageSigner } from '../types/signer.js';
|
|
3
3
|
import type { EncryptionInput, JweEncryption } from '../utils/encryption.js';
|
|
4
|
-
import type { RecordsWriteAttestationPayload,
|
|
4
|
+
import type { RecordsWriteAttestationPayload, RecordsWriteMessage, RecordsWriteSignaturePayload } from '../types/records-types.js';
|
|
5
5
|
|
|
6
6
|
import { Cid } from '../utils/cid.js';
|
|
7
7
|
import { Encoder } from '../utils/encoder.js';
|
|
8
8
|
import { Encryption } from '../utils/encryption.js';
|
|
9
9
|
import { GeneralJwsBuilder } from '../jose/jws/general/builder.js';
|
|
10
10
|
import { Jws } from '../utils/jws.js';
|
|
11
|
-
import { KeyDerivationScheme } from '../utils/hd-key.js';
|
|
12
11
|
import { removeUndefinedProperties } from '../utils/object.js';
|
|
13
12
|
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Creates the JWE `encryption` property if encryption input is given. Else `undefined` is returned.
|
|
17
16
|
* Uses ECDH-ES+A256KW key agreement with X25519 and AEAD content encryption (A256GCM or XC20P).
|
|
18
|
-
* @param descriptor Descriptor of the `RecordsWrite` message which contains the information needed by key path derivation schemes.
|
|
19
17
|
* @param encryptionInput The encryption input containing CEK, IV, authentication tag, and recipient key encryption inputs.
|
|
20
18
|
*/
|
|
21
19
|
export async function createEncryptionProperty(
|
|
22
|
-
descriptor: RecordsWriteDescriptor,
|
|
23
20
|
encryptionInput: EncryptionInput | undefined,
|
|
24
21
|
): Promise<JweEncryption | undefined> {
|
|
25
22
|
if (encryptionInput === undefined) {
|
|
26
23
|
return undefined;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
// Validate derivation scheme prerequisites
|
|
30
|
-
for (const keyEncryptionInput of encryptionInput.keyEncryptionInputs) {
|
|
31
|
-
if (keyEncryptionInput.derivationScheme === KeyDerivationScheme.ProtocolPath && descriptor.protocol === undefined) {
|
|
32
|
-
throw new DwnError(
|
|
33
|
-
DwnErrorCode.RecordsWriteMissingProtocol,
|
|
34
|
-
'`protocols` encryption scheme cannot be applied to record without the `protocol` property.'
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (keyEncryptionInput.derivationScheme === KeyDerivationScheme.Schemas && descriptor.schema === undefined) {
|
|
39
|
-
throw new DwnError(
|
|
40
|
-
DwnErrorCode.RecordsWriteMissingSchema,
|
|
41
|
-
'`schemas` encryption scheme cannot be applied to record without the `schema` property.'
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
26
|
// Build the JWE structure. The authentication tag comes from the AEAD encryption of record data.
|
|
47
27
|
const jwe = await Encryption.buildJwe(encryptionInput, encryptionInput.authenticationTag);
|
|
48
28
|
|
|
@@ -69,7 +49,7 @@ export async function createAttestation(descriptorCid: string, signers?: Message
|
|
|
69
49
|
*/
|
|
70
50
|
export async function createSignerSignature(input: {
|
|
71
51
|
recordId: string,
|
|
72
|
-
contextId: string
|
|
52
|
+
contextId: string,
|
|
73
53
|
descriptorCid: string,
|
|
74
54
|
attestation: GeneralJws | undefined,
|
|
75
55
|
encryption: JweEncryption | undefined,
|
|
@@ -43,8 +43,8 @@ import { normalizeProtocolUrl, normalizeSchemaUrl, validateProtocolUrlNormalized
|
|
|
43
43
|
|
|
44
44
|
export type RecordsWriteOptions = {
|
|
45
45
|
recipient?: string;
|
|
46
|
-
protocol
|
|
47
|
-
protocolPath
|
|
46
|
+
protocol: string;
|
|
47
|
+
protocolPath: string;
|
|
48
48
|
protocolRole?: string;
|
|
49
49
|
schema?: string;
|
|
50
50
|
tags?: RecordsWriteTags;
|
|
@@ -52,7 +52,7 @@ export type RecordsWriteOptions = {
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Must be given if this message is for a non-root protocol record.
|
|
55
|
-
* If not given, it
|
|
55
|
+
* If not given, it means this write is for a root protocol record.
|
|
56
56
|
*/
|
|
57
57
|
parentContextId?: string;
|
|
58
58
|
|
|
@@ -79,6 +79,13 @@ export type RecordsWriteOptions = {
|
|
|
79
79
|
encryptionInput?: EncryptionInput;
|
|
80
80
|
permissionGrantId?: string;
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* When `true`, this record is a squash (snapshot) write that atomically creates a snapshot
|
|
84
|
+
* and deletes all older sibling records at the same protocol path within the same parent context.
|
|
85
|
+
* Only valid at protocol paths with `$squash: true`. Must be an initial write (new record).
|
|
86
|
+
*/
|
|
87
|
+
squash?: true;
|
|
88
|
+
|
|
82
89
|
/**
|
|
83
90
|
* The author's ProtocolPath-derived public key for key delivery.
|
|
84
91
|
* When set, this is attached to the authorization model so the DWN owner
|
|
@@ -282,12 +289,11 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
282
289
|
* @param options.dateCreated If `undefined`, it will be auto-filled with current time.
|
|
283
290
|
* @param options.messageTimestamp If `undefined`, it will be auto-filled with current time.
|
|
284
291
|
* @param options.parentContextId Must be given if this message is for a non-root protocol record.
|
|
285
|
-
* If not given, it
|
|
292
|
+
* If not given, it means this write is for a root protocol record.
|
|
286
293
|
*/
|
|
287
294
|
public static async create(options: RecordsWriteOptions): Promise<RecordsWrite> {
|
|
288
|
-
if (
|
|
289
|
-
(
|
|
290
|
-
throw new DwnError(DwnErrorCode.RecordsWriteCreateProtocolAndProtocolPathMutuallyInclusive, '`protocol` and `protocolPath` must both be defined or undefined at the same time');
|
|
295
|
+
if (options.protocol === undefined || options.protocolPath === undefined) {
|
|
296
|
+
throw new DwnError(DwnErrorCode.RecordsWriteCreateMissingProtocol, '`protocol` and `protocolPath` are required');
|
|
291
297
|
}
|
|
292
298
|
|
|
293
299
|
if ((options.data === undefined && options.dataCid === undefined) ||
|
|
@@ -312,7 +318,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
312
318
|
const descriptor: RecordsWriteDescriptor = {
|
|
313
319
|
interface : DwnInterfaceName.Records,
|
|
314
320
|
method : DwnMethodName.Write,
|
|
315
|
-
protocol :
|
|
321
|
+
protocol : normalizeProtocolUrl(options.protocol),
|
|
316
322
|
protocolPath : options.protocolPath,
|
|
317
323
|
recipient : options.recipient,
|
|
318
324
|
schema : options.schema !== undefined ? normalizeSchemaUrl(options.schema) : undefined,
|
|
@@ -326,6 +332,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
326
332
|
datePublished : options.datePublished,
|
|
327
333
|
dataFormat : options.dataFormat,
|
|
328
334
|
permissionGrantId : options.permissionGrantId,
|
|
335
|
+
squash : options.squash,
|
|
329
336
|
};
|
|
330
337
|
|
|
331
338
|
// generate `datePublished` if the message is to be published but `datePublished` is not given
|
|
@@ -346,7 +353,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
346
353
|
const attestation = await createAttestation(descriptorCid, options.attestationSigners);
|
|
347
354
|
|
|
348
355
|
// `encryption` generation
|
|
349
|
-
const encryption = await createEncryptionProperty(
|
|
356
|
+
const encryption = await createEncryptionProperty(options.encryptionInput);
|
|
350
357
|
|
|
351
358
|
const message: InternalRecordsWriteMessage = {
|
|
352
359
|
recordId,
|
|
@@ -474,7 +481,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
474
481
|
}
|
|
475
482
|
|
|
476
483
|
// Build only the new recipients (reuses createEncryptionProperty for ECDH-ES+A256KW logic)
|
|
477
|
-
const newEncryption = await createEncryptionProperty(
|
|
484
|
+
const newEncryption = await createEncryptionProperty(encryptionInput);
|
|
478
485
|
if (newEncryption) {
|
|
479
486
|
this._message.encryption.recipients.push(...newEncryption.recipients);
|
|
480
487
|
}
|
|
@@ -493,7 +500,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
493
500
|
// the contextKey schema. We chose the in-record approach because it keeps
|
|
494
501
|
// records self-contained and the read/decrypt path unchanged.
|
|
495
502
|
} else {
|
|
496
|
-
this._message.encryption = await createEncryptionProperty(
|
|
503
|
+
this._message.encryption = await createEncryptionProperty(encryptionInput);
|
|
497
504
|
|
|
498
505
|
// Full replacement invalidates the authorization — caller must re-sign.
|
|
499
506
|
delete this._message.authorization;
|
|
@@ -530,22 +537,19 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
530
537
|
// compute `recordId` if not given at construction time
|
|
531
538
|
this._message.recordId = this._message.recordId ?? await RecordsWrite.getEntryId(authorDid, descriptor);
|
|
532
539
|
|
|
533
|
-
// compute `contextId`
|
|
534
|
-
if (this.
|
|
535
|
-
//
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
this._message.contextId = this.parentContextId + '/' + this._message.recordId;
|
|
542
|
-
}
|
|
540
|
+
// compute `contextId` — all records belong to a protocol
|
|
541
|
+
if (this.parentContextId === undefined || this.parentContextId === '') {
|
|
542
|
+
// root protocol record
|
|
543
|
+
this._message.contextId = this._message.recordId;
|
|
544
|
+
} else {
|
|
545
|
+
// non-root protocol record
|
|
546
|
+
this._message.contextId = this.parentContextId + '/' + this._message.recordId;
|
|
543
547
|
}
|
|
544
548
|
|
|
545
549
|
// `signature` generation
|
|
546
550
|
const signature = await createSignerSignature({
|
|
547
551
|
recordId : this._message.recordId,
|
|
548
|
-
contextId : this._message.contextId,
|
|
552
|
+
contextId : this._message.contextId!, // contextId is computed just above, always defined here
|
|
549
553
|
descriptorCid,
|
|
550
554
|
attestation : this._message.attestation,
|
|
551
555
|
encryption : this._message.encryption,
|
|
@@ -589,7 +593,6 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
589
593
|
|
|
590
594
|
this._ownerSignaturePayload = Jws.decodePlainObjectPayload(ownerSignature);
|
|
591
595
|
this._owner = Jws.extractDid(signer.keyId);
|
|
592
|
-
;
|
|
593
596
|
}
|
|
594
597
|
|
|
595
598
|
/**
|
|
@@ -634,9 +637,8 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
634
637
|
);
|
|
635
638
|
}
|
|
636
639
|
|
|
637
|
-
// if the message is
|
|
638
|
-
if (this.message.descriptor.
|
|
639
|
-
this.message.descriptor.parentId === undefined) {
|
|
640
|
+
// if the message is a protocol context root, the `contextId` must match the expected deterministic value
|
|
641
|
+
if (this.message.descriptor.parentId === undefined) {
|
|
640
642
|
const expectedContextId = await this.getEntryId();
|
|
641
643
|
|
|
642
644
|
if (this.message.contextId !== expectedContextId) {
|
|
@@ -699,9 +701,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
699
701
|
}
|
|
700
702
|
}
|
|
701
703
|
|
|
702
|
-
|
|
703
|
-
validateProtocolUrlNormalized(this.message.descriptor.protocol);
|
|
704
|
-
}
|
|
704
|
+
validateProtocolUrlNormalized(this.message.descriptor.protocol);
|
|
705
705
|
if (this.message.descriptor.schema !== undefined) {
|
|
706
706
|
validateSchemaUrlNormalized(this.message.descriptor.schema);
|
|
707
707
|
}
|
|
@@ -713,13 +713,6 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
715
|
|
|
716
|
-
/**
|
|
717
|
-
* Delegate to the standalone `validateAttestationIntegrity` function for backward compatibility.
|
|
718
|
-
*/
|
|
719
|
-
private static async validateAttestationIntegrity(message: RecordsWriteMessage): Promise<void> {
|
|
720
|
-
return validateAttestationIntegrity(message);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
716
|
/**
|
|
724
717
|
* Computes the deterministic Entry ID of this message.
|
|
725
718
|
*/
|
|
@@ -757,11 +750,13 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
757
750
|
// we want to process tags separately from the rest of descriptors as it is an object and not a primitive KeyValue type.
|
|
758
751
|
const { tags, ...descriptor } = message.descriptor;
|
|
759
752
|
delete descriptor.published; // handle `published` specifically further down
|
|
753
|
+
delete descriptor.squash; // handle `squash` specifically further down
|
|
760
754
|
|
|
761
755
|
let indexes: KeyValues = {
|
|
762
756
|
...descriptor,
|
|
763
757
|
isLatestBaseState,
|
|
764
758
|
published : !!message.descriptor.published,
|
|
759
|
+
squash : !!message.descriptor.squash,
|
|
765
760
|
author : this.author!, //author will not be undefined when indexes are constructed as it's been authorized
|
|
766
761
|
recordId : message.recordId,
|
|
767
762
|
entryId : await RecordsWrite.getEntryId(this.author, this.message.descriptor)
|
|
@@ -778,7 +773,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
778
773
|
// add additional indexes to optional values if given
|
|
779
774
|
// TODO: index multiple attesters (https://github.com/enboxorg/enbox/issues/223)
|
|
780
775
|
if (this.attesters.length > 0) { indexes.attester = this.attesters[0]; }
|
|
781
|
-
|
|
776
|
+
indexes.contextId = message.contextId;
|
|
782
777
|
|
|
783
778
|
return indexes;
|
|
784
779
|
}
|
|
@@ -788,7 +783,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
788
783
|
* @param messageStore Used to check if the grant has been revoked.
|
|
789
784
|
*/
|
|
790
785
|
public async authorizeAuthorDelegate(messageStore: MessageStore): Promise<void> {
|
|
791
|
-
const delegatedGrant =
|
|
786
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization.authorDelegatedGrant!);
|
|
792
787
|
await RecordsGrantAuthorization.authorizeWrite({
|
|
793
788
|
recordsWriteMessage : this.message,
|
|
794
789
|
expectedGrantor : this.author!,
|
|
@@ -803,7 +798,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
803
798
|
* @param messageStore Used to check if the grant has been revoked.
|
|
804
799
|
*/
|
|
805
800
|
public async authorizeOwnerDelegate(messageStore: MessageStore): Promise<void> {
|
|
806
|
-
const delegatedGrant =
|
|
801
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization.ownerDelegatedGrant!);
|
|
807
802
|
await RecordsGrantAuthorization.authorizeWrite({
|
|
808
803
|
recordsWriteMessage : this.message,
|
|
809
804
|
expectedGrantor : this.owner!,
|
|
@@ -829,14 +824,6 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
829
824
|
return (entryId === recordsWriteMessage.recordId);
|
|
830
825
|
}
|
|
831
826
|
|
|
832
|
-
/** Delegate to `createEncryptionProperty` in `records-write-signing.ts`. */
|
|
833
|
-
private static async createEncryptionProperty(
|
|
834
|
-
descriptor: RecordsWriteDescriptor,
|
|
835
|
-
encryptionInput: EncryptionInput | undefined,
|
|
836
|
-
): Promise<JweEncryption | undefined> {
|
|
837
|
-
return createEncryptionProperty(descriptor, encryptionInput);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
827
|
/** Delegate to `createAttestation` in `records-write-signing.ts`. */
|
|
841
828
|
public static async createAttestation(descriptorCid: string, signers?: MessageSigner[]): Promise<GeneralJws | undefined> {
|
|
842
829
|
return createAttestation(descriptorCid, signers);
|
|
@@ -845,7 +832,7 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
845
832
|
/** Delegate to `createSignerSignature` in `records-write-signing.ts`. */
|
|
846
833
|
public static async createSignerSignature(input: {
|
|
847
834
|
recordId: string,
|
|
848
|
-
contextId: string
|
|
835
|
+
contextId: string,
|
|
849
836
|
descriptorCid: string,
|
|
850
837
|
attestation: GeneralJws | undefined,
|
|
851
838
|
encryption: JweEncryption | undefined,
|
|
@@ -68,7 +68,7 @@ export class PermissionGrant {
|
|
|
68
68
|
* and that the decoded data contains `scope` and `dateExpires`.
|
|
69
69
|
* @throws {DwnError} if any required field is missing.
|
|
70
70
|
*/
|
|
71
|
-
public static
|
|
71
|
+
public static parse(message: DataEncodedRecordsWriteMessage): PermissionGrant {
|
|
72
72
|
PermissionGrant.validateMessage(message);
|
|
73
73
|
const permissionGrant = new PermissionGrant(message);
|
|
74
74
|
return permissionGrant;
|
|
@@ -49,7 +49,7 @@ export class PermissionRequest {
|
|
|
49
49
|
* and that the decoded data contains `scope`.
|
|
50
50
|
* @throws {DwnError} if any required field is missing.
|
|
51
51
|
*/
|
|
52
|
-
public static
|
|
52
|
+
public static parse(message: DataEncodedRecordsWriteMessage): PermissionRequest {
|
|
53
53
|
PermissionRequest.validateMessage(message);
|
|
54
54
|
const permissionRequest = new PermissionRequest(message);
|
|
55
55
|
return permissionRequest;
|