@enbox/dwn-sdk-js 0.0.1
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/LICENSE +201 -0
- package/README.md +352 -0
- package/dist/bundles/dwn.js +153 -0
- package/dist/cjs/index.js +36749 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/generated/precompiled-validators.js +11973 -0
- package/dist/esm/generated/precompiled-validators.js.map +1 -0
- package/dist/esm/json-schemas/definitions.json +23 -0
- package/dist/esm/src/core/abstract-message.js +47 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -0
- package/dist/esm/src/core/auth.js +39 -0
- package/dist/esm/src/core/auth.js.map +1 -0
- package/dist/esm/src/core/dwn-constant.js +10 -0
- package/dist/esm/src/core/dwn-constant.js.map +1 -0
- package/dist/esm/src/core/dwn-error.js +169 -0
- package/dist/esm/src/core/dwn-error.js.map +1 -0
- package/dist/esm/src/core/grant-authorization.js +97 -0
- package/dist/esm/src/core/grant-authorization.js.map +1 -0
- package/dist/esm/src/core/message-reply.js +5 -0
- package/dist/esm/src/core/message-reply.js.map +1 -0
- package/dist/esm/src/core/message.js +233 -0
- package/dist/esm/src/core/message.js.map +1 -0
- package/dist/esm/src/core/messages-grant-authorization.js +101 -0
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +608 -0
- package/dist/esm/src/core/protocol-authorization.js.map +1 -0
- package/dist/esm/src/core/protocols-grant-authorization.js +66 -0
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +132 -0
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -0
- package/dist/esm/src/core/resumable-task-manager.js +109 -0
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -0
- package/dist/esm/src/core/tenant-gate.js +20 -0
- package/dist/esm/src/core/tenant-gate.js.map +1 -0
- package/dist/esm/src/dwn.js +164 -0
- package/dist/esm/src/dwn.js.map +1 -0
- package/dist/esm/src/enums/dwn-interface-method.js +16 -0
- package/dist/esm/src/enums/dwn-interface-method.js.map +1 -0
- package/dist/esm/src/event-log/event-emitter-stream.js +60 -0
- package/dist/esm/src/event-log/event-emitter-stream.js.map +1 -0
- package/dist/esm/src/event-log/event-log-level.js +63 -0
- package/dist/esm/src/event-log/event-log-level.js.map +1 -0
- package/dist/esm/src/handlers/messages-query.js +71 -0
- package/dist/esm/src/handlers/messages-query.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +102 -0
- package/dist/esm/src/handlers/messages-read.js.map +1 -0
- package/dist/esm/src/handlers/messages-subscribe.js +81 -0
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -0
- package/dist/esm/src/handlers/protocols-configure.js +133 -0
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -0
- package/dist/esm/src/handlers/protocols-query.js +73 -0
- package/dist/esm/src/handlers/protocols-query.js.map +1 -0
- package/dist/esm/src/handlers/records-delete.js +107 -0
- package/dist/esm/src/handlers/records-delete.js.map +1 -0
- package/dist/esm/src/handlers/records-query.js +210 -0
- package/dist/esm/src/handlers/records-query.js.map +1 -0
- package/dist/esm/src/handlers/records-read.js +169 -0
- package/dist/esm/src/handlers/records-read.js.map +1 -0
- package/dist/esm/src/handlers/records-subscribe.js +172 -0
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -0
- package/dist/esm/src/handlers/records-write.js +344 -0
- package/dist/esm/src/handlers/records-write.js.map +1 -0
- package/dist/esm/src/index.js +49 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/interfaces/messages-query.js +53 -0
- package/dist/esm/src/interfaces/messages-query.js.map +1 -0
- package/dist/esm/src/interfaces/messages-read.js +61 -0
- package/dist/esm/src/interfaces/messages-read.js.map +1 -0
- package/dist/esm/src/interfaces/messages-subscribe.js +58 -0
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-configure.js +271 -0
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-query.js +84 -0
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-delete.js +89 -0
- package/dist/esm/src/interfaces/records-delete.js.map +1 -0
- package/dist/esm/src/interfaces/records-query.js +104 -0
- package/dist/esm/src/interfaces/records-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-read.js +84 -0
- package/dist/esm/src/interfaces/records-read.js.map +1 -0
- package/dist/esm/src/interfaces/records-subscribe.js +91 -0
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +795 -0
- package/dist/esm/src/interfaces/records-write.js.map +1 -0
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +51 -0
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -0
- package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js +20 -0
- package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js.map +1 -0
- package/dist/esm/src/jose/jws/general/builder.js +47 -0
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -0
- package/dist/esm/src/jose/jws/general/verifier.js +97 -0
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -0
- package/dist/esm/src/protocols/permission-grant.js +39 -0
- package/dist/esm/src/protocols/permission-grant.js.map +1 -0
- package/dist/esm/src/protocols/permission-request.js +35 -0
- package/dist/esm/src/protocols/permission-request.js.map +1 -0
- package/dist/esm/src/protocols/permissions.js +357 -0
- package/dist/esm/src/protocols/permissions.js.map +1 -0
- package/dist/esm/src/schema-validator.js +37 -0
- package/dist/esm/src/schema-validator.js.map +1 -0
- package/dist/esm/src/store/blockstore-level.js +187 -0
- package/dist/esm/src/store/blockstore-level.js.map +1 -0
- package/dist/esm/src/store/blockstore-mock.js +168 -0
- package/dist/esm/src/store/blockstore-mock.js.map +1 -0
- package/dist/esm/src/store/data-store-level.js +136 -0
- package/dist/esm/src/store/data-store-level.js.map +1 -0
- package/dist/esm/src/store/index-level.js +660 -0
- package/dist/esm/src/store/index-level.js.map +1 -0
- package/dist/esm/src/store/level-wrapper.js +305 -0
- package/dist/esm/src/store/level-wrapper.js.map +1 -0
- package/dist/esm/src/store/message-store-level.js +159 -0
- package/dist/esm/src/store/message-store-level.js.map +1 -0
- package/dist/esm/src/store/resumable-task-store-level.js +131 -0
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -0
- package/dist/esm/src/store/storage-controller.js +184 -0
- package/dist/esm/src/store/storage-controller.js.map +1 -0
- package/dist/esm/src/types/cache.js +2 -0
- package/dist/esm/src/types/cache.js.map +1 -0
- package/dist/esm/src/types/data-store.js +2 -0
- package/dist/esm/src/types/data-store.js.map +1 -0
- package/dist/esm/src/types/event-log.js +2 -0
- package/dist/esm/src/types/event-log.js.map +1 -0
- package/dist/esm/src/types/jose-types.js +2 -0
- package/dist/esm/src/types/jose-types.js.map +1 -0
- package/dist/esm/src/types/jws-types.js +2 -0
- package/dist/esm/src/types/jws-types.js.map +1 -0
- package/dist/esm/src/types/message-interface.js +2 -0
- package/dist/esm/src/types/message-interface.js.map +1 -0
- package/dist/esm/src/types/message-store.js +2 -0
- package/dist/esm/src/types/message-store.js.map +1 -0
- package/dist/esm/src/types/message-types.js +3 -0
- package/dist/esm/src/types/message-types.js.map +1 -0
- package/dist/esm/src/types/messages-types.js +2 -0
- package/dist/esm/src/types/messages-types.js.map +1 -0
- package/dist/esm/src/types/method-handler.js +2 -0
- package/dist/esm/src/types/method-handler.js.map +1 -0
- package/dist/esm/src/types/permission-types.js +6 -0
- package/dist/esm/src/types/permission-types.js.map +1 -0
- package/dist/esm/src/types/protocols-types.js +20 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -0
- package/dist/esm/src/types/query-types.js +6 -0
- package/dist/esm/src/types/query-types.js.map +1 -0
- package/dist/esm/src/types/records-types.js +8 -0
- package/dist/esm/src/types/records-types.js.map +1 -0
- package/dist/esm/src/types/resumable-task-store.js +2 -0
- package/dist/esm/src/types/resumable-task-store.js.map +1 -0
- package/dist/esm/src/types/signer.js +2 -0
- package/dist/esm/src/types/signer.js.map +1 -0
- package/dist/esm/src/types/subscriptions.js +2 -0
- package/dist/esm/src/types/subscriptions.js.map +1 -0
- package/dist/esm/src/utils/abort.js +40 -0
- package/dist/esm/src/utils/abort.js.map +1 -0
- package/dist/esm/src/utils/array.js +72 -0
- package/dist/esm/src/utils/array.js.map +1 -0
- package/dist/esm/src/utils/cid.js +130 -0
- package/dist/esm/src/utils/cid.js.map +1 -0
- package/dist/esm/src/utils/data-stream.js +100 -0
- package/dist/esm/src/utils/data-stream.js.map +1 -0
- package/dist/esm/src/utils/encoder.js +45 -0
- package/dist/esm/src/utils/encoder.js.map +1 -0
- package/dist/esm/src/utils/encryption.js +128 -0
- package/dist/esm/src/utils/encryption.js.map +1 -0
- package/dist/esm/src/utils/filter.js +229 -0
- package/dist/esm/src/utils/filter.js.map +1 -0
- package/dist/esm/src/utils/hd-key.js +114 -0
- package/dist/esm/src/utils/hd-key.js.map +1 -0
- package/dist/esm/src/utils/jws.js +89 -0
- package/dist/esm/src/utils/jws.js.map +1 -0
- package/dist/esm/src/utils/memory-cache.js +41 -0
- package/dist/esm/src/utils/memory-cache.js.map +1 -0
- package/dist/esm/src/utils/messages.js +84 -0
- package/dist/esm/src/utils/messages.js.map +1 -0
- package/dist/esm/src/utils/object.js +40 -0
- package/dist/esm/src/utils/object.js.map +1 -0
- package/dist/esm/src/utils/private-key-signer.js +43 -0
- package/dist/esm/src/utils/private-key-signer.js.map +1 -0
- package/dist/esm/src/utils/protocols.js +51 -0
- package/dist/esm/src/utils/protocols.js.map +1 -0
- package/dist/esm/src/utils/records.js +454 -0
- package/dist/esm/src/utils/records.js.map +1 -0
- package/dist/esm/src/utils/secp256k1.js +166 -0
- package/dist/esm/src/utils/secp256k1.js.map +1 -0
- package/dist/esm/src/utils/secp256r1.js +120 -0
- package/dist/esm/src/utils/secp256r1.js.map +1 -0
- package/dist/esm/src/utils/string.js +16 -0
- package/dist/esm/src/utils/string.js.map +1 -0
- package/dist/esm/src/utils/time.js +85 -0
- package/dist/esm/src/utils/time.js.map +1 -0
- package/dist/esm/src/utils/url.js +62 -0
- package/dist/esm/src/utils/url.js.map +1 -0
- package/dist/esm/tests/core/auth.spec.js +22 -0
- package/dist/esm/tests/core/auth.spec.js.map +1 -0
- package/dist/esm/tests/core/message-reply.spec.js +16 -0
- package/dist/esm/tests/core/message-reply.spec.js.map +1 -0
- package/dist/esm/tests/core/message.spec.js +146 -0
- package/dist/esm/tests/core/message.spec.js.map +1 -0
- package/dist/esm/tests/core/protocol-authorization.spec.js +48 -0
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -0
- package/dist/esm/tests/dwn.spec.js +166 -0
- package/dist/esm/tests/dwn.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-emitter-stream.spec.js +78 -0
- package/dist/esm/tests/event-log/event-emitter-stream.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-log-level.spec.js +44 -0
- package/dist/esm/tests/event-log/event-log-level.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-log.spec.js +236 -0
- package/dist/esm/tests/event-log/event-log.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-stream.spec.js +125 -0
- package/dist/esm/tests/event-log/event-stream.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +1273 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -0
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +584 -0
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -0
- package/dist/esm/tests/features/owner-signature.spec.js +192 -0
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -0
- package/dist/esm/tests/features/permissions.spec.js +815 -0
- package/dist/esm/tests/features/permissions.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-create-action.spec.js +248 -0
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-delete-action.spec.js +492 -0
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-update-action.spec.js +572 -0
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +812 -0
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +2516 -0
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -0
- package/dist/esm/tests/features/resumable-tasks.spec.js +349 -0
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-query.spec.js +349 -0
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-read.spec.js +647 -0
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +432 -0
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js +608 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -0
- package/dist/esm/tests/handlers/protocols-query.spec.js +454 -0
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-delete.spec.js +662 -0
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-query.spec.js +2695 -0
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-read.spec.js +1724 -0
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-subscribe.spec.js +684 -0
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-write.spec.js +3637 -0
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/messages-get.spec.js +78 -0
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +30 -0
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/messagess-query.spec.js +127 -0
- package/dist/esm/tests/interfaces/messagess-query.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +489 -0
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/protocols-query.spec.js +46 -0
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-delete.spec.js +39 -0
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-query.spec.js +85 -0
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-read.spec.js +62 -0
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +72 -0
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-write.spec.js +423 -0
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -0
- package/dist/esm/tests/jose/jws/general.spec.js +243 -0
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -0
- package/dist/esm/tests/protocols/permission-request.spec.js +40 -0
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -0
- package/dist/esm/tests/protocols/permissions.spec.js +123 -0
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/aggregator.spec.js +670 -0
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/deleted-record.spec.js +102 -0
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +220 -0
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/messages-query.spec.js +395 -0
- package/dist/esm/tests/scenarios/messages-query.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/nested-roles.spec.js +300 -0
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/subscriptions.spec.js +886 -0
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -0
- package/dist/esm/tests/store/blockstore-mock.spec.js +192 -0
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -0
- package/dist/esm/tests/store/data-store-level.spec.js +146 -0
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -0
- package/dist/esm/tests/store/index-level.spec.js +1208 -0
- package/dist/esm/tests/store/index-level.spec.js.map +1 -0
- package/dist/esm/tests/store/message-store-level.spec.js +48 -0
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -0
- package/dist/esm/tests/store/message-store.spec.js +404 -0
- package/dist/esm/tests/store/message-store.spec.js.map +1 -0
- package/dist/esm/tests/store-dependent-tests.spec.js +5 -0
- package/dist/esm/tests/store-dependent-tests.spec.js.map +1 -0
- package/dist/esm/tests/test-event-stream.js +25 -0
- package/dist/esm/tests/test-event-stream.js.map +1 -0
- package/dist/esm/tests/test-stores.js +45 -0
- package/dist/esm/tests/test-stores.js.map +1 -0
- package/dist/esm/tests/test-suite.js +88 -0
- package/dist/esm/tests/test-suite.js.map +1 -0
- package/dist/esm/tests/utils/cid.spec.js +80 -0
- package/dist/esm/tests/utils/cid.spec.js.map +1 -0
- package/dist/esm/tests/utils/data-stream.spec.js +27 -0
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -0
- package/dist/esm/tests/utils/encryption.spec.js +148 -0
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -0
- package/dist/esm/tests/utils/filters.spec.js +295 -0
- package/dist/esm/tests/utils/filters.spec.js.map +1 -0
- package/dist/esm/tests/utils/hd-key.spec.js +35 -0
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -0
- package/dist/esm/tests/utils/jws.spec.js +8 -0
- package/dist/esm/tests/utils/jws.spec.js.map +1 -0
- package/dist/esm/tests/utils/memory-cache.spec.js +35 -0
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -0
- package/dist/esm/tests/utils/messages.spec.js +101 -0
- package/dist/esm/tests/utils/messages.spec.js.map +1 -0
- package/dist/esm/tests/utils/object.spec.js +36 -0
- package/dist/esm/tests/utils/object.spec.js.map +1 -0
- package/dist/esm/tests/utils/poller.js +49 -0
- package/dist/esm/tests/utils/poller.js.map +1 -0
- package/dist/esm/tests/utils/private-key-signer.spec.js +44 -0
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -0
- package/dist/esm/tests/utils/records.spec.js +53 -0
- package/dist/esm/tests/utils/records.spec.js.map +1 -0
- package/dist/esm/tests/utils/secp256k1.spec.js +50 -0
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -0
- package/dist/esm/tests/utils/secp256r1.spec.js +56 -0
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -0
- package/dist/esm/tests/utils/test-data-generator.js +643 -0
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -0
- package/dist/esm/tests/utils/test-stub-generator.js +39 -0
- package/dist/esm/tests/utils/test-stub-generator.js.map +1 -0
- package/dist/esm/tests/utils/time.spec.js +64 -0
- package/dist/esm/tests/utils/time.spec.js.map +1 -0
- package/dist/esm/tests/utils/url.spec.js +43 -0
- package/dist/esm/tests/utils/url.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +33 -0
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +50 -0
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +36 -0
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +82 -0
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +75 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +148 -0
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +421 -0
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -0
- package/dist/esm/tests/vectors/protocol-definitions/anyone-collaborate.json +21 -0
- package/dist/esm/tests/vectors/protocol-definitions/author-can.json +33 -0
- package/dist/esm/tests/vectors/protocol-definitions/chat.json +70 -0
- package/dist/esm/tests/vectors/protocol-definitions/credential-issuance.json +41 -0
- package/dist/esm/tests/vectors/protocol-definitions/dex.json +58 -0
- package/dist/esm/tests/vectors/protocol-definitions/email.json +62 -0
- package/dist/esm/tests/vectors/protocol-definitions/free-for-all.json +45 -0
- package/dist/esm/tests/vectors/protocol-definitions/friend-role.json +48 -0
- package/dist/esm/tests/vectors/protocol-definitions/message.json +37 -0
- package/dist/esm/tests/vectors/protocol-definitions/minimal.json +10 -0
- package/dist/esm/tests/vectors/protocol-definitions/nested.json +31 -0
- package/dist/esm/tests/vectors/protocol-definitions/private-protocol.json +15 -0
- package/dist/esm/tests/vectors/protocol-definitions/recipient-can.json +33 -0
- package/dist/esm/tests/vectors/protocol-definitions/slack.json +242 -0
- package/dist/esm/tests/vectors/protocol-definitions/social-media.json +106 -0
- package/dist/esm/tests/vectors/protocol-definitions/thread-role.json +70 -0
- package/dist/types/generated/precompiled-validators.d.ts +597 -0
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -0
- package/dist/types/src/core/abstract-message.d.ts +25 -0
- package/dist/types/src/core/abstract-message.d.ts.map +1 -0
- package/dist/types/src/core/auth.d.ts +9 -0
- package/dist/types/src/core/auth.d.ts.map +1 -0
- package/dist/types/src/core/dwn-constant.d.ts +10 -0
- package/dist/types/src/core/dwn-constant.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +164 -0
- package/dist/types/src/core/dwn-error.d.ts.map +1 -0
- package/dist/types/src/core/grant-authorization.d.ts +43 -0
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/message-reply.d.ts +32 -0
- package/dist/types/src/core/message-reply.d.ts.map +1 -0
- package/dist/types/src/core/message.d.ts +94 -0
- package/dist/types/src/core/message.d.ts.map +1 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts +34 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +103 -0
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -0
- package/dist/types/src/core/protocols-grant-authorization.d.ts +31 -0
- package/dist/types/src/core/protocols-grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts +60 -0
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/resumable-task-manager.d.ts +43 -0
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -0
- package/dist/types/src/core/tenant-gate.d.ts +29 -0
- package/dist/types/src/core/tenant-gate.d.ts.map +1 -0
- package/dist/types/src/dwn.d.ts +85 -0
- package/dist/types/src/dwn.d.ts.map +1 -0
- package/dist/types/src/enums/dwn-interface-method.d.ts +14 -0
- package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -0
- package/dist/types/src/event-log/event-emitter-stream.d.ts +23 -0
- package/dist/types/src/event-log/event-emitter-stream.d.ts.map +1 -0
- package/dist/types/src/event-log/event-log-level.d.ts +35 -0
- package/dist/types/src/event-log/event-log-level.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-query.d.ts +17 -0
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +22 -0
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-subscribe.d.ts +18 -0
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -0
- package/dist/types/src/handlers/protocols-configure.d.ts +24 -0
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -0
- package/dist/types/src/handlers/protocols-query.d.ts +20 -0
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -0
- package/dist/types/src/handlers/records-delete.d.ts +23 -0
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -0
- package/dist/types/src/handlers/records-query.d.ts +70 -0
- package/dist/types/src/handlers/records-query.d.ts.map +1 -0
- package/dist/types/src/handlers/records-read.d.ts +20 -0
- package/dist/types/src/handlers/records-read.d.ts.map +1 -0
- package/dist/types/src/handlers/records-subscribe.d.ts +62 -0
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -0
- package/dist/types/src/handlers/records-write.d.ts +51 -0
- package/dist/types/src/handlers/records-write.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +63 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/interfaces/messages-query.d.ts +16 -0
- package/dist/types/src/interfaces/messages-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/messages-read.d.ts +20 -0
- package/dist/types/src/interfaces/messages-read.d.ts.map +1 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts +20 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts +40 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-query.d.ts +17 -0
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-delete.d.ts +34 -0
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-query.d.ts +31 -0
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-read.d.ts +36 -0
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts +27 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +309 -0
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -0
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts +3 -0
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts.map +1 -0
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts +3 -0
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts.map +1 -0
- package/dist/types/src/jose/jws/general/builder.d.ts +10 -0
- package/dist/types/src/jose/jws/general/builder.d.ts.map +1 -0
- package/dist/types/src/jose/jws/general/verifier.d.ts +32 -0
- package/dist/types/src/jose/jws/general/verifier.d.ts.map +1 -0
- package/dist/types/src/protocols/permission-grant.d.ts +50 -0
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -0
- package/dist/types/src/protocols/permission-request.d.ts +35 -0
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -0
- package/dist/types/src/protocols/permissions.d.ts +150 -0
- package/dist/types/src/protocols/permissions.d.ts.map +1 -0
- package/dist/types/src/schema-validator.d.ts +8 -0
- package/dist/types/src/schema-validator.d.ts.map +1 -0
- package/dist/types/src/store/blockstore-level.d.ts +34 -0
- package/dist/types/src/store/blockstore-level.d.ts.map +1 -0
- package/dist/types/src/store/blockstore-mock.d.ts +27 -0
- package/dist/types/src/store/blockstore-mock.d.ts.map +1 -0
- package/dist/types/src/store/data-store-level.d.ts +34 -0
- package/dist/types/src/store/data-store-level.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +171 -0
- package/dist/types/src/store/index-level.d.ts.map +1 -0
- package/dist/types/src/store/level-wrapper.d.ts +48 -0
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -0
- package/dist/types/src/store/message-store-level.d.ts +46 -0
- package/dist/types/src/store/message-store-level.d.ts.map +1 -0
- package/dist/types/src/store/resumable-task-store-level.d.ts +28 -0
- package/dist/types/src/store/resumable-task-store-level.d.ts.map +1 -0
- package/dist/types/src/store/storage-controller.d.ts +46 -0
- package/dist/types/src/store/storage-controller.d.ts.map +1 -0
- package/dist/types/src/types/cache.d.ts +16 -0
- package/dist/types/src/types/cache.d.ts.map +1 -0
- package/dist/types/src/types/data-store.d.ts +57 -0
- package/dist/types/src/types/data-store.d.ts.map +1 -0
- package/dist/types/src/types/event-log.d.ts +52 -0
- package/dist/types/src/types/event-log.d.ts.map +1 -0
- package/dist/types/src/types/jose-types.d.ts +75 -0
- package/dist/types/src/types/jose-types.d.ts.map +1 -0
- package/dist/types/src/types/jws-types.d.ts +27 -0
- package/dist/types/src/types/jws-types.d.ts.map +1 -0
- package/dist/types/src/types/message-interface.d.ts +27 -0
- package/dist/types/src/types/message-interface.d.ts.map +1 -0
- package/dist/types/src/types/message-store.d.ts +42 -0
- package/dist/types/src/types/message-store.d.ts.map +1 -0
- package/dist/types/src/types/message-types.d.ts +116 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -0
- package/dist/types/src/types/messages-types.d.ts +65 -0
- package/dist/types/src/types/messages-types.d.ts.map +1 -0
- package/dist/types/src/types/method-handler.d.ts +19 -0
- package/dist/types/src/types/method-handler.d.ts.map +1 -0
- package/dist/types/src/types/permission-types.d.ts +93 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -0
- package/dist/types/src/types/protocols-types.d.ts +154 -0
- package/dist/types/src/types/protocols-types.d.ts.map +1 -0
- package/dist/types/src/types/query-types.d.ts +66 -0
- package/dist/types/src/types/query-types.d.ts.map +1 -0
- package/dist/types/src/types/records-types.d.ts +230 -0
- package/dist/types/src/types/records-types.d.ts.map +1 -0
- package/dist/types/src/types/resumable-task-store.d.ts +89 -0
- package/dist/types/src/types/resumable-task-store.d.ts.map +1 -0
- package/dist/types/src/types/signer.d.ts +26 -0
- package/dist/types/src/types/signer.d.ts.map +1 -0
- package/dist/types/src/types/subscriptions.d.ts +30 -0
- package/dist/types/src/types/subscriptions.d.ts.map +1 -0
- package/dist/types/src/utils/abort.d.ts +5 -0
- package/dist/types/src/utils/abort.d.ts.map +1 -0
- package/dist/types/src/utils/array.d.ts +18 -0
- package/dist/types/src/utils/array.d.ts.map +1 -0
- package/dist/types/src/utils/cid.d.ts +30 -0
- package/dist/types/src/utils/cid.d.ts.map +1 -0
- package/dist/types/src/utils/data-stream.d.ts +31 -0
- package/dist/types/src/utils/data-stream.d.ts.map +1 -0
- package/dist/types/src/utils/encoder.d.ts +14 -0
- package/dist/types/src/utils/encoder.d.ts.map +1 -0
- package/dist/types/src/utils/encryption.d.ts +44 -0
- package/dist/types/src/utils/encryption.d.ts.map +1 -0
- package/dist/types/src/utils/filter.d.ts +60 -0
- package/dist/types/src/utils/filter.d.ts.map +1 -0
- package/dist/types/src/utils/hd-key.d.ts +54 -0
- package/dist/types/src/utils/hd-key.d.ts.map +1 -0
- package/dist/types/src/utils/jws.d.ts +39 -0
- package/dist/types/src/utils/jws.d.ts.map +1 -0
- package/dist/types/src/utils/memory-cache.d.ts +15 -0
- package/dist/types/src/utils/memory-cache.d.ts.map +1 -0
- package/dist/types/src/utils/messages.d.ts +27 -0
- package/dist/types/src/utils/messages.d.ts.map +1 -0
- package/dist/types/src/utils/object.d.ts +13 -0
- package/dist/types/src/utils/object.d.ts.map +1 -0
- package/dist/types/src/utils/private-key-signer.d.ts +34 -0
- package/dist/types/src/utils/private-key-signer.d.ts.map +1 -0
- package/dist/types/src/utils/protocols.d.ts +14 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -0
- package/dist/types/src/utils/records.d.ts +122 -0
- package/dist/types/src/utils/records.d.ts.map +1 -0
- package/dist/types/src/utils/secp256k1.d.ts +59 -0
- package/dist/types/src/utils/secp256k1.d.ts.map +1 -0
- package/dist/types/src/utils/secp256r1.d.ts +39 -0
- package/dist/types/src/utils/secp256r1.d.ts.map +1 -0
- package/dist/types/src/utils/string.d.ts +6 -0
- package/dist/types/src/utils/string.d.ts.map +1 -0
- package/dist/types/src/utils/time.d.ts +50 -0
- package/dist/types/src/utils/time.d.ts.map +1 -0
- package/dist/types/src/utils/url.d.ts +5 -0
- package/dist/types/src/utils/url.d.ts.map +1 -0
- package/dist/types/tests/core/auth.spec.d.ts +2 -0
- package/dist/types/tests/core/auth.spec.d.ts.map +1 -0
- package/dist/types/tests/core/message-reply.spec.d.ts +2 -0
- package/dist/types/tests/core/message-reply.spec.d.ts.map +1 -0
- package/dist/types/tests/core/message.spec.d.ts +2 -0
- package/dist/types/tests/core/message.spec.d.ts.map +1 -0
- package/dist/types/tests/core/protocol-authorization.spec.d.ts +2 -0
- package/dist/types/tests/core/protocol-authorization.spec.d.ts.map +1 -0
- package/dist/types/tests/dwn.spec.d.ts +2 -0
- package/dist/types/tests/dwn.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-log-level.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-log-level.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-stream.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts +2 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -0
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts +2 -0
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -0
- package/dist/types/tests/features/owner-signature.spec.d.ts +2 -0
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -0
- package/dist/types/tests/features/permissions.spec.d.ts +2 -0
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-create-action.spec.d.ts +2 -0
- package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts +2 -0
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-update-action.spec.d.ts +2 -0
- package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-prune.spec.d.ts +2 -0
- package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-tags.spec.d.ts +2 -0
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -0
- package/dist/types/tests/features/resumable-tasks.spec.d.ts +2 -0
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-read.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts +2 -0
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/protocols-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-delete.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-read.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-write.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/messages-get.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/messages-get.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/messages-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/messages-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/protocols-configure.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/protocols-configure.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/protocols-query.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/protocols-query.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-delete.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-delete.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-query.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-query.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-read.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-read.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-write.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-write.spec.d.ts.map +1 -0
- package/dist/types/tests/jose/jws/general.spec.d.ts +2 -0
- package/dist/types/tests/jose/jws/general.spec.d.ts.map +1 -0
- package/dist/types/tests/protocols/permission-request.spec.d.ts +2 -0
- package/dist/types/tests/protocols/permission-request.spec.d.ts.map +1 -0
- package/dist/types/tests/protocols/permissions.spec.d.ts +2 -0
- package/dist/types/tests/protocols/permissions.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/aggregator.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/aggregator.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/messages-query.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/messages-query.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -0
- package/dist/types/tests/store/blockstore-mock.spec.d.ts +2 -0
- package/dist/types/tests/store/blockstore-mock.spec.d.ts.map +1 -0
- package/dist/types/tests/store/data-store-level.spec.d.ts +2 -0
- package/dist/types/tests/store/data-store-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/index-level.spec.d.ts +2 -0
- package/dist/types/tests/store/index-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store-level.spec.d.ts +2 -0
- package/dist/types/tests/store/message-store-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store.spec.d.ts +2 -0
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -0
- package/dist/types/tests/store-dependent-tests.spec.d.ts +2 -0
- package/dist/types/tests/store-dependent-tests.spec.d.ts.map +1 -0
- package/dist/types/tests/test-event-stream.d.ts +22 -0
- package/dist/types/tests/test-event-stream.d.ts.map +1 -0
- package/dist/types/tests/test-stores.d.ts +33 -0
- package/dist/types/tests/test-stores.d.ts.map +1 -0
- package/dist/types/tests/test-suite.d.ts +18 -0
- package/dist/types/tests/test-suite.d.ts.map +1 -0
- package/dist/types/tests/utils/cid.spec.d.ts +2 -0
- package/dist/types/tests/utils/cid.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/data-stream.spec.d.ts +2 -0
- package/dist/types/tests/utils/data-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/encryption.spec.d.ts +2 -0
- package/dist/types/tests/utils/encryption.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/filters.spec.d.ts +2 -0
- package/dist/types/tests/utils/filters.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/hd-key.spec.d.ts +2 -0
- package/dist/types/tests/utils/hd-key.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/jws.spec.d.ts +2 -0
- package/dist/types/tests/utils/jws.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/memory-cache.spec.d.ts +2 -0
- package/dist/types/tests/utils/memory-cache.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/messages.spec.d.ts +2 -0
- package/dist/types/tests/utils/messages.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/object.spec.d.ts +2 -0
- package/dist/types/tests/utils/object.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/poller.d.ts +21 -0
- package/dist/types/tests/utils/poller.d.ts.map +1 -0
- package/dist/types/tests/utils/private-key-signer.spec.d.ts +2 -0
- package/dist/types/tests/utils/private-key-signer.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/records.spec.d.ts +2 -0
- package/dist/types/tests/utils/records.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/secp256k1.spec.d.ts +2 -0
- package/dist/types/tests/utils/secp256k1.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/secp256r1.spec.d.ts +2 -0
- package/dist/types/tests/utils/secp256r1.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts +342 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -0
- package/dist/types/tests/utils/test-stub-generator.d.ts +16 -0
- package/dist/types/tests/utils/test-stub-generator.d.ts.map +1 -0
- package/dist/types/tests/utils/time.spec.d.ts +2 -0
- package/dist/types/tests/utils/time.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/url.spec.d.ts +2 -0
- package/dist/types/tests/utils/url.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/definitions.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/definitions.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/jwk/general-jwk.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/jwk/general-jwk.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/jwk/public-jwk.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/jwk/public-jwk.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/jwk-verification-method.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/jwk-verification-method.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/protocols/protocols-configure.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/protocols/protocols-configure.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/records/records-query.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/records/records-query.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/records/records-write.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/records/records-write.spec.d.ts.map +1 -0
- package/package.json +167 -0
- package/src/core/abstract-message.ts +62 -0
- package/src/core/auth.ts +36 -0
- package/src/core/dwn-constant.ts +9 -0
- package/src/core/dwn-error.ts +167 -0
- package/src/core/grant-authorization.ts +148 -0
- package/src/core/message-reply.ts +41 -0
- package/src/core/message.ts +259 -0
- package/src/core/messages-grant-authorization.ts +134 -0
- package/src/core/protocol-authorization.ts +903 -0
- package/src/core/protocols-grant-authorization.ts +88 -0
- package/src/core/records-grant-authorization.ts +197 -0
- package/src/core/resumable-task-manager.ts +114 -0
- package/src/core/tenant-gate.ts +33 -0
- package/src/dwn.ts +264 -0
- package/src/enums/dwn-interface-method.ts +14 -0
- package/src/event-log/event-emitter-stream.ts +69 -0
- package/src/event-log/event-log-level.ts +72 -0
- package/src/handlers/messages-query.ts +67 -0
- package/src/handlers/messages-read.ts +103 -0
- package/src/handlers/messages-subscribe.ts +89 -0
- package/src/handlers/protocols-configure.ts +137 -0
- package/src/handlers/protocols-query.ts +82 -0
- package/src/handlers/records-delete.ts +124 -0
- package/src/handlers/records-query.ts +262 -0
- package/src/handlers/records-read.ts +187 -0
- package/src/handlers/records-subscribe.ts +218 -0
- package/src/handlers/records-write.ts +404 -0
- package/src/index.ts +67 -0
- package/src/interfaces/messages-query.ts +60 -0
- package/src/interfaces/messages-read.ts +63 -0
- package/src/interfaces/messages-subscribe.ts +64 -0
- package/src/interfaces/protocols-configure.ts +340 -0
- package/src/interfaces/protocols-query.ts +96 -0
- package/src/interfaces/records-delete.ts +117 -0
- package/src/interfaces/records-query.ts +131 -0
- package/src/interfaces/records-read.ts +100 -0
- package/src/interfaces/records-subscribe.ts +104 -0
- package/src/interfaces/records-write.ts +1072 -0
- package/src/jose/algorithms/signing/ed25519.ts +58 -0
- package/src/jose/algorithms/signing/signature-algorithms.ts +22 -0
- package/src/jose/jws/general/builder.ts +48 -0
- package/src/jose/jws/general/verifier.ts +112 -0
- package/src/protocols/permission-grant.ts +86 -0
- package/src/protocols/permission-request.ts +63 -0
- package/src/protocols/permissions.ts +508 -0
- package/src/schema-validator.ts +46 -0
- package/src/store/blockstore-level.ts +113 -0
- package/src/store/blockstore-mock.ts +80 -0
- package/src/store/data-store-level.ts +120 -0
- package/src/store/index-level.ts +691 -0
- package/src/store/level-wrapper.ts +272 -0
- package/src/store/message-store-level.ts +195 -0
- package/src/store/resumable-task-store-level.ts +120 -0
- package/src/store/storage-controller.ts +240 -0
- package/src/types/cache.ts +16 -0
- package/src/types/data-store.ts +64 -0
- package/src/types/event-log.ts +52 -0
- package/src/types/jose-types.ts +76 -0
- package/src/types/jws-types.ts +28 -0
- package/src/types/message-interface.ts +30 -0
- package/src/types/message-store.ts +57 -0
- package/src/types/message-types.ts +132 -0
- package/src/types/messages-types.ts +77 -0
- package/src/types/method-handler.ts +19 -0
- package/src/types/permission-types.ts +110 -0
- package/src/types/protocols-types.ts +177 -0
- package/src/types/query-types.ts +61 -0
- package/src/types/records-types.ts +263 -0
- package/src/types/resumable-task-store.ts +96 -0
- package/src/types/signer.ts +27 -0
- package/src/types/subscriptions.ts +34 -0
- package/src/utils/abort.ts +31 -0
- package/src/utils/array.ts +39 -0
- package/src/utils/cid.ts +101 -0
- package/src/utils/data-stream.ts +99 -0
- package/src/utils/encoder.ts +54 -0
- package/src/utils/encryption.ts +145 -0
- package/src/utils/filter.ts +245 -0
- package/src/utils/hd-key.ts +126 -0
- package/src/utils/jws.ts +95 -0
- package/src/utils/memory-cache.ts +31 -0
- package/src/utils/messages.ts +109 -0
- package/src/utils/object.ts +43 -0
- package/src/utils/private-key-signer.ts +72 -0
- package/src/utils/protocols.ts +50 -0
- package/src/utils/records.ts +559 -0
- package/src/utils/secp256k1.ts +157 -0
- package/src/utils/secp256r1.ts +142 -0
- package/src/utils/string.ts +13 -0
- package/src/utils/time.ts +78 -0
- package/src/utils/url.ts +65 -0
|
@@ -0,0 +1,903 @@
|
|
|
1
|
+
import type { Filter } from '../types/query-types.js';
|
|
2
|
+
import type { MessageStore } from '../types/message-store.js';
|
|
3
|
+
import type { RecordsDelete } from '../interfaces/records-delete.js';
|
|
4
|
+
import type { RecordsQuery } from '../interfaces/records-query.js';
|
|
5
|
+
import type { RecordsRead } from '../interfaces/records-read.js';
|
|
6
|
+
import type { RecordsSubscribe } from '../interfaces/records-subscribe.js';
|
|
7
|
+
import type { RecordsWriteMessage } from '../types/records-types.js';
|
|
8
|
+
import type { ProtocolActionRule, ProtocolDefinition, ProtocolRuleSet, ProtocolsConfigureMessage, ProtocolType, ProtocolTypes } from '../types/protocols-types.js';
|
|
9
|
+
|
|
10
|
+
import Ajv from 'ajv/dist/2020.js';
|
|
11
|
+
import { FilterUtility } from '../utils/filter.js';
|
|
12
|
+
import { PermissionsProtocol } from '../protocols/permissions.js';
|
|
13
|
+
import { Records } from '../utils/records.js';
|
|
14
|
+
import { RecordsWrite } from '../interfaces/records-write.js';
|
|
15
|
+
import { DwnError, DwnErrorCode } from './dwn-error.js';
|
|
16
|
+
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
17
|
+
import { ProtocolAction, ProtocolActor } from '../types/protocols-types.js';
|
|
18
|
+
|
|
19
|
+
export class ProtocolAuthorization {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Performs validation on the structure of RecordsWrite messages that use a protocol.
|
|
23
|
+
* @throws {Error} if validation fails.
|
|
24
|
+
*/
|
|
25
|
+
public static async validateReferentialIntegrity(
|
|
26
|
+
tenant: string,
|
|
27
|
+
incomingMessage: RecordsWrite,
|
|
28
|
+
messageStore: MessageStore,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
// fetch the protocol definition
|
|
31
|
+
const protocolDefinition = await ProtocolAuthorization.fetchProtocolDefinition(
|
|
32
|
+
tenant,
|
|
33
|
+
incomingMessage.message.descriptor.protocol!,
|
|
34
|
+
messageStore,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// verify declared protocol type exists in protocol and that it conforms to type specification
|
|
38
|
+
ProtocolAuthorization.verifyType(
|
|
39
|
+
incomingMessage.message,
|
|
40
|
+
protocolDefinition.types
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// validate `protocolPath`
|
|
44
|
+
await ProtocolAuthorization.verifyProtocolPathAndContextId(
|
|
45
|
+
tenant,
|
|
46
|
+
incomingMessage,
|
|
47
|
+
messageStore,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// get the rule set for the inbound message
|
|
51
|
+
const ruleSet = ProtocolAuthorization.getRuleSet(
|
|
52
|
+
incomingMessage.message.descriptor.protocolPath!,
|
|
53
|
+
protocolDefinition,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Validate as a role record if the incoming message is writing a role record
|
|
57
|
+
await ProtocolAuthorization.verifyAsRoleRecordIfNeeded(
|
|
58
|
+
tenant,
|
|
59
|
+
incomingMessage,
|
|
60
|
+
ruleSet,
|
|
61
|
+
messageStore,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Verify size limit
|
|
65
|
+
ProtocolAuthorization.verifySizeLimit(incomingMessage, ruleSet);
|
|
66
|
+
|
|
67
|
+
// Verify protocol tags
|
|
68
|
+
ProtocolAuthorization.verifyTagsIfNeeded(incomingMessage, ruleSet);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Performs protocol-based authorization against the incoming RecordsWrite message.
|
|
73
|
+
* @throws {Error} if authorization fails.
|
|
74
|
+
*/
|
|
75
|
+
public static async authorizeWrite(
|
|
76
|
+
tenant: string,
|
|
77
|
+
incomingMessage: RecordsWrite,
|
|
78
|
+
messageStore: MessageStore,
|
|
79
|
+
): Promise<void> {
|
|
80
|
+
const existingInitialWrite = await ProtocolAuthorization.fetchInitialWrite(tenant, incomingMessage.message.recordId, messageStore);
|
|
81
|
+
|
|
82
|
+
let recordChain;
|
|
83
|
+
if (existingInitialWrite === undefined) {
|
|
84
|
+
// NOTE: we can assume this message is an initial write because an existing initial write does not exist.
|
|
85
|
+
// Additionally, we check further down in the `RecordsWriteHandler` if the incoming message is an initialWrite,
|
|
86
|
+
// so we don't check explicitly here to avoid an unnecessary duplicate check.
|
|
87
|
+
recordChain = await ProtocolAuthorization.constructRecordChain(tenant, incomingMessage.message.descriptor.parentId, messageStore);
|
|
88
|
+
} else {
|
|
89
|
+
recordChain = await ProtocolAuthorization.constructRecordChain(tenant, incomingMessage.message.recordId, messageStore);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// fetch the protocol definition
|
|
93
|
+
const protocolDefinition = await ProtocolAuthorization.fetchProtocolDefinition(
|
|
94
|
+
tenant,
|
|
95
|
+
incomingMessage.message.descriptor.protocol!,
|
|
96
|
+
messageStore,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// get the rule set for the inbound message
|
|
100
|
+
const ruleSet = ProtocolAuthorization.getRuleSet(
|
|
101
|
+
incomingMessage.message.descriptor.protocolPath!,
|
|
102
|
+
protocolDefinition,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
106
|
+
await ProtocolAuthorization.verifyInvokedRole(
|
|
107
|
+
tenant,
|
|
108
|
+
incomingMessage,
|
|
109
|
+
incomingMessage.message.descriptor.protocol!,
|
|
110
|
+
incomingMessage.message.contextId!,
|
|
111
|
+
protocolDefinition,
|
|
112
|
+
messageStore,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// verify method invoked against the allowed actions in the rule set
|
|
116
|
+
await ProtocolAuthorization.authorizeAgainstAllowedActions(
|
|
117
|
+
tenant,
|
|
118
|
+
incomingMessage,
|
|
119
|
+
ruleSet,
|
|
120
|
+
recordChain,
|
|
121
|
+
messageStore,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Performs protocol-based authorization against the incoming `RecordsRead` message.
|
|
127
|
+
* @param newestRecordsWrite The latest RecordsWrite associated with the recordId being read.
|
|
128
|
+
* @throws {Error} if authorization fails.
|
|
129
|
+
*/
|
|
130
|
+
public static async authorizeRead(
|
|
131
|
+
tenant: string,
|
|
132
|
+
incomingMessage: RecordsRead,
|
|
133
|
+
newestRecordsWrite: RecordsWrite,
|
|
134
|
+
messageStore: MessageStore,
|
|
135
|
+
): Promise<void> {
|
|
136
|
+
// fetch record chain
|
|
137
|
+
const recordChain: RecordsWriteMessage[] =
|
|
138
|
+
await ProtocolAuthorization.constructRecordChain(tenant, newestRecordsWrite.message.recordId, messageStore);
|
|
139
|
+
|
|
140
|
+
// fetch the protocol definition
|
|
141
|
+
const protocolDefinition = await ProtocolAuthorization.fetchProtocolDefinition(
|
|
142
|
+
tenant,
|
|
143
|
+
newestRecordsWrite.message.descriptor.protocol!,
|
|
144
|
+
messageStore,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// get the rule set for the inbound message
|
|
148
|
+
const ruleSet = ProtocolAuthorization.getRuleSet(
|
|
149
|
+
newestRecordsWrite.message.descriptor.protocolPath!,
|
|
150
|
+
protocolDefinition,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
154
|
+
await ProtocolAuthorization.verifyInvokedRole(
|
|
155
|
+
tenant,
|
|
156
|
+
incomingMessage,
|
|
157
|
+
newestRecordsWrite.message.descriptor.protocol!,
|
|
158
|
+
newestRecordsWrite.message.contextId!,
|
|
159
|
+
protocolDefinition,
|
|
160
|
+
messageStore,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// verify method invoked against the allowed actions in the rule set
|
|
164
|
+
await ProtocolAuthorization.authorizeAgainstAllowedActions(
|
|
165
|
+
tenant,
|
|
166
|
+
incomingMessage,
|
|
167
|
+
ruleSet,
|
|
168
|
+
recordChain,
|
|
169
|
+
messageStore,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public static async authorizeQueryOrSubscribe(
|
|
174
|
+
tenant: string,
|
|
175
|
+
incomingMessage: RecordsQuery | RecordsSubscribe,
|
|
176
|
+
messageStore: MessageStore,
|
|
177
|
+
): Promise<void> {
|
|
178
|
+
const { protocol, protocolPath, contextId } = incomingMessage.message.descriptor.filter;
|
|
179
|
+
|
|
180
|
+
// fetch the protocol definition
|
|
181
|
+
const protocolDefinition = await ProtocolAuthorization.fetchProtocolDefinition(
|
|
182
|
+
tenant,
|
|
183
|
+
protocol!, // `authorizeQueryOrSubscribe` is only called if `protocol` is present
|
|
184
|
+
messageStore,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// get the rule set for the inbound message
|
|
188
|
+
const ruleSet = ProtocolAuthorization.getRuleSet(
|
|
189
|
+
protocolPath!, // presence of `protocolPath` is verified in `parse()`
|
|
190
|
+
protocolDefinition,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
194
|
+
await ProtocolAuthorization.verifyInvokedRole(
|
|
195
|
+
tenant,
|
|
196
|
+
incomingMessage,
|
|
197
|
+
protocol!,
|
|
198
|
+
contextId,
|
|
199
|
+
protocolDefinition,
|
|
200
|
+
messageStore,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// verify method invoked against the allowed actions in the rule set
|
|
204
|
+
await ProtocolAuthorization.authorizeAgainstAllowedActions(
|
|
205
|
+
tenant,
|
|
206
|
+
incomingMessage,
|
|
207
|
+
ruleSet,
|
|
208
|
+
[], // record chain is not relevant to queries or subscriptions
|
|
209
|
+
messageStore,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Performs protocol-based authorization against the incoming `RecordsDelete` message.
|
|
215
|
+
* @param recordsWrite A `RecordsWrite` of the record being deleted.
|
|
216
|
+
*/
|
|
217
|
+
public static async authorizeDelete(
|
|
218
|
+
tenant: string,
|
|
219
|
+
incomingMessage: RecordsDelete,
|
|
220
|
+
recordsWrite: RecordsWrite,
|
|
221
|
+
messageStore: MessageStore,
|
|
222
|
+
): Promise<void> {
|
|
223
|
+
|
|
224
|
+
// fetch record chain
|
|
225
|
+
const recordChain: RecordsWriteMessage[] =
|
|
226
|
+
await ProtocolAuthorization.constructRecordChain(tenant, incomingMessage.message.descriptor.recordId, messageStore);
|
|
227
|
+
|
|
228
|
+
// fetch the protocol definition
|
|
229
|
+
const protocolDefinition = await ProtocolAuthorization.fetchProtocolDefinition(
|
|
230
|
+
tenant,
|
|
231
|
+
recordsWrite.message.descriptor.protocol!,
|
|
232
|
+
messageStore,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
// get the rule set for the inbound message
|
|
236
|
+
const ruleSet = ProtocolAuthorization.getRuleSet(
|
|
237
|
+
recordsWrite.message.descriptor.protocolPath!,
|
|
238
|
+
protocolDefinition,
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
// If the incoming message has `protocolRole` in the descriptor, validate the invoked role
|
|
242
|
+
await ProtocolAuthorization.verifyInvokedRole(
|
|
243
|
+
tenant,
|
|
244
|
+
incomingMessage,
|
|
245
|
+
recordsWrite.message.descriptor.protocol!,
|
|
246
|
+
recordsWrite.message.contextId!,
|
|
247
|
+
protocolDefinition,
|
|
248
|
+
messageStore,
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
// verify method invoked against the allowed actions in the rule set
|
|
252
|
+
await ProtocolAuthorization.authorizeAgainstAllowedActions(
|
|
253
|
+
tenant,
|
|
254
|
+
incomingMessage,
|
|
255
|
+
ruleSet,
|
|
256
|
+
recordChain,
|
|
257
|
+
messageStore,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Fetches the protocol definition based on the protocol specified in the given message.
|
|
263
|
+
*/
|
|
264
|
+
private static async fetchProtocolDefinition(
|
|
265
|
+
tenant: string,
|
|
266
|
+
protocolUri: string,
|
|
267
|
+
messageStore: MessageStore
|
|
268
|
+
): Promise<ProtocolDefinition> {
|
|
269
|
+
// if first-class protocol, return the definition from const object directly without going to data store
|
|
270
|
+
if (protocolUri === PermissionsProtocol.uri) {
|
|
271
|
+
return PermissionsProtocol.definition;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// fetch the corresponding protocol definition
|
|
275
|
+
const query: Filter = {
|
|
276
|
+
interface : DwnInterfaceName.Protocols,
|
|
277
|
+
method : DwnMethodName.Configure,
|
|
278
|
+
protocol : protocolUri
|
|
279
|
+
};
|
|
280
|
+
const { messages: protocols } = await messageStore.query(tenant, [query]);
|
|
281
|
+
|
|
282
|
+
if (protocols.length === 0) {
|
|
283
|
+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationProtocolNotFound, `unable to find protocol definition for ${protocolUri}`);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const protocolMessage = protocols[0] as ProtocolsConfigureMessage;
|
|
287
|
+
return protocolMessage.descriptor.definition;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Constructs the chain of EXISTING records in the datastore where the first record is the root initial `RecordsWrite` of the record chain
|
|
292
|
+
* and last record is the initial `RecordsWrite` of the descendant record specified.
|
|
293
|
+
* @param descendantRecordId The ID of the descendent record to start constructing the record chain from by repeatedly looking up the parent.
|
|
294
|
+
* @returns the record chain where each record is represented by its initial `RecordsWrite`;
|
|
295
|
+
* returns empty array if `descendantRecordId` is `undefined`.
|
|
296
|
+
* @throws {DwnError} if `descendantRecordId` is defined but any initial `RecordsWrite` is not found in the chain of records.
|
|
297
|
+
*/
|
|
298
|
+
private static async constructRecordChain(
|
|
299
|
+
tenant: string,
|
|
300
|
+
descendantRecordId: string | undefined,
|
|
301
|
+
messageStore: MessageStore
|
|
302
|
+
) : Promise<RecordsWriteMessage[]> {
|
|
303
|
+
|
|
304
|
+
if (descendantRecordId === undefined) {
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const recordChain: RecordsWriteMessage[] = [];
|
|
309
|
+
|
|
310
|
+
// keep walking up the chain from the inbound message's parent, until there is no more parent
|
|
311
|
+
let currentRecordId: string | undefined = descendantRecordId;
|
|
312
|
+
while (currentRecordId !== undefined) {
|
|
313
|
+
|
|
314
|
+
const initialWrite = await ProtocolAuthorization.fetchInitialWrite(tenant, currentRecordId, messageStore);
|
|
315
|
+
|
|
316
|
+
// RecordsWrite needed should be available since we perform necessary checks at the time of writes,
|
|
317
|
+
// eg. check the immediate parent in `verifyProtocolPathAndContextId` at the time of writing,
|
|
318
|
+
// so if this condition is triggered, it means there is an unexpected bug that caused an incomplete chain.
|
|
319
|
+
// We add additional defensive check here because returning an unexpected/incorrect record chain could lead to security vulnerabilities.
|
|
320
|
+
if (initialWrite === undefined) {
|
|
321
|
+
throw new DwnError(
|
|
322
|
+
DwnErrorCode.ProtocolAuthorizationParentNotFoundConstructingRecordChain,
|
|
323
|
+
`Unexpected error that should never trigger: no parent found with ID ${currentRecordId} when constructing record chain.`
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
recordChain.push(initialWrite);
|
|
328
|
+
currentRecordId = initialWrite.descriptor.parentId;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return recordChain.reverse(); // root record first
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Fetches the initial RecordsWrite message associated with the given (tenant + recordId).
|
|
336
|
+
*/
|
|
337
|
+
private static async fetchInitialWrite(
|
|
338
|
+
tenant: string,
|
|
339
|
+
recordId: string,
|
|
340
|
+
messageStore: MessageStore
|
|
341
|
+
): Promise<RecordsWriteMessage | undefined> {
|
|
342
|
+
|
|
343
|
+
const query: Filter = {
|
|
344
|
+
interface : DwnInterfaceName.Records,
|
|
345
|
+
method : DwnMethodName.Write,
|
|
346
|
+
recordId : recordId
|
|
347
|
+
};
|
|
348
|
+
const { messages } = await messageStore.query(tenant, [query]);
|
|
349
|
+
|
|
350
|
+
if (messages.length === 0) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const initialWrite = await RecordsWrite.getInitialWrite(messages);
|
|
355
|
+
return initialWrite;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Gets the rule set corresponding to the given protocolPath.
|
|
360
|
+
*/
|
|
361
|
+
private static getRuleSet(
|
|
362
|
+
protocolPath: string,
|
|
363
|
+
protocolDefinition: ProtocolDefinition,
|
|
364
|
+
): ProtocolRuleSet {
|
|
365
|
+
const ruleSet = ProtocolAuthorization.getRuleSetAtProtocolPath(protocolPath, protocolDefinition);
|
|
366
|
+
if (ruleSet === undefined) {
|
|
367
|
+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationMissingRuleSet,
|
|
368
|
+
`No rule set defined for protocolPath ${protocolPath}`);
|
|
369
|
+
}
|
|
370
|
+
return ruleSet;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Verifies the `protocolPath` declared in the given message (if it is a RecordsWrite) matches the path of actual record chain.
|
|
375
|
+
* @throws {DwnError} if fails verification.
|
|
376
|
+
*/
|
|
377
|
+
private static async verifyProtocolPathAndContextId(
|
|
378
|
+
tenant: string,
|
|
379
|
+
inboundMessage: RecordsWrite,
|
|
380
|
+
messageStore: MessageStore
|
|
381
|
+
): Promise<void> {
|
|
382
|
+
const declaredProtocolPath = inboundMessage.message.descriptor.protocolPath!;
|
|
383
|
+
const declaredTypeName = ProtocolAuthorization.getTypeName(declaredProtocolPath);
|
|
384
|
+
|
|
385
|
+
const parentId = inboundMessage.message.descriptor.parentId;
|
|
386
|
+
if (parentId === undefined) {
|
|
387
|
+
if (declaredProtocolPath !== declaredTypeName) {
|
|
388
|
+
throw new DwnError(
|
|
389
|
+
DwnErrorCode.ProtocolAuthorizationParentlessIncorrectProtocolPath,
|
|
390
|
+
`Declared protocol path '${declaredProtocolPath}' is not valid for records with no parent'.`
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Else `parentId` is defined, so we need to verify both protocolPath and contextId
|
|
398
|
+
|
|
399
|
+
// fetch the parent message
|
|
400
|
+
const protocol = inboundMessage.message.descriptor.protocol!;
|
|
401
|
+
const query: Filter = {
|
|
402
|
+
isLatestBaseState : true, // NOTE: this filter is critical, to ensure are are not returning a deleted parent
|
|
403
|
+
interface : DwnInterfaceName.Records,
|
|
404
|
+
method : DwnMethodName.Write,
|
|
405
|
+
protocol,
|
|
406
|
+
recordId : parentId
|
|
407
|
+
};
|
|
408
|
+
const { messages: parentMessages } = await messageStore.query(tenant, [query]);
|
|
409
|
+
const parentMessage = (parentMessages as RecordsWriteMessage[])[0];
|
|
410
|
+
|
|
411
|
+
// verifying protocolPath of incoming message is a child of the parent message's protocolPath
|
|
412
|
+
const parentProtocolPath = parentMessage?.descriptor?.protocolPath;
|
|
413
|
+
const expectedProtocolPath = `${parentProtocolPath}/${declaredTypeName}`;
|
|
414
|
+
if (expectedProtocolPath !== declaredProtocolPath) {
|
|
415
|
+
throw new DwnError(
|
|
416
|
+
DwnErrorCode.ProtocolAuthorizationIncorrectProtocolPath,
|
|
417
|
+
`Could not find matching parent record to verify declared protocol path '${declaredProtocolPath}'.`
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// verifying contextId of incoming message is a child of the parent message's contextId
|
|
422
|
+
const expectedContextId = `${parentMessage.contextId}/${inboundMessage.message.recordId}`;
|
|
423
|
+
const actualContextId = inboundMessage.message.contextId;
|
|
424
|
+
if (actualContextId !== expectedContextId) {
|
|
425
|
+
throw new DwnError(
|
|
426
|
+
DwnErrorCode.ProtocolAuthorizationIncorrectContextId,
|
|
427
|
+
`Declared contextId '${actualContextId}' is not the same as expected: '${expectedContextId}'.`
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Verifies the `dataFormat` and `schema` declared in the given message (if it is a RecordsWrite) matches dataFormat
|
|
435
|
+
* and schema of the type in the given protocol.
|
|
436
|
+
* @throws {DwnError} if fails verification.
|
|
437
|
+
*/
|
|
438
|
+
private static verifyType(
|
|
439
|
+
inboundMessage: RecordsWriteMessage,
|
|
440
|
+
protocolTypes: ProtocolTypes,
|
|
441
|
+
): void {
|
|
442
|
+
|
|
443
|
+
const typeNames = Object.keys(protocolTypes);
|
|
444
|
+
const declaredProtocolPath = inboundMessage.descriptor.protocolPath!;
|
|
445
|
+
const declaredTypeName = ProtocolAuthorization.getTypeName(declaredProtocolPath);
|
|
446
|
+
if (!typeNames.includes(declaredTypeName)) {
|
|
447
|
+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationInvalidType,
|
|
448
|
+
`record with type ${declaredTypeName} not allowed in protocol`);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const protocolPath = inboundMessage.descriptor.protocolPath!;
|
|
452
|
+
// existence of `protocolType` has already been verified
|
|
453
|
+
const typeName = ProtocolAuthorization.getTypeName(protocolPath);
|
|
454
|
+
const protocolType: ProtocolType = protocolTypes[typeName];
|
|
455
|
+
|
|
456
|
+
// no `schema` specified in protocol definition means that any schema is allowed
|
|
457
|
+
const { schema } = inboundMessage.descriptor;
|
|
458
|
+
if (protocolType.schema !== undefined && protocolType.schema !== schema) {
|
|
459
|
+
throw new DwnError(
|
|
460
|
+
DwnErrorCode.ProtocolAuthorizationInvalidSchema,
|
|
461
|
+
`type '${typeName}' must have schema '${protocolType.schema}', \
|
|
462
|
+
instead has '${schema}'`
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// no `dataFormats` specified in protocol definition means that all dataFormats are allowed
|
|
467
|
+
const { dataFormat } = inboundMessage.descriptor;
|
|
468
|
+
if (protocolType.dataFormats !== undefined && !protocolType.dataFormats.includes(dataFormat)) {
|
|
469
|
+
throw new DwnError(
|
|
470
|
+
DwnErrorCode.ProtocolAuthorizationIncorrectDataFormat,
|
|
471
|
+
`type '${typeName}' must have data format in (${protocolType.dataFormats}), \
|
|
472
|
+
instead has '${dataFormat}'`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Check if the incoming message is invoking a role. If so, validate the invoked role.
|
|
479
|
+
*/
|
|
480
|
+
private static async verifyInvokedRole(
|
|
481
|
+
tenant: string,
|
|
482
|
+
incomingMessage: RecordsDelete | RecordsQuery | RecordsRead | RecordsSubscribe | RecordsWrite,
|
|
483
|
+
protocolUri: string,
|
|
484
|
+
contextId: string | undefined,
|
|
485
|
+
protocolDefinition: ProtocolDefinition,
|
|
486
|
+
messageStore: MessageStore,
|
|
487
|
+
): Promise<void> {
|
|
488
|
+
const protocolRole = incomingMessage.signaturePayload?.protocolRole;
|
|
489
|
+
|
|
490
|
+
// Only verify role if there is a role being invoked
|
|
491
|
+
if (protocolRole === undefined) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const roleRuleSet = ProtocolAuthorization.getRuleSetAtProtocolPath(protocolRole, protocolDefinition);
|
|
496
|
+
if (roleRuleSet === undefined || !roleRuleSet.$role) {
|
|
497
|
+
throw new DwnError(
|
|
498
|
+
DwnErrorCode.ProtocolAuthorizationNotARole,
|
|
499
|
+
`Protocol path ${protocolRole} does not match role record type.`
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// Construct a filter to fetch the invoked role record
|
|
504
|
+
const roleRecordFilter: Filter = {
|
|
505
|
+
interface : DwnInterfaceName.Records,
|
|
506
|
+
method : DwnMethodName.Write,
|
|
507
|
+
protocol : protocolUri,
|
|
508
|
+
protocolPath : protocolRole,
|
|
509
|
+
recipient : incomingMessage.author!,
|
|
510
|
+
isLatestBaseState : true,
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
const ancestorSegmentCountOfRolePath = protocolRole.split('/').length - 1;
|
|
514
|
+
if (contextId === undefined && ancestorSegmentCountOfRolePath > 0) {
|
|
515
|
+
throw new DwnError(
|
|
516
|
+
DwnErrorCode.ProtocolAuthorizationMissingContextId,
|
|
517
|
+
'Could not verify role because contextId is missing.'
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// Compute `contextId` prefix filter for fetching the invoked role record if the role path is not at the root level.
|
|
522
|
+
// e.g. if invoked role path is `Thread/Participant`, and the `contextId` of the message is `threadX/messageY/attachmentZ`,
|
|
523
|
+
// then we need to add a prefix filter as `threadX` for the `contextId`
|
|
524
|
+
// because the `contextId` of the Participant record would be in the form of be `threadX/participantA`
|
|
525
|
+
if (ancestorSegmentCountOfRolePath > 0) {
|
|
526
|
+
const contextIdSegments = contextId!.split('/'); // NOTE: currently contextId segment count is never shorter than the role path count.
|
|
527
|
+
const contextIdPrefix = contextIdSegments.slice(0, ancestorSegmentCountOfRolePath).join('/');
|
|
528
|
+
const contextIdPrefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(contextIdPrefix);
|
|
529
|
+
|
|
530
|
+
roleRecordFilter.contextId = contextIdPrefixFilter;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
const { messages: matchingMessages } = await messageStore.query(tenant, [roleRecordFilter]);
|
|
535
|
+
|
|
536
|
+
if (matchingMessages.length === 0) {
|
|
537
|
+
throw new DwnError(
|
|
538
|
+
DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound,
|
|
539
|
+
`No matching role record found for protocol path ${protocolRole}`
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Returns all the ProtocolActions that would authorized the incoming message
|
|
546
|
+
* (but we still need to later verify if there is a rule defined that matches one of the actions).
|
|
547
|
+
* NOTE: the reason why there could be multiple actions is because:
|
|
548
|
+
* - In case of an initial RecordsWrite, the RecordsWrite can be authorized by an allow `create` or `write` rule.
|
|
549
|
+
* - In case of a non-initial RecordsWrite by the original record author, the RecordsWrite can be authorized by a `write` or `co-update` rule.
|
|
550
|
+
*
|
|
551
|
+
* It is important to recognize that the `write` access that allowed the original record author to create the record maybe revoked
|
|
552
|
+
* (e.g. by role revocation) by the time a "non-initial" write by the same author is attempted.
|
|
553
|
+
*/
|
|
554
|
+
private static async getActionsSeekingARuleMatch(
|
|
555
|
+
tenant: string,
|
|
556
|
+
incomingMessage: RecordsDelete | RecordsQuery | RecordsRead | RecordsSubscribe | RecordsWrite,
|
|
557
|
+
messageStore: MessageStore,
|
|
558
|
+
): Promise<ProtocolAction[]> {
|
|
559
|
+
|
|
560
|
+
switch (incomingMessage.message.descriptor.method) {
|
|
561
|
+
case DwnMethodName.Delete:
|
|
562
|
+
const recordsDelete = incomingMessage as RecordsDelete;
|
|
563
|
+
const recordId = recordsDelete.message.descriptor.recordId;
|
|
564
|
+
const initialWrite = await RecordsWrite.fetchInitialRecordsWrite(messageStore, tenant, recordId);
|
|
565
|
+
|
|
566
|
+
// if there is no initial write, then no action rule can authorize the incoming message, because we won't know who the original author is
|
|
567
|
+
// NOTE: purely defensive programming: currently not reachable
|
|
568
|
+
// because RecordsDelete handler already have an existence check prior to this method being called.
|
|
569
|
+
if (initialWrite === undefined) {
|
|
570
|
+
return [];
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const actionsThatWouldAuthorizeDelete = [];
|
|
574
|
+
const prune = recordsDelete.message.descriptor.prune;
|
|
575
|
+
if (prune) {
|
|
576
|
+
actionsThatWouldAuthorizeDelete.push(ProtocolAction.CoPrune);
|
|
577
|
+
|
|
578
|
+
// A prune by the original record author can also be authorized by a 'prune' rule.
|
|
579
|
+
if (incomingMessage.author === initialWrite.author) {
|
|
580
|
+
actionsThatWouldAuthorizeDelete.push(ProtocolAction.Prune);
|
|
581
|
+
}
|
|
582
|
+
} else {
|
|
583
|
+
actionsThatWouldAuthorizeDelete.push(ProtocolAction.CoDelete);
|
|
584
|
+
|
|
585
|
+
// A delete by the original record author can also be authorized by a 'delete' rule.
|
|
586
|
+
if (incomingMessage.author === initialWrite.author) {
|
|
587
|
+
actionsThatWouldAuthorizeDelete.push(ProtocolAction.Delete);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return actionsThatWouldAuthorizeDelete;
|
|
592
|
+
|
|
593
|
+
case DwnMethodName.Query:
|
|
594
|
+
return [ProtocolAction.Query];
|
|
595
|
+
|
|
596
|
+
case DwnMethodName.Read:
|
|
597
|
+
return [ProtocolAction.Read];
|
|
598
|
+
|
|
599
|
+
case DwnMethodName.Subscribe:
|
|
600
|
+
return [ProtocolAction.Subscribe];
|
|
601
|
+
|
|
602
|
+
case DwnMethodName.Write:
|
|
603
|
+
const incomingRecordsWrite = incomingMessage as RecordsWrite;
|
|
604
|
+
|
|
605
|
+
if (await incomingRecordsWrite.isInitialWrite()) {
|
|
606
|
+
return [ProtocolAction.Create];
|
|
607
|
+
} else {
|
|
608
|
+
// else incoming RecordsWrite not an initial write
|
|
609
|
+
|
|
610
|
+
const recordId = (incomingMessage as RecordsWrite).message.recordId;
|
|
611
|
+
const initialWrite = await RecordsWrite.fetchInitialRecordsWrite(messageStore, tenant, recordId);
|
|
612
|
+
|
|
613
|
+
// if there is no initial write to update from, then no action rule can authorize the incoming message
|
|
614
|
+
if (initialWrite === undefined) {
|
|
615
|
+
return [];
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (incomingMessage.author === initialWrite.author) {
|
|
619
|
+
// 'update' or 'co-update' action authorizes the incoming message
|
|
620
|
+
return [ProtocolAction.CoUpdate, ProtocolAction.Update];
|
|
621
|
+
} else {
|
|
622
|
+
// An update by someone who is not the record author can only be authorized by a 'co-update' rule.
|
|
623
|
+
return [ProtocolAction.CoUpdate];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// purely defensive programming: should not be reachable
|
|
629
|
+
// setting to empty array will prevent any message from being authorized
|
|
630
|
+
return [];
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Verifies the given message is authorized by one of the action rules in the given protocol rule set.
|
|
635
|
+
* @throws {Error} if action not allowed.
|
|
636
|
+
*/
|
|
637
|
+
private static async authorizeAgainstAllowedActions(
|
|
638
|
+
tenant: string,
|
|
639
|
+
incomingMessage: RecordsDelete | RecordsQuery | RecordsRead | RecordsSubscribe | RecordsWrite,
|
|
640
|
+
ruleSet: ProtocolRuleSet,
|
|
641
|
+
recordChain: RecordsWriteMessage[],
|
|
642
|
+
messageStore: MessageStore,
|
|
643
|
+
): Promise<void> {
|
|
644
|
+
const incomingMessageMethod = incomingMessage.message.descriptor.method;
|
|
645
|
+
const actionsSeekingARuleMatch = await ProtocolAuthorization.getActionsSeekingARuleMatch(tenant, incomingMessage, messageStore);
|
|
646
|
+
const author = incomingMessage.author;
|
|
647
|
+
const actionRules = ruleSet.$actions;
|
|
648
|
+
|
|
649
|
+
// NOTE: We have already checked that the message is not from tenant, owner, or permission grant authorized prior to this method being called.
|
|
650
|
+
|
|
651
|
+
if (actionRules === undefined) {
|
|
652
|
+
throw new DwnError(
|
|
653
|
+
DwnErrorCode.ProtocolAuthorizationActionRulesNotFound,
|
|
654
|
+
`no action rule defined for Records${incomingMessageMethod}, ${author} is unauthorized`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const invokedRole = incomingMessage.signaturePayload?.protocolRole;
|
|
659
|
+
|
|
660
|
+
// Iterate through the action rules to find a rule that authorizes the incoming message.
|
|
661
|
+
for (const actionRule of actionRules) {
|
|
662
|
+
// If the action rule does not have an allowed action that matches an action that can authorize the message, skip to evaluate next action rule.
|
|
663
|
+
const ruleHasAMatchingAllowedAction = actionRule.can.some(allowedAction => actionsSeekingARuleMatch.includes(allowedAction as ProtocolAction));
|
|
664
|
+
if (!ruleHasAMatchingAllowedAction) {
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Code reaches here means this action rule has an allowed action that matches the action of the message.
|
|
669
|
+
// The remaining code checks the actor/author of the incoming message.
|
|
670
|
+
|
|
671
|
+
// If the action rule allows `anyone`, then no further checks are needed.
|
|
672
|
+
if (actionRule.who === ProtocolActor.Anyone) {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// Since not `anyone` is allowed in this action rule, we will need to check the author of the incoming message,
|
|
677
|
+
// if the author of incoming message is not defined, this action rule cannot authorize the incoming message.
|
|
678
|
+
if (author === undefined) {
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// go through role validation path if a role is invoked by the incoming message
|
|
683
|
+
if (invokedRole !== undefined) {
|
|
684
|
+
// When a protocol role is being invoked, we require that there is a matching `role` rule.
|
|
685
|
+
if (actionRule.role === invokedRole) {
|
|
686
|
+
// role is successfully invoked
|
|
687
|
+
return;
|
|
688
|
+
} else {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// else we go through the actor (`who`) validation
|
|
694
|
+
|
|
695
|
+
// If `of` is not set, handle it as a special case
|
|
696
|
+
// NOTE: `of` is always set if `who` is set to `author` (we do this check in `validateRuleSetRecursively()`)
|
|
697
|
+
if (actionRule.who === ProtocolActor.Recipient && actionRule.of === undefined) {
|
|
698
|
+
// If the action rule specifies a recipient without `of` and the incoming message is authenticated:
|
|
699
|
+
|
|
700
|
+
// Author must be recipient of the record being accessed
|
|
701
|
+
let recordsWriteMessage: RecordsWriteMessage;
|
|
702
|
+
if (incomingMessage.message.descriptor.method === DwnMethodName.Write) {
|
|
703
|
+
recordsWriteMessage = incomingMessage.message as RecordsWriteMessage;
|
|
704
|
+
} else {
|
|
705
|
+
// else the incoming message must be a `RecordsDelete` because only `co-update`, `co-delete`, `co-prune` are allowed recipient actions,
|
|
706
|
+
// (we do this check in `validateRuleSetRecursively()`)
|
|
707
|
+
// and we have already checked that the incoming message is not a `RecordsWrite` above which covers `co-update` path.
|
|
708
|
+
recordsWriteMessage = recordChain[recordChain.length - 1];
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (recordsWriteMessage.descriptor.recipient === author) {
|
|
712
|
+
return;
|
|
713
|
+
} else {
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// validate the actor is allowed by the current action rule
|
|
719
|
+
const ancestorRuleSuccess: boolean = await ProtocolAuthorization.checkActor(author, actionRule, recordChain);
|
|
720
|
+
if (ancestorRuleSuccess) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// No action rules were satisfied, message is not authorized
|
|
726
|
+
throw new DwnError(
|
|
727
|
+
DwnErrorCode.ProtocolAuthorizationActionNotAllowed,
|
|
728
|
+
`Inbound message action Records${incomingMessageMethod} by author ${incomingMessage.author} not allowed.`
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Verifies that writes adhere to the $size constraints if provided
|
|
734
|
+
* @throws {Error} if size is exceeded.
|
|
735
|
+
*/
|
|
736
|
+
private static verifySizeLimit(
|
|
737
|
+
incomingMessage: RecordsWrite,
|
|
738
|
+
ruleSet: ProtocolRuleSet
|
|
739
|
+
): void {
|
|
740
|
+
const { min = 0, max } = ruleSet.$size || {};
|
|
741
|
+
|
|
742
|
+
const dataSize = incomingMessage.message.descriptor.dataSize;
|
|
743
|
+
|
|
744
|
+
if (dataSize < min) {
|
|
745
|
+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationMinSizeInvalid, `data size ${dataSize} is less than allowed ${min}`);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
if (max === undefined) {
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (dataSize > max) {
|
|
753
|
+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationMaxSizeInvalid, `data size ${dataSize} is more than allowed ${max}`);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
private static verifyTagsIfNeeded(
|
|
758
|
+
incomingMessage: RecordsWrite,
|
|
759
|
+
ruleSet: ProtocolRuleSet
|
|
760
|
+
): void {
|
|
761
|
+
if (ruleSet.$tags !== undefined) {
|
|
762
|
+
const { tags = {}, protocol, protocolPath } = incomingMessage.message.descriptor;
|
|
763
|
+
|
|
764
|
+
const { $allowUndefinedTags, $requiredTags, ...properties } = ruleSet.$tags;
|
|
765
|
+
|
|
766
|
+
// if $allowUndefinedTags is set to false and there are properties not defined in the schema, an error is thrown
|
|
767
|
+
const additionalProperties = $allowUndefinedTags || false;
|
|
768
|
+
|
|
769
|
+
// if $requiredTags is set, all required tags must be present
|
|
770
|
+
const required = $requiredTags || [];
|
|
771
|
+
|
|
772
|
+
const ajv = new Ajv.default();
|
|
773
|
+
const compiledTags = ajv.compile({
|
|
774
|
+
type: 'object',
|
|
775
|
+
properties,
|
|
776
|
+
required,
|
|
777
|
+
additionalProperties,
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
const validSchema = compiledTags(tags);
|
|
781
|
+
if (!validSchema) {
|
|
782
|
+
// the `dataVar` is used to add a qualifier to the error message.
|
|
783
|
+
// For example. If the error is related to a tag `status` in a protocol `https://example.protocol` with the protocolPath `example/path`
|
|
784
|
+
// the error would be described as `https://example.protocol/example/path/$tags/status'
|
|
785
|
+
// without this decorator it would show up as `data/status` which may be confusing.
|
|
786
|
+
const schemaError = ajv.errorsText(compiledTags.errors, { dataVar: `${protocol}/${protocolPath}/$tags` });
|
|
787
|
+
throw new DwnError(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema, `tags schema validation error: ${schemaError}`);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* If the given RecordsWrite is not a role record, this method does nothing and succeeds immediately.
|
|
794
|
+
*
|
|
795
|
+
* Else it verifies the validity of the given `RecordsWrite` as a role record, including:
|
|
796
|
+
* 1. The same role has not been assigned to the same entity/recipient.
|
|
797
|
+
*/
|
|
798
|
+
private static async verifyAsRoleRecordIfNeeded(
|
|
799
|
+
tenant: string,
|
|
800
|
+
incomingMessage: RecordsWrite,
|
|
801
|
+
ruleSet: ProtocolRuleSet,
|
|
802
|
+
messageStore: MessageStore,
|
|
803
|
+
): Promise<void> {
|
|
804
|
+
if (!ruleSet.$role) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// else this is a role record
|
|
809
|
+
|
|
810
|
+
const incomingRecordsWrite = incomingMessage;
|
|
811
|
+
const recipient = incomingRecordsWrite.message.descriptor.recipient;
|
|
812
|
+
if (recipient === undefined) {
|
|
813
|
+
throw new DwnError(
|
|
814
|
+
DwnErrorCode.ProtocolAuthorizationRoleMissingRecipient,
|
|
815
|
+
'Role records must have a recipient'
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
const protocolPath = incomingRecordsWrite.message.descriptor.protocolPath!;
|
|
820
|
+
const filter: Filter = {
|
|
821
|
+
interface : DwnInterfaceName.Records,
|
|
822
|
+
method : DwnMethodName.Write,
|
|
823
|
+
isLatestBaseState : true,
|
|
824
|
+
protocol : incomingRecordsWrite.message.descriptor.protocol!,
|
|
825
|
+
protocolPath,
|
|
826
|
+
recipient,
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
const parentContextId = Records.getParentContextFromOfContextId(incomingRecordsWrite.message.contextId)!;
|
|
830
|
+
|
|
831
|
+
// if this is not the root record, add a prefix filter to the query
|
|
832
|
+
if (parentContextId !== '') {
|
|
833
|
+
const prefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(parentContextId);
|
|
834
|
+
filter.contextId = prefixFilter;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const { messages: matchingMessages } = await messageStore.query(tenant, [filter]);
|
|
838
|
+
const matchingRecords = matchingMessages as RecordsWriteMessage[];
|
|
839
|
+
const matchingRecordsExceptIncomingRecordId = matchingRecords.filter((recordsWriteMessage) =>
|
|
840
|
+
recordsWriteMessage.recordId !== incomingRecordsWrite.message.recordId
|
|
841
|
+
);
|
|
842
|
+
if (matchingRecordsExceptIncomingRecordId.length > 0) {
|
|
843
|
+
throw new DwnError(
|
|
844
|
+
DwnErrorCode.ProtocolAuthorizationDuplicateRoleRecipient,
|
|
845
|
+
`DID '${recipient}' is already recipient of a role record at protocol path '${protocolPath} under the parent context ${parentContextId}.`
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
private static getRuleSetAtProtocolPath(protocolPath: string, protocolDefinition: ProtocolDefinition): ProtocolRuleSet | undefined {
|
|
851
|
+
const protocolPathArray = protocolPath.split('/');
|
|
852
|
+
let currentRuleSet: ProtocolRuleSet = protocolDefinition.structure;
|
|
853
|
+
let i = 0;
|
|
854
|
+
while (i < protocolPathArray.length) {
|
|
855
|
+
const currentTypeName = protocolPathArray[i];
|
|
856
|
+
const nextRuleSet: ProtocolRuleSet | undefined = currentRuleSet[currentTypeName];
|
|
857
|
+
|
|
858
|
+
if (nextRuleSet === undefined) {
|
|
859
|
+
return undefined;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
currentRuleSet = nextRuleSet;
|
|
863
|
+
i++;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
return currentRuleSet;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Checks if the `who: 'author' | 'recipient'` action rule has a matching record in the record chain.
|
|
871
|
+
* @returns `true` if the action rule is satisfied; `false` otherwise.
|
|
872
|
+
*/
|
|
873
|
+
private static async checkActor(
|
|
874
|
+
author: string,
|
|
875
|
+
actionRule: ProtocolActionRule,
|
|
876
|
+
recordChain: RecordsWriteMessage[],
|
|
877
|
+
): Promise<boolean> {
|
|
878
|
+
// find a message with matching protocolPath
|
|
879
|
+
const ancestorRecordsWrite = recordChain.find((recordsWriteMessage) =>
|
|
880
|
+
recordsWriteMessage.descriptor.protocolPath === actionRule.of!
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
if (ancestorRecordsWrite === undefined) {
|
|
884
|
+
// If this is reached, there is likely an issue with the protocol definition.
|
|
885
|
+
// The protocolPath to the actionRule should start with actionRule.of
|
|
886
|
+
// consider moving this check to ProtocolsConfigure message ingestion
|
|
887
|
+
return false;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
if (actionRule.who === ProtocolActor.Recipient) {
|
|
891
|
+
// author of the incoming message must be the recipient of the ancestor message
|
|
892
|
+
return author === ancestorRecordsWrite.descriptor.recipient;
|
|
893
|
+
} else { // actionRule.who === ProtocolActor.Author
|
|
894
|
+
// author of the incoming message must be the author of the ancestor message
|
|
895
|
+
const ancestorAuthor = (await RecordsWrite.parse(ancestorRecordsWrite)).author;
|
|
896
|
+
return author === ancestorAuthor;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
private static getTypeName(protocolPath: string): string {
|
|
901
|
+
return protocolPath.split('/').slice(-1)[0];
|
|
902
|
+
}
|
|
903
|
+
}
|