@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,1273 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
11
|
+
import emailProtocolDefinition from '../vectors/protocol-definitions/email.json' assert { type: 'json' };
|
|
12
|
+
import messageProtocolDefinition from '../vectors/protocol-definitions/message.json' assert { type: 'json' };
|
|
13
|
+
import sinon from 'sinon';
|
|
14
|
+
import threadRoleProtocolDefinition from '../vectors/protocol-definitions/thread-role.json' assert { type: 'json' };
|
|
15
|
+
import chai, { expect } from 'chai';
|
|
16
|
+
import { base64url } from 'multiformats/bases/base64';
|
|
17
|
+
import { DataStream } from '../../src/utils/data-stream.js';
|
|
18
|
+
import { Dwn } from '../../src/dwn.js';
|
|
19
|
+
import { DwnErrorCode } from '../../src/core/dwn-error.js';
|
|
20
|
+
import { Jws } from '../../src/utils/jws.js';
|
|
21
|
+
import { PermissionGrant } from '../../src/protocols/permission-grant.js';
|
|
22
|
+
import { Poller } from '../utils/poller.js';
|
|
23
|
+
import { RecordsWrite } from '../../src/interfaces/records-write.js';
|
|
24
|
+
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
25
|
+
import { TestEventStream } from '../test-event-stream.js';
|
|
26
|
+
import { TestStores } from '../test-stores.js';
|
|
27
|
+
import { Time } from '../../src/utils/time.js';
|
|
28
|
+
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
29
|
+
import { DwnInterfaceName, DwnMethodName, Encoder, Message, PermissionsProtocol, RecordsDelete, RecordsQuery, RecordsRead, RecordsSubscribe } from '../../src/index.js';
|
|
30
|
+
chai.use(chaiAsPromised);
|
|
31
|
+
export function testAuthorDelegatedGrant() {
|
|
32
|
+
describe('author delegated grant', () => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
let didResolver;
|
|
34
|
+
let messageStore;
|
|
35
|
+
let dataStore;
|
|
36
|
+
let resumableTaskStore;
|
|
37
|
+
let eventLog;
|
|
38
|
+
let eventStream;
|
|
39
|
+
let dwn;
|
|
40
|
+
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
41
|
+
// so that different test suites can reuse the same backend store for testing
|
|
42
|
+
before(() => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
44
|
+
const stores = TestStores.get();
|
|
45
|
+
messageStore = stores.messageStore;
|
|
46
|
+
dataStore = stores.dataStore;
|
|
47
|
+
resumableTaskStore = stores.resumableTaskStore;
|
|
48
|
+
eventLog = stores.eventLog;
|
|
49
|
+
eventStream = TestEventStream.get();
|
|
50
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, eventLog, eventStream, resumableTaskStore });
|
|
51
|
+
}));
|
|
52
|
+
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
54
|
+
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
55
|
+
yield messageStore.clear();
|
|
56
|
+
yield dataStore.clear();
|
|
57
|
+
yield resumableTaskStore.clear();
|
|
58
|
+
yield eventLog.clear();
|
|
59
|
+
}));
|
|
60
|
+
after(() => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield dwn.close();
|
|
62
|
+
}));
|
|
63
|
+
describe('ProtocolsConfigure', () => {
|
|
64
|
+
it('should allow author-delegated grant to configure protocols', () => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
66
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
67
|
+
// Alice grants Bob ability to configure any protocol, bob will use it to configure the email protocol
|
|
68
|
+
const scope = {
|
|
69
|
+
interface: DwnInterfaceName.Protocols,
|
|
70
|
+
method: DwnMethodName.Configure,
|
|
71
|
+
};
|
|
72
|
+
const grantToBob = yield PermissionsProtocol.createGrant({
|
|
73
|
+
delegated: true, // this is a delegated grant
|
|
74
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
75
|
+
description: 'Allow Bob to configure the email protocol',
|
|
76
|
+
grantedTo: bob.did,
|
|
77
|
+
scope,
|
|
78
|
+
signer: Jws.createSigner(alice)
|
|
79
|
+
});
|
|
80
|
+
// Bob attempts to configure a protocol
|
|
81
|
+
const protocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
82
|
+
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
83
|
+
author: bob,
|
|
84
|
+
protocolDefinition: emailProtocolDefinition,
|
|
85
|
+
});
|
|
86
|
+
// Bob should be able to configure a protocol on behalf of alice
|
|
87
|
+
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfigure.message);
|
|
88
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
89
|
+
// verify the protocol configure message was processed
|
|
90
|
+
const protocolsQuery = yield TestDataGenerator.generateProtocolsQuery({
|
|
91
|
+
author: alice,
|
|
92
|
+
filter: { protocol: emailProtocolDefinition.protocol }
|
|
93
|
+
});
|
|
94
|
+
const { status, entries } = yield dwn.processMessage(alice.did, protocolsQuery.message);
|
|
95
|
+
expect(status.code).to.equal(200);
|
|
96
|
+
expect(entries === null || entries === void 0 ? void 0 : entries.length).to.equal(1);
|
|
97
|
+
const fetchedProtocolConfigure = entries[0];
|
|
98
|
+
expect(fetchedProtocolConfigure.descriptor.definition).to.deep.equal(emailProtocolDefinition);
|
|
99
|
+
// author should be alice
|
|
100
|
+
const author = Message.getAuthor(fetchedProtocolConfigure);
|
|
101
|
+
expect(author).to.equal(alice.did);
|
|
102
|
+
const signer = Message.getSigner(fetchedProtocolConfigure);
|
|
103
|
+
expect(signer).to.equal(bob.did);
|
|
104
|
+
}));
|
|
105
|
+
it('should allow author-delegated grant to configure a specific protocol', () => __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
107
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
108
|
+
// Alice grants Bob to configure the email protocol
|
|
109
|
+
const scope = {
|
|
110
|
+
interface: DwnInterfaceName.Protocols,
|
|
111
|
+
method: DwnMethodName.Configure,
|
|
112
|
+
protocol: emailProtocolDefinition.protocol,
|
|
113
|
+
};
|
|
114
|
+
const grantToBob = yield PermissionsProtocol.createGrant({
|
|
115
|
+
delegated: true, // this is a delegated grant
|
|
116
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
117
|
+
description: 'Allow Bob to configure the email protocol',
|
|
118
|
+
grantedTo: bob.did,
|
|
119
|
+
scope,
|
|
120
|
+
signer: Jws.createSigner(alice)
|
|
121
|
+
});
|
|
122
|
+
// Bob attempts to configure a protocol
|
|
123
|
+
const protocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
124
|
+
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
125
|
+
author: bob,
|
|
126
|
+
protocolDefinition: emailProtocolDefinition,
|
|
127
|
+
});
|
|
128
|
+
// Bob should be able to configure a protocol on behalf of alice
|
|
129
|
+
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfigure.message);
|
|
130
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
131
|
+
// verify the protocol configure message was processed
|
|
132
|
+
const protocolsQuery = yield TestDataGenerator.generateProtocolsQuery({
|
|
133
|
+
author: alice,
|
|
134
|
+
filter: { protocol: emailProtocolDefinition.protocol }
|
|
135
|
+
});
|
|
136
|
+
const { status, entries } = yield dwn.processMessage(alice.did, protocolsQuery.message);
|
|
137
|
+
expect(status.code).to.equal(200);
|
|
138
|
+
expect(entries === null || entries === void 0 ? void 0 : entries.length).to.equal(1);
|
|
139
|
+
const fetchedProtocolConfigure = entries[0];
|
|
140
|
+
expect(fetchedProtocolConfigure.descriptor.definition).to.deep.equal(emailProtocolDefinition);
|
|
141
|
+
// author should be alice
|
|
142
|
+
const author = Message.getAuthor(fetchedProtocolConfigure);
|
|
143
|
+
expect(author).to.equal(alice.did);
|
|
144
|
+
const signer = Message.getSigner(fetchedProtocolConfigure);
|
|
145
|
+
expect(signer).to.equal(bob.did);
|
|
146
|
+
// verify that bob cannot configure a different protocol
|
|
147
|
+
const otherProtocolDefinition = Object.assign(Object.assign({}, emailProtocolDefinition), { protocol: 'https://example.com/protocol/otherProtocol' });
|
|
148
|
+
const otherProtocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
149
|
+
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
150
|
+
author: bob,
|
|
151
|
+
protocolDefinition: otherProtocolDefinition,
|
|
152
|
+
});
|
|
153
|
+
const otherProtocolConfigureReply = yield dwn.processMessage(alice.did, otherProtocolConfigure.message);
|
|
154
|
+
expect(otherProtocolConfigureReply.status.code).to.equal(401);
|
|
155
|
+
expect(otherProtocolConfigureReply.status.detail).to.contain(DwnErrorCode.ProtocolsGrantAuthorizationScopeProtocolMismatch);
|
|
156
|
+
}));
|
|
157
|
+
});
|
|
158
|
+
describe('RecordsWrite.parse()', () => __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
it('should throw if a message invokes a author-delegated grant (ID) but the author-delegated grant is not given', () => __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
161
|
+
const bob = yield TestDataGenerator.generatePersona();
|
|
162
|
+
// Alice grants Bob to write as her for the chat protocol
|
|
163
|
+
const scope = {
|
|
164
|
+
interface: DwnInterfaceName.Records,
|
|
165
|
+
method: DwnMethodName.Write,
|
|
166
|
+
protocol: 'chat'
|
|
167
|
+
};
|
|
168
|
+
const grantToBob = yield PermissionsProtocol.createGrant({
|
|
169
|
+
delegated: true, // this is a delegated grant
|
|
170
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
171
|
+
description: 'Allow Bob to write as me in chat protocol',
|
|
172
|
+
grantedTo: bob.did,
|
|
173
|
+
scope,
|
|
174
|
+
signer: Jws.createSigner(alice)
|
|
175
|
+
});
|
|
176
|
+
// Bob creates a chat message invoking the delegated grant (ID) but does not include the author-delegated grant (we remove it below)
|
|
177
|
+
const recordsWrite = yield RecordsWrite.create({
|
|
178
|
+
signer: Jws.createSigner(bob),
|
|
179
|
+
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
180
|
+
dataFormat: 'application/octet-stream',
|
|
181
|
+
data: TestDataGenerator.randomBytes(10),
|
|
182
|
+
});
|
|
183
|
+
delete recordsWrite.message.authorization.authorDelegatedGrant; // intentionally remove `authorDelegatedGrant`
|
|
184
|
+
const parsePromise = RecordsWrite.parse(recordsWrite.message);
|
|
185
|
+
yield expect(parsePromise).to.be.rejectedWith(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
|
|
186
|
+
}));
|
|
187
|
+
it('should throw if a message includes an author-delegated grant but does not reference it in author signature', () => __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
189
|
+
const bob = yield TestDataGenerator.generatePersona();
|
|
190
|
+
// Alice grants Bob to write as her for the chat protocol
|
|
191
|
+
const scope = {
|
|
192
|
+
interface: DwnInterfaceName.Records,
|
|
193
|
+
method: DwnMethodName.Write,
|
|
194
|
+
protocol: 'chat'
|
|
195
|
+
};
|
|
196
|
+
const grantToBob = yield PermissionsProtocol.createGrant({
|
|
197
|
+
delegated: true, // this is a delegated grant
|
|
198
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
199
|
+
description: 'Allow Bob to write as me in chat protocol',
|
|
200
|
+
grantedTo: bob.did,
|
|
201
|
+
scope,
|
|
202
|
+
signer: Jws.createSigner(alice)
|
|
203
|
+
});
|
|
204
|
+
// Bob attempts to sign as Alice by including an author-delegated grant
|
|
205
|
+
// but does not reference the grant ID in author signature (we remove it below)
|
|
206
|
+
const recordsWrite = yield RecordsWrite.create({
|
|
207
|
+
signer: Jws.createSigner(bob),
|
|
208
|
+
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
209
|
+
dataFormat: 'application/octet-stream',
|
|
210
|
+
data: TestDataGenerator.randomBytes(10),
|
|
211
|
+
});
|
|
212
|
+
const authorSignaturePayloadCopy = Object.assign({}, recordsWrite.signaturePayload);
|
|
213
|
+
delete authorSignaturePayloadCopy.delegatedGrantId; // intentionally remove `delegatedGrantId` in author signature
|
|
214
|
+
recordsWrite.message.authorization.signature.payload = Encoder.stringToBase64Url(JSON.stringify(authorSignaturePayloadCopy));
|
|
215
|
+
const parsePromise = RecordsWrite.parse(recordsWrite.message);
|
|
216
|
+
yield expect(parsePromise).to.be.rejectedWith(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
|
|
217
|
+
}));
|
|
218
|
+
}));
|
|
219
|
+
it('should only allow correct entity invoking an author-delegated grant to write', () => __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
// scenario:
|
|
222
|
+
// 1. Alice creates a delegated grant for Device X and Device Y,
|
|
223
|
+
// 2. Device X and Y can both use their grants to write a message to Bob's DWN as Alice
|
|
224
|
+
// 3. Messages written by device X and Y should be considered to have been authored by Alice
|
|
225
|
+
// 4. Carol should not be able to write a message as Alice using Device X's delegated grant
|
|
226
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
227
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
228
|
+
const deviceY = yield TestDataGenerator.generateDidKeyPersona();
|
|
229
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
230
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
231
|
+
// Bob has the message protocol installed
|
|
232
|
+
const protocolDefinition = messageProtocolDefinition;
|
|
233
|
+
const protocol = protocolDefinition.protocol;
|
|
234
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
235
|
+
author: bob,
|
|
236
|
+
protocolDefinition
|
|
237
|
+
});
|
|
238
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
239
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
240
|
+
// Alice creates a delegated grant for device X and device Y
|
|
241
|
+
const scope = {
|
|
242
|
+
interface: DwnInterfaceName.Records,
|
|
243
|
+
method: DwnMethodName.Write,
|
|
244
|
+
protocol
|
|
245
|
+
};
|
|
246
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
247
|
+
delegated: true, // this is a delegated grant
|
|
248
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
249
|
+
grantedTo: deviceX.did,
|
|
250
|
+
scope: scope,
|
|
251
|
+
signer: Jws.createSigner(alice)
|
|
252
|
+
});
|
|
253
|
+
const deviceYGrant = yield PermissionsProtocol.createGrant({
|
|
254
|
+
delegated: true, // this is a delegated grant
|
|
255
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
256
|
+
grantedTo: deviceY.did,
|
|
257
|
+
scope: scope,
|
|
258
|
+
signer: Jws.createSigner(alice)
|
|
259
|
+
});
|
|
260
|
+
// generate a `RecordsWrite` message from device X and write to Bob's DWN
|
|
261
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
262
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
263
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
264
|
+
signer: Jws.createSigner(deviceX),
|
|
265
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
266
|
+
protocol,
|
|
267
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
268
|
+
schema: protocolDefinition.types.message.schema,
|
|
269
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
270
|
+
data: deviceXData
|
|
271
|
+
});
|
|
272
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
273
|
+
expect(deviceXWriteReply.status.code).to.equal(202);
|
|
274
|
+
// verify the message by device X got written to Bob's DWN, AND Alice is the logical author
|
|
275
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
276
|
+
author: bob,
|
|
277
|
+
filter: { protocol }
|
|
278
|
+
});
|
|
279
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
280
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
281
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
282
|
+
const fetchedDeviceXWriteEntry = bobRecordsQueryReply.entries[0];
|
|
283
|
+
expect(fetchedDeviceXWriteEntry.encodedData).to.equal(base64url.baseEncode(deviceXData));
|
|
284
|
+
const fetchedDeviceXWrite = yield RecordsWrite.parse(fetchedDeviceXWriteEntry);
|
|
285
|
+
expect(fetchedDeviceXWrite.author).to.equal(alice.did);
|
|
286
|
+
// generate a new message by device Y updating the existing record device X created, and write to Bob's DWN
|
|
287
|
+
const deviceYData = new TextEncoder().encode('message from device Y');
|
|
288
|
+
const deviceYDataStream = DataStream.fromBytes(deviceYData);
|
|
289
|
+
const messageByDeviceY = yield RecordsWrite.createFrom({
|
|
290
|
+
recordsWriteMessage: fetchedDeviceXWrite.message,
|
|
291
|
+
data: deviceYData,
|
|
292
|
+
signer: Jws.createSigner(deviceY),
|
|
293
|
+
delegatedGrant: deviceYGrant.dataEncodedMessage,
|
|
294
|
+
});
|
|
295
|
+
const deviceYWriteReply = yield dwn.processMessage(bob.did, messageByDeviceY.message, { dataStream: deviceYDataStream });
|
|
296
|
+
expect(deviceYWriteReply.status.code).to.equal(202);
|
|
297
|
+
// verify the message by device Y got written to Bob's DWN, AND Alice is the logical author
|
|
298
|
+
const bobRecordsQueryReply2 = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
299
|
+
expect(bobRecordsQueryReply2.status.code).to.equal(200);
|
|
300
|
+
expect((_b = bobRecordsQueryReply2.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
301
|
+
const fetchedDeviceYWriteEntry = bobRecordsQueryReply2.entries[0];
|
|
302
|
+
expect(fetchedDeviceYWriteEntry.encodedData).to.equal(base64url.baseEncode(deviceYData));
|
|
303
|
+
const fetchedDeviceYWrite = yield RecordsWrite.parse(fetchedDeviceYWriteEntry);
|
|
304
|
+
expect(fetchedDeviceYWrite.author).to.equal(alice.did);
|
|
305
|
+
// Verify that Carol cannot write a chat message as Alice by invoking the Device X's grant
|
|
306
|
+
const messageByCarolAsAlice = new TextEncoder().encode('Message from Carol pretending to be Alice');
|
|
307
|
+
const writeByCarolAsAlice = yield RecordsWrite.create({
|
|
308
|
+
signer: Jws.createSigner(carol),
|
|
309
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
310
|
+
protocol,
|
|
311
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
312
|
+
schema: protocolDefinition.types.message.schema,
|
|
313
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
314
|
+
data: messageByCarolAsAlice
|
|
315
|
+
});
|
|
316
|
+
const carolWriteReply = yield dwn.processMessage(carol.did, writeByCarolAsAlice.message, { dataStream: DataStream.fromBytes(messageByCarolAsAlice) });
|
|
317
|
+
expect(carolWriteReply.status.code).to.equal(400);
|
|
318
|
+
expect(carolWriteReply.status.detail).to.contain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
319
|
+
}));
|
|
320
|
+
it('should only allow correct entity invoking an author-delegated grant to read and query ', () => __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
var _a, _b, _c, _d;
|
|
322
|
+
// scenario:
|
|
323
|
+
// 1. Alice creates read and query delegated grants for device X,
|
|
324
|
+
// 2. Bob starts a chat thread with Alice on his DWN
|
|
325
|
+
// 3. device X should be able to read the chat thread
|
|
326
|
+
// 4. Carol should not be able to read the chat thread using device X's delegated grant
|
|
327
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
328
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
329
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
330
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
331
|
+
// Bob has the chat protocol installed
|
|
332
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
333
|
+
const protocol = threadRoleProtocolDefinition.protocol;
|
|
334
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
335
|
+
author: bob,
|
|
336
|
+
protocolDefinition
|
|
337
|
+
});
|
|
338
|
+
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
339
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
340
|
+
// Bob starts a chat thread
|
|
341
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
342
|
+
author: bob,
|
|
343
|
+
protocol: protocolDefinition.protocol,
|
|
344
|
+
protocolPath: 'thread',
|
|
345
|
+
});
|
|
346
|
+
const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
347
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
348
|
+
// Bob adds Alice as a participant in the thread
|
|
349
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
350
|
+
author: bob,
|
|
351
|
+
recipient: alice.did,
|
|
352
|
+
protocol: protocolDefinition.protocol,
|
|
353
|
+
protocolPath: 'thread/participant',
|
|
354
|
+
parentContextId: threadRecord.message.contextId,
|
|
355
|
+
data: new TextEncoder().encode('Alice is my friend'),
|
|
356
|
+
});
|
|
357
|
+
const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
358
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
359
|
+
// Bob writes a chat message in the thread
|
|
360
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
361
|
+
author: bob,
|
|
362
|
+
protocol: protocolDefinition.protocol,
|
|
363
|
+
protocolPath: 'thread/chat',
|
|
364
|
+
parentContextId: threadRecord.message.contextId,
|
|
365
|
+
});
|
|
366
|
+
const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
367
|
+
expect(chatRecordReply.status.code).to.equal(202);
|
|
368
|
+
// Alice creates a delegated query grant for device X to act as Alice.
|
|
369
|
+
const queryGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
370
|
+
delegated: true, // this is a delegated grant
|
|
371
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
372
|
+
grantedTo: deviceX.did,
|
|
373
|
+
scope: {
|
|
374
|
+
interface: DwnInterfaceName.Records,
|
|
375
|
+
method: DwnMethodName.Query,
|
|
376
|
+
protocol
|
|
377
|
+
},
|
|
378
|
+
signer: Jws.createSigner(alice)
|
|
379
|
+
});
|
|
380
|
+
// Alice creates a delegated read grant for device X to act as Alice.
|
|
381
|
+
const readGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
382
|
+
delegated: true, // this is a delegated grant
|
|
383
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
384
|
+
grantedTo: deviceX.did,
|
|
385
|
+
scope: {
|
|
386
|
+
interface: DwnInterfaceName.Records,
|
|
387
|
+
method: DwnMethodName.Read,
|
|
388
|
+
protocol
|
|
389
|
+
},
|
|
390
|
+
signer: Jws.createSigner(alice)
|
|
391
|
+
});
|
|
392
|
+
// sanity verify Bob himself is able to query for the chat thread from Bob's DWN
|
|
393
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
394
|
+
author: bob,
|
|
395
|
+
filter: { protocol }
|
|
396
|
+
});
|
|
397
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
398
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
399
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(3);
|
|
400
|
+
// sanity verify Alice herself is able to query for the chat message from Bob's DWN
|
|
401
|
+
const recordsQueryByAlice = yield RecordsQuery.create({
|
|
402
|
+
signer: Jws.createSigner(alice),
|
|
403
|
+
protocolRole: 'thread/participant',
|
|
404
|
+
filter: {
|
|
405
|
+
protocol,
|
|
406
|
+
contextId: threadRecord.message.contextId,
|
|
407
|
+
protocolPath: 'thread/chat'
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const aliceRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByAlice.message);
|
|
411
|
+
expect(aliceRecordsQueryReply.status.code).to.equal(200);
|
|
412
|
+
expect((_b = aliceRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
413
|
+
// verify device X is able to query for the chat message from Bob's DWN
|
|
414
|
+
const recordsQueryByDeviceX = yield RecordsQuery.create({
|
|
415
|
+
signer: Jws.createSigner(deviceX),
|
|
416
|
+
delegatedGrant: queryGrantForDeviceX.dataEncodedMessage,
|
|
417
|
+
protocolRole: 'thread/participant',
|
|
418
|
+
filter: {
|
|
419
|
+
protocol,
|
|
420
|
+
contextId: threadRecord.message.contextId,
|
|
421
|
+
protocolPath: 'thread/chat'
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
const deviceXRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
|
|
425
|
+
expect(deviceXRecordsQueryReply.status.code).to.equal(200);
|
|
426
|
+
expect((_c = deviceXRecordsQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
427
|
+
// verify device X is able to read the chat message from Bob's DWN
|
|
428
|
+
const recordsReadByDeviceX = yield RecordsRead.create({
|
|
429
|
+
signer: Jws.createSigner(deviceX),
|
|
430
|
+
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
431
|
+
protocolRole: 'thread/participant',
|
|
432
|
+
filter: {
|
|
433
|
+
recordId: chatRecord.message.recordId
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
const deviceXRecordsReadReply = yield dwn.processMessage(bob.did, recordsReadByDeviceX.message);
|
|
437
|
+
expect(deviceXRecordsReadReply.status.code).to.equal(200);
|
|
438
|
+
expect((_d = deviceXRecordsReadReply.entry.recordsWrite) === null || _d === void 0 ? void 0 : _d.recordId).to.equal(chatRecord.message.recordId);
|
|
439
|
+
// Verify that Carol cannot query as Alice by invoking the delegated grant granted to Device X
|
|
440
|
+
const recordsQueryByCarol = yield RecordsQuery.create({
|
|
441
|
+
signer: Jws.createSigner(carol),
|
|
442
|
+
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
443
|
+
protocolRole: 'thread/participant',
|
|
444
|
+
filter: {
|
|
445
|
+
protocol,
|
|
446
|
+
contextId: threadRecord.message.contextId,
|
|
447
|
+
protocolPath: 'thread/chat'
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
const recordsQueryByCarolReply = yield dwn.processMessage(bob.did, recordsQueryByCarol.message);
|
|
451
|
+
expect(recordsQueryByCarolReply.status.code).to.equal(400);
|
|
452
|
+
expect(recordsQueryByCarolReply.status.detail).to.contain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
453
|
+
// Verify that Carol cannot read as Alice by invoking the delegated grant granted to Device X
|
|
454
|
+
const recordsReadByCarol = yield RecordsRead.create({
|
|
455
|
+
signer: Jws.createSigner(carol),
|
|
456
|
+
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
457
|
+
protocolRole: 'thread/participant',
|
|
458
|
+
filter: {
|
|
459
|
+
recordId: chatRecord.message.recordId
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
const recordsReadByCarolReply = yield dwn.processMessage(bob.did, recordsReadByCarol.message);
|
|
463
|
+
expect(recordsReadByCarolReply.status.code).to.equal(400);
|
|
464
|
+
expect(recordsQueryByCarolReply.status.detail).to.contain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
465
|
+
}));
|
|
466
|
+
it('should only allow correct entity invoking an author-delegated grant to subscribe', () => __awaiter(this, void 0, void 0, function* () {
|
|
467
|
+
// scenario:
|
|
468
|
+
// 1. Bob installs a chat protocol and creates a thread, adding Alice as a participant.
|
|
469
|
+
// 2. Alice a creates subscribe delegated grant for device X,
|
|
470
|
+
// 3. Carol should not be able to subscribe to the chat using deviceX's delegated grant.
|
|
471
|
+
// 4. deviceX creates a subscription to receive events using the delegated grant.
|
|
472
|
+
// 5. Bob writes two chat messages to the thread.
|
|
473
|
+
// 6. The subscription should have received the chat messages.
|
|
474
|
+
// 7. Bob deletes one of the chat messages.
|
|
475
|
+
// 8. The subscription should have received the delete event.
|
|
476
|
+
var _a;
|
|
477
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
478
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
479
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
480
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
481
|
+
// Bob has the chat protocol installed
|
|
482
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
483
|
+
const protocol = threadRoleProtocolDefinition.protocol;
|
|
484
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
485
|
+
author: bob,
|
|
486
|
+
protocolDefinition
|
|
487
|
+
});
|
|
488
|
+
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
489
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
490
|
+
// Bob starts a chat thread
|
|
491
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
492
|
+
author: bob,
|
|
493
|
+
protocol: protocolDefinition.protocol,
|
|
494
|
+
protocolPath: 'thread',
|
|
495
|
+
});
|
|
496
|
+
const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
497
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
498
|
+
// Bob adds Alice as a participant in the thread
|
|
499
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
500
|
+
author: bob,
|
|
501
|
+
recipient: alice.did,
|
|
502
|
+
protocol: protocolDefinition.protocol,
|
|
503
|
+
protocolPath: 'thread/participant',
|
|
504
|
+
parentContextId: threadRecord.message.contextId,
|
|
505
|
+
data: new TextEncoder().encode('Alice is my friend'),
|
|
506
|
+
});
|
|
507
|
+
const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
508
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
509
|
+
// Alice creates a delegated subscribe grant for device X to act as Alice.
|
|
510
|
+
const subscribeGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
511
|
+
delegated: true, // this is a delegated grant
|
|
512
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
513
|
+
grantedTo: deviceX.did,
|
|
514
|
+
scope: {
|
|
515
|
+
interface: DwnInterfaceName.Records,
|
|
516
|
+
method: DwnMethodName.Subscribe,
|
|
517
|
+
protocol
|
|
518
|
+
},
|
|
519
|
+
signer: Jws.createSigner(alice)
|
|
520
|
+
});
|
|
521
|
+
// Create a handler to set or delete the chat record ID in the subscription set depending on the interface method
|
|
522
|
+
const subscriptionChatRecords = new Set();
|
|
523
|
+
const captureChatRecords = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
524
|
+
const { message } = event;
|
|
525
|
+
if (message.descriptor.method === DwnMethodName.Delete) {
|
|
526
|
+
const recordId = message.descriptor.recordId;
|
|
527
|
+
subscriptionChatRecords.delete(recordId);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
const recordId = message.recordId;
|
|
531
|
+
subscriptionChatRecords.add(recordId);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
// control: verify that device X cannot subscribe to the chat thread without the delegated grant
|
|
535
|
+
const recordsSubscribeByDeviceXWithoutGrant = yield RecordsSubscribe.create({
|
|
536
|
+
signer: Jws.createSigner(deviceX),
|
|
537
|
+
protocolRole: 'thread/participant',
|
|
538
|
+
filter: {
|
|
539
|
+
contextId: threadRecord.message.contextId,
|
|
540
|
+
protocol: protocolDefinition.protocol,
|
|
541
|
+
protocolPath: 'thread/chat'
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
const recordsSubscribeByDeviceXWithoutGrantReply = yield dwn.processMessage(bob.did, recordsSubscribeByDeviceXWithoutGrant.message);
|
|
545
|
+
expect(recordsSubscribeByDeviceXWithoutGrantReply.status.code).to.equal(401, 'device X without grant subscribe');
|
|
546
|
+
// control: verify that Carol cannot subscribe as Alice by invoking the delegated grant granted to Device X
|
|
547
|
+
const recordsSubscribeByCarol = yield RecordsSubscribe.create({
|
|
548
|
+
signer: Jws.createSigner(carol),
|
|
549
|
+
delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
|
|
550
|
+
protocolRole: 'thread/participant',
|
|
551
|
+
filter: {
|
|
552
|
+
contextId: threadRecord.message.contextId,
|
|
553
|
+
protocol: protocolDefinition.protocol,
|
|
554
|
+
protocolPath: 'thread/chat'
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
const recordsSubscribeByCarolReply = yield dwn.processMessage(bob.did, recordsSubscribeByCarol.message);
|
|
558
|
+
expect(recordsSubscribeByCarolReply.status.code).to.equal(400, 'carol subscribe');
|
|
559
|
+
expect(recordsSubscribeByCarolReply.status.detail).to.contain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
560
|
+
// verify device X is able to subscribe the chat message from Bob's DWN using the delegated grant
|
|
561
|
+
const recordsSubscribeByDeviceX = yield RecordsSubscribe.create({
|
|
562
|
+
signer: Jws.createSigner(deviceX),
|
|
563
|
+
delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
|
|
564
|
+
protocolRole: 'thread/participant',
|
|
565
|
+
filter: {
|
|
566
|
+
contextId: threadRecord.message.contextId,
|
|
567
|
+
protocol: protocolDefinition.protocol,
|
|
568
|
+
protocolPath: 'thread/chat'
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
const recordsSubscribeByDeviceXReply = yield dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message, {
|
|
572
|
+
subscriptionHandler: captureChatRecords
|
|
573
|
+
});
|
|
574
|
+
expect(recordsSubscribeByDeviceXReply.status.code).to.equal(200, 'subscribe');
|
|
575
|
+
// Bob writes chat messages in the thread
|
|
576
|
+
const chatRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
577
|
+
author: bob,
|
|
578
|
+
protocol: protocolDefinition.protocol,
|
|
579
|
+
protocolPath: 'thread/chat',
|
|
580
|
+
parentContextId: threadRecord.message.contextId,
|
|
581
|
+
});
|
|
582
|
+
const chatRecord1Reply = yield dwn.processMessage(bob.did, chatRecord1.message, { dataStream: chatRecord1.dataStream });
|
|
583
|
+
expect(chatRecord1Reply.status.code).to.equal(202);
|
|
584
|
+
const chatRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
585
|
+
author: bob,
|
|
586
|
+
protocol: protocolDefinition.protocol,
|
|
587
|
+
protocolPath: 'thread/chat',
|
|
588
|
+
parentContextId: threadRecord.message.contextId,
|
|
589
|
+
});
|
|
590
|
+
const chatRecord2Reply = yield dwn.processMessage(bob.did, chatRecord2.message, { dataStream: chatRecord2.dataStream });
|
|
591
|
+
expect(chatRecord2Reply.status.code).to.equal(202);
|
|
592
|
+
yield Poller.pollUntilSuccessOrTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
593
|
+
expect(subscriptionChatRecords.size).to.equal(2);
|
|
594
|
+
expect([...subscriptionChatRecords]).to.have.members([chatRecord1.message.recordId, chatRecord2.message.recordId]);
|
|
595
|
+
}));
|
|
596
|
+
yield ((_a = recordsSubscribeByDeviceXReply.subscription) === null || _a === void 0 ? void 0 : _a.close());
|
|
597
|
+
}));
|
|
598
|
+
it('should only allow correct entity invoking an author-delegated grant to delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
599
|
+
var _a, _b;
|
|
600
|
+
// scenario:
|
|
601
|
+
// 1. Bob installs the chat protocol on his DWN and makes Alice an admin
|
|
602
|
+
// 2. Bob starts a chat thread with Carol on his DWN
|
|
603
|
+
// 3. Alice creates a delegated grant for Device X to act as her
|
|
604
|
+
// 4. Carol should not be able to delete a chat message as Alice using Device X's delegated grant
|
|
605
|
+
// 5. Device X should be able to delete a chat message as Alice
|
|
606
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
607
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
608
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
609
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
610
|
+
// Bob has the chat protocol installed
|
|
611
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
612
|
+
const protocol = threadRoleProtocolDefinition.protocol;
|
|
613
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
614
|
+
author: bob,
|
|
615
|
+
protocolDefinition
|
|
616
|
+
});
|
|
617
|
+
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
618
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
619
|
+
// Bob adds Alice as an admin
|
|
620
|
+
const globalAdminRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
621
|
+
author: bob,
|
|
622
|
+
recipient: alice.did,
|
|
623
|
+
protocol: protocolDefinition.protocol,
|
|
624
|
+
protocolPath: 'globalAdmin',
|
|
625
|
+
data: new TextEncoder().encode('I trust Alice to manage my chat thread'),
|
|
626
|
+
});
|
|
627
|
+
const globalAdminRecordReply = yield dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
|
|
628
|
+
expect(globalAdminRecordReply.status.code).to.equal(202);
|
|
629
|
+
// Bob starts a chat thread
|
|
630
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
631
|
+
author: bob,
|
|
632
|
+
protocol: protocolDefinition.protocol,
|
|
633
|
+
protocolPath: 'thread',
|
|
634
|
+
});
|
|
635
|
+
const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
636
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
637
|
+
// Bob adds Carol as a participant in the thread
|
|
638
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
639
|
+
author: bob,
|
|
640
|
+
recipient: carol.did,
|
|
641
|
+
protocol: protocolDefinition.protocol,
|
|
642
|
+
protocolPath: 'thread/participant',
|
|
643
|
+
parentContextId: threadRecord.message.contextId
|
|
644
|
+
});
|
|
645
|
+
const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
646
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
647
|
+
// Carol writes a chat message in the thread
|
|
648
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
649
|
+
author: carol,
|
|
650
|
+
protocolRole: 'thread/participant',
|
|
651
|
+
protocol: protocolDefinition.protocol,
|
|
652
|
+
protocolPath: 'thread/chat',
|
|
653
|
+
parentContextId: threadRecord.message.contextId,
|
|
654
|
+
data: new TextEncoder().encode('A rude message'),
|
|
655
|
+
});
|
|
656
|
+
const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
657
|
+
expect(chatRecordReply.status.code).to.equal(202);
|
|
658
|
+
// Alice creates a delegated delete grant for device X to act as Alice.
|
|
659
|
+
const deleteGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
660
|
+
delegated: true, // this is a delegated grant
|
|
661
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
662
|
+
grantedTo: deviceX.did,
|
|
663
|
+
scope: {
|
|
664
|
+
interface: DwnInterfaceName.Records,
|
|
665
|
+
method: DwnMethodName.Delete,
|
|
666
|
+
protocol
|
|
667
|
+
},
|
|
668
|
+
signer: Jws.createSigner(alice)
|
|
669
|
+
});
|
|
670
|
+
// verify Carol is not able to delete Carol's chat message from Bob's DWN
|
|
671
|
+
const recordsDeleteByCarol = yield RecordsDelete.create({
|
|
672
|
+
signer: Jws.createSigner(carol),
|
|
673
|
+
delegatedGrant: deleteGrantForDeviceX.dataEncodedMessage,
|
|
674
|
+
protocolRole: 'thread/participant',
|
|
675
|
+
recordId: chatRecord.message.recordId
|
|
676
|
+
});
|
|
677
|
+
const carolRecordsDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByCarol.message);
|
|
678
|
+
expect(carolRecordsDeleteReply.status.code).to.equal(400);
|
|
679
|
+
// sanity verify the chat message is still in Bob's DWN
|
|
680
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
681
|
+
author: bob,
|
|
682
|
+
filter: { protocolPath: 'thread/chat' }
|
|
683
|
+
});
|
|
684
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
685
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
686
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
687
|
+
// verify device X is able to delete Carol's chat message from Bob's DWN
|
|
688
|
+
const recordsDeleteByDeviceX = yield RecordsDelete.create({
|
|
689
|
+
signer: Jws.createSigner(deviceX),
|
|
690
|
+
delegatedGrant: deleteGrantForDeviceX.dataEncodedMessage,
|
|
691
|
+
protocolRole: 'globalAdmin',
|
|
692
|
+
recordId: chatRecord.message.recordId
|
|
693
|
+
});
|
|
694
|
+
const deviceXRecordsDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
|
|
695
|
+
expect(deviceXRecordsDeleteReply.status.code).to.equal(202);
|
|
696
|
+
// sanity verify the chat message is no longer queryable from Bob's DWN
|
|
697
|
+
const bobRecordsQueryReply2 = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
698
|
+
expect(bobRecordsQueryReply2.status.code).to.equal(200);
|
|
699
|
+
expect((_b = bobRecordsQueryReply2.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(0);
|
|
700
|
+
}));
|
|
701
|
+
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke write', () => __awaiter(this, void 0, void 0, function* () {
|
|
702
|
+
var _a;
|
|
703
|
+
// scenario:
|
|
704
|
+
// 1. Bob has the message protocol installed
|
|
705
|
+
// 2. Alice creates a non-delegated grant for device X
|
|
706
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the non-delegated grant
|
|
707
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
708
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
709
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
710
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
711
|
+
// 1. Bob has the message protocol installed
|
|
712
|
+
const protocolDefinition = messageProtocolDefinition;
|
|
713
|
+
const protocol = protocolDefinition.protocol;
|
|
714
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
715
|
+
author: bob,
|
|
716
|
+
protocolDefinition
|
|
717
|
+
});
|
|
718
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
719
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
720
|
+
// 2. Alice creates a non-delegated grant for device X
|
|
721
|
+
const scope = {
|
|
722
|
+
interface: DwnInterfaceName.Records,
|
|
723
|
+
method: DwnMethodName.Write,
|
|
724
|
+
protocol
|
|
725
|
+
};
|
|
726
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
727
|
+
// delegated : true, // intentionally commented out to show that this is not a delegated grant
|
|
728
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
729
|
+
grantedTo: deviceX.did,
|
|
730
|
+
scope: scope,
|
|
731
|
+
signer: Jws.createSigner(alice)
|
|
732
|
+
});
|
|
733
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the non-delegated grant
|
|
734
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
735
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
736
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
737
|
+
signer: Jws.createSigner(deviceX),
|
|
738
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
739
|
+
protocol,
|
|
740
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
741
|
+
schema: protocolDefinition.types.message.schema,
|
|
742
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
743
|
+
data: deviceXData
|
|
744
|
+
});
|
|
745
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
746
|
+
expect(deviceXWriteReply.status.code).to.equal(400);
|
|
747
|
+
expect(deviceXWriteReply.status.detail).to.contain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
|
|
748
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
749
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
750
|
+
author: bob,
|
|
751
|
+
filter: { protocol }
|
|
752
|
+
});
|
|
753
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
754
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
755
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(0);
|
|
756
|
+
}));
|
|
757
|
+
xit('should not allow entity using a non-delegated grant as an author-delegated grant to invoke read', () => __awaiter(this, void 0, void 0, function* () {
|
|
758
|
+
}));
|
|
759
|
+
xit('should not allow entity using a non-delegated grant as an author-delegated grant to invoke query', () => __awaiter(this, void 0, void 0, function* () {
|
|
760
|
+
}));
|
|
761
|
+
xit('should not allow entity using a non-delegated grant as an author-delegated grant to invoke delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
762
|
+
}));
|
|
763
|
+
it('should fail if author-delegated grant has a mismatching protocol scope - write', () => __awaiter(this, void 0, void 0, function* () {
|
|
764
|
+
// scenario:
|
|
765
|
+
// 1. Alice creates a delegated grant for device X to act as her for a protocol that is NOT email protocol
|
|
766
|
+
// 2. Bob has email protocol configured for his DWN that allows anyone to write an email to him
|
|
767
|
+
// 3. Device X attempts to use the delegated grant to write an email to Bob as Alice
|
|
768
|
+
// 4. Bob's DWN should reject Device X's message
|
|
769
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
770
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
771
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
772
|
+
// 1. Alice creates a delegated grant for device X to act as her for a protocol that is NOT email protocol
|
|
773
|
+
const scope = {
|
|
774
|
+
interface: DwnInterfaceName.Records,
|
|
775
|
+
method: DwnMethodName.Write,
|
|
776
|
+
protocol: 'random-protocol'
|
|
777
|
+
};
|
|
778
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
779
|
+
delegated: true, // this is a delegated grant
|
|
780
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
781
|
+
grantedTo: deviceX.did,
|
|
782
|
+
scope: scope,
|
|
783
|
+
signer: Jws.createSigner(alice)
|
|
784
|
+
});
|
|
785
|
+
// 2. Bob has email protocol configured for his DWN that allows anyone to write an email to him
|
|
786
|
+
const protocolDefinition = emailProtocolDefinition;
|
|
787
|
+
const protocol = protocolDefinition.protocol;
|
|
788
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
789
|
+
author: bob,
|
|
790
|
+
protocolDefinition
|
|
791
|
+
});
|
|
792
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
793
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
794
|
+
// 3. Device X attempts to use the delegated grant to write an email to Bob as Alice
|
|
795
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
796
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
797
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
798
|
+
signer: Jws.createSigner(deviceX),
|
|
799
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
800
|
+
protocol,
|
|
801
|
+
protocolPath: 'email', // this comes from `types` in protocol definition
|
|
802
|
+
schema: protocolDefinition.types.email.schema,
|
|
803
|
+
dataFormat: protocolDefinition.types.email.dataFormats[0],
|
|
804
|
+
data: deviceXData
|
|
805
|
+
});
|
|
806
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
807
|
+
expect(deviceXWriteReply.status.code).to.equal(401);
|
|
808
|
+
expect(deviceXWriteReply.status.detail).to.contain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
809
|
+
}));
|
|
810
|
+
it('should fail if author-delegated grant has a mismatching protocol scope - query, subscribe & read', () => __awaiter(this, void 0, void 0, function* () {
|
|
811
|
+
// scenario:
|
|
812
|
+
// 1. Bob starts a chat thread with Alice on his DWN
|
|
813
|
+
// 2. Alice creates a delegated grant for device X to act as her for a protocol that is NOT chat protocol
|
|
814
|
+
// 3. Device X attempts to use the delegated grant to read, query and subscribe to the chat thread and gets rejected by Bob's DWN
|
|
815
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
816
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
817
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
818
|
+
// 1. Bob starts a chat thread with Alice on his DWN
|
|
819
|
+
// Bob has the chat protocol installed
|
|
820
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
821
|
+
const protocol = threadRoleProtocolDefinition.protocol;
|
|
822
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
823
|
+
author: bob,
|
|
824
|
+
protocolDefinition
|
|
825
|
+
});
|
|
826
|
+
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
827
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
828
|
+
// Bob starts a chat thread
|
|
829
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
830
|
+
author: bob,
|
|
831
|
+
protocol: protocolDefinition.protocol,
|
|
832
|
+
protocolPath: 'thread',
|
|
833
|
+
});
|
|
834
|
+
const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
835
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
836
|
+
// Bob adds Alice as a participant in the thread
|
|
837
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
838
|
+
author: bob,
|
|
839
|
+
recipient: alice.did,
|
|
840
|
+
protocol: protocolDefinition.protocol,
|
|
841
|
+
protocolPath: 'thread/participant',
|
|
842
|
+
parentContextId: threadRecord.message.contextId,
|
|
843
|
+
data: new TextEncoder().encode('Alice is my friend'),
|
|
844
|
+
});
|
|
845
|
+
const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
846
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
847
|
+
// Bob writes a chat message in the thread
|
|
848
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
849
|
+
author: bob,
|
|
850
|
+
protocol: protocolDefinition.protocol,
|
|
851
|
+
protocolPath: 'thread/chat',
|
|
852
|
+
parentContextId: threadRecord.message.contextId,
|
|
853
|
+
});
|
|
854
|
+
const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
855
|
+
expect(chatRecordReply.status.code).to.equal(202);
|
|
856
|
+
// 2. Alice creates a delegated grant for device X to act as her for a protocol that is NOT chat protocol
|
|
857
|
+
// Alice creates a delegated query grant for device X to act as Alice but not for chat protocol
|
|
858
|
+
const queryGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
859
|
+
delegated: true, // this is a delegated grant
|
|
860
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
861
|
+
grantedTo: deviceX.did,
|
|
862
|
+
scope: {
|
|
863
|
+
interface: DwnInterfaceName.Records,
|
|
864
|
+
method: DwnMethodName.Query,
|
|
865
|
+
protocol: 'some-other-protocol'
|
|
866
|
+
},
|
|
867
|
+
signer: Jws.createSigner(alice)
|
|
868
|
+
});
|
|
869
|
+
// Alice creates a delegated read grant for device X to act as Alice but not for chat protocol
|
|
870
|
+
const readGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
871
|
+
delegated: true, // this is a delegated grant
|
|
872
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
873
|
+
grantedTo: deviceX.did,
|
|
874
|
+
scope: {
|
|
875
|
+
interface: DwnInterfaceName.Records,
|
|
876
|
+
method: DwnMethodName.Read,
|
|
877
|
+
protocol: 'some-other-protocol'
|
|
878
|
+
},
|
|
879
|
+
signer: Jws.createSigner(alice)
|
|
880
|
+
});
|
|
881
|
+
// Alice creates a delegated subscribe grant for device X to act as Alice but not for chat protocol
|
|
882
|
+
const subscribeGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
883
|
+
delegated: true, // this is a delegated grant
|
|
884
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
885
|
+
grantedTo: deviceX.did,
|
|
886
|
+
scope: {
|
|
887
|
+
interface: DwnInterfaceName.Records,
|
|
888
|
+
method: DwnMethodName.Subscribe,
|
|
889
|
+
protocol: 'some-other-protocol'
|
|
890
|
+
},
|
|
891
|
+
signer: Jws.createSigner(alice)
|
|
892
|
+
});
|
|
893
|
+
// 3. Device X attempts to use the delegated grant to read, query and subscribe to the chat thread and gets rejected by Bob's DWN
|
|
894
|
+
// verify device X querying for the chat message from Bob's DWN fails
|
|
895
|
+
const recordsQueryByDeviceX = yield RecordsQuery.create({
|
|
896
|
+
signer: Jws.createSigner(deviceX),
|
|
897
|
+
delegatedGrant: queryGrantForDeviceX.dataEncodedMessage,
|
|
898
|
+
protocolRole: 'thread/participant',
|
|
899
|
+
filter: {
|
|
900
|
+
protocol,
|
|
901
|
+
contextId: threadRecord.message.contextId,
|
|
902
|
+
protocolPath: 'thread/chat'
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
const deviceXRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
|
|
906
|
+
expect(deviceXRecordsQueryReply.status.code).to.equal(401);
|
|
907
|
+
expect(deviceXRecordsQueryReply.status.detail).to.contain(DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch);
|
|
908
|
+
// verify device X reading for the chat message from Bob's DWN fails
|
|
909
|
+
const recordsReadByDeviceX = yield RecordsRead.create({
|
|
910
|
+
signer: Jws.createSigner(deviceX),
|
|
911
|
+
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
912
|
+
protocolRole: 'thread/participant',
|
|
913
|
+
filter: {
|
|
914
|
+
recordId: chatRecord.message.recordId
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
const deviceXReadReply = yield dwn.processMessage(bob.did, recordsReadByDeviceX.message);
|
|
918
|
+
expect(deviceXReadReply.status.code).to.equal(401);
|
|
919
|
+
expect(deviceXReadReply.status.detail).to.contain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
920
|
+
// verify device X subscribing to the chat message from Bob's DWN fails
|
|
921
|
+
const recordsSubscribeByDeviceX = yield RecordsSubscribe.create({
|
|
922
|
+
signer: Jws.createSigner(deviceX),
|
|
923
|
+
delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
|
|
924
|
+
protocolRole: 'thread/participant',
|
|
925
|
+
filter: {
|
|
926
|
+
protocol,
|
|
927
|
+
contextId: threadRecord.message.contextId,
|
|
928
|
+
protocolPath: 'thread/chat'
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
const deviceXRecordsSubscribeReply = yield dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message);
|
|
932
|
+
expect(deviceXRecordsSubscribeReply.status.code).to.equal(401);
|
|
933
|
+
expect(deviceXRecordsSubscribeReply.status.detail).to.contain(DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch);
|
|
934
|
+
}));
|
|
935
|
+
it('should fail if author-delegated grant has a mismatching protocol scope - delete', () => __awaiter(this, void 0, void 0, function* () {
|
|
936
|
+
var _a;
|
|
937
|
+
// scenario:
|
|
938
|
+
// 1. Bob installs the chat protocol on his DWN and makes Alice an admin
|
|
939
|
+
// 2. Bob starts a chat thread with Carol on his DWN
|
|
940
|
+
// 3. Alice creates a delegated delete grant for Device X to act as her for a protocol that is NOT chat protocol
|
|
941
|
+
// 4. Device X should NOT be able to delete a chat message as Alice
|
|
942
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
943
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
944
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
945
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
946
|
+
// Bob has the chat protocol installed
|
|
947
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
948
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
949
|
+
author: bob,
|
|
950
|
+
protocolDefinition
|
|
951
|
+
});
|
|
952
|
+
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
953
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
954
|
+
// Bob adds Alice as an admin
|
|
955
|
+
const globalAdminRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
956
|
+
author: bob,
|
|
957
|
+
recipient: alice.did,
|
|
958
|
+
protocol: protocolDefinition.protocol,
|
|
959
|
+
protocolPath: 'globalAdmin',
|
|
960
|
+
data: new TextEncoder().encode('I trust Alice to manage my chat thread'),
|
|
961
|
+
});
|
|
962
|
+
const globalAdminRecordReply = yield dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
|
|
963
|
+
expect(globalAdminRecordReply.status.code).to.equal(202);
|
|
964
|
+
// Bob starts a chat thread
|
|
965
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
966
|
+
author: bob,
|
|
967
|
+
protocol: protocolDefinition.protocol,
|
|
968
|
+
protocolPath: 'thread',
|
|
969
|
+
});
|
|
970
|
+
const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
971
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
972
|
+
// Bob adds Carol as a participant in the thread
|
|
973
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
974
|
+
author: bob,
|
|
975
|
+
recipient: carol.did,
|
|
976
|
+
protocol: protocolDefinition.protocol,
|
|
977
|
+
protocolPath: 'thread/participant',
|
|
978
|
+
parentContextId: threadRecord.message.contextId
|
|
979
|
+
});
|
|
980
|
+
const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
981
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
982
|
+
// Carol writes a chat message in the thread
|
|
983
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
984
|
+
author: carol,
|
|
985
|
+
protocolRole: 'thread/participant',
|
|
986
|
+
protocol: protocolDefinition.protocol,
|
|
987
|
+
protocolPath: 'thread/chat',
|
|
988
|
+
parentContextId: threadRecord.message.contextId,
|
|
989
|
+
data: new TextEncoder().encode('A rude message'),
|
|
990
|
+
});
|
|
991
|
+
const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
992
|
+
expect(chatRecordReply.status.code).to.equal(202);
|
|
993
|
+
// Alice creates a delegated delete grant for Device X to act as her for a protocol that is NOT chat protocol
|
|
994
|
+
const delegatedGrantForDeviceX = yield PermissionsProtocol.createGrant({
|
|
995
|
+
delegated: true, // this is a delegated grant
|
|
996
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
997
|
+
grantedTo: deviceX.did,
|
|
998
|
+
scope: {
|
|
999
|
+
interface: DwnInterfaceName.Records,
|
|
1000
|
+
method: DwnMethodName.Delete,
|
|
1001
|
+
protocol: 'some-protocol-that-is-not-chat'
|
|
1002
|
+
},
|
|
1003
|
+
signer: Jws.createSigner(alice)
|
|
1004
|
+
});
|
|
1005
|
+
// verify device X is NOT able to delete Carol's chat message from Bob's DWN
|
|
1006
|
+
const recordsDeleteByDeviceX = yield RecordsDelete.create({
|
|
1007
|
+
signer: Jws.createSigner(deviceX),
|
|
1008
|
+
delegatedGrant: delegatedGrantForDeviceX.dataEncodedMessage,
|
|
1009
|
+
protocolRole: 'globalAdmin',
|
|
1010
|
+
recordId: chatRecord.message.recordId
|
|
1011
|
+
});
|
|
1012
|
+
const deviceXRecordsDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
|
|
1013
|
+
expect(deviceXRecordsDeleteReply.status.code).to.equal(401);
|
|
1014
|
+
expect(deviceXRecordsDeleteReply.status.detail).to.contain(DwnErrorCode.RecordsGrantAuthorizationDeleteProtocolScopeMismatch);
|
|
1015
|
+
// sanity verify the chat message is still in Bob's DWN
|
|
1016
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
1017
|
+
author: bob,
|
|
1018
|
+
filter: { protocolPath: 'thread/chat' }
|
|
1019
|
+
});
|
|
1020
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1021
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
1022
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
1023
|
+
}));
|
|
1024
|
+
it('should fail if presented with an author-delegated grant with invalid grantor signature - write', () => __awaiter(this, void 0, void 0, function* () {
|
|
1025
|
+
var _a;
|
|
1026
|
+
// scenario:
|
|
1027
|
+
// 1. Bob has the message protocol installed
|
|
1028
|
+
// 2. Alice creates a delegated grant for device X to write as Alice, but with invalid signature
|
|
1029
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the delegated grant with invalid grantor signature
|
|
1030
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1031
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1032
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1033
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
1034
|
+
// 1. Bob has the message protocol installed
|
|
1035
|
+
const protocolDefinition = messageProtocolDefinition;
|
|
1036
|
+
const protocol = protocolDefinition.protocol;
|
|
1037
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
1038
|
+
author: bob,
|
|
1039
|
+
protocolDefinition
|
|
1040
|
+
});
|
|
1041
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1042
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
1043
|
+
// 2. Alice creates a delegated grant for device X to write as Alice, but with invalid signature
|
|
1044
|
+
const scope = {
|
|
1045
|
+
interface: DwnInterfaceName.Records,
|
|
1046
|
+
method: DwnMethodName.Write,
|
|
1047
|
+
protocol
|
|
1048
|
+
};
|
|
1049
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
1050
|
+
delegated: true,
|
|
1051
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1052
|
+
grantedTo: deviceX.did,
|
|
1053
|
+
scope: scope,
|
|
1054
|
+
signer: Jws.createSigner(alice)
|
|
1055
|
+
});
|
|
1056
|
+
const deviceXGrantMessage = deviceXGrant.dataEncodedMessage;
|
|
1057
|
+
deviceXGrantMessage.authorization.signature.signatures[0].signature = yield TestDataGenerator.randomSignatureString();
|
|
1058
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the delegated grant with invalid grantor signature
|
|
1059
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1060
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1061
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
1062
|
+
signer: Jws.createSigner(deviceX),
|
|
1063
|
+
delegatedGrant: deviceXGrantMessage,
|
|
1064
|
+
protocol,
|
|
1065
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
1066
|
+
schema: protocolDefinition.types.message.schema,
|
|
1067
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1068
|
+
data: deviceXData
|
|
1069
|
+
});
|
|
1070
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1071
|
+
expect(deviceXWriteReply.status.code).to.equal(401);
|
|
1072
|
+
expect(deviceXWriteReply.status.detail).to.contain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
|
|
1073
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1074
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
1075
|
+
author: bob,
|
|
1076
|
+
filter: { protocol }
|
|
1077
|
+
});
|
|
1078
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1079
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
1080
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(0);
|
|
1081
|
+
}));
|
|
1082
|
+
it('should fail if the CID of the author-delegated grant and the grant ID in the payload of the message signature is mismatching - write', () => __awaiter(this, void 0, void 0, function* () {
|
|
1083
|
+
var _a;
|
|
1084
|
+
// scenario:
|
|
1085
|
+
// 1. Bob has the message protocol installed
|
|
1086
|
+
// 2. Alice creates two delegated grants for device X to write as Alice
|
|
1087
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
|
|
1088
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1089
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1090
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1091
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
1092
|
+
// 1. Bob has the message protocol installed
|
|
1093
|
+
const protocolDefinition = messageProtocolDefinition;
|
|
1094
|
+
const protocol = protocolDefinition.protocol;
|
|
1095
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
1096
|
+
author: bob,
|
|
1097
|
+
protocolDefinition
|
|
1098
|
+
});
|
|
1099
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1100
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
1101
|
+
// 2. Alice creates two delegated grants for device X to write as Alice
|
|
1102
|
+
const scope = {
|
|
1103
|
+
interface: DwnInterfaceName.Records,
|
|
1104
|
+
method: DwnMethodName.Write,
|
|
1105
|
+
protocol
|
|
1106
|
+
};
|
|
1107
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
1108
|
+
delegated: true,
|
|
1109
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1110
|
+
grantedTo: deviceX.did,
|
|
1111
|
+
scope: scope,
|
|
1112
|
+
signer: Jws.createSigner(alice)
|
|
1113
|
+
});
|
|
1114
|
+
yield Time.minimalSleep();
|
|
1115
|
+
const deviceXGrant2 = yield PermissionsProtocol.createGrant({
|
|
1116
|
+
delegated: true,
|
|
1117
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1118
|
+
grantedTo: deviceX.did,
|
|
1119
|
+
scope: scope,
|
|
1120
|
+
signer: Jws.createSigner(alice)
|
|
1121
|
+
});
|
|
1122
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
|
|
1123
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1124
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1125
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
1126
|
+
signer: Jws.createSigner(deviceX),
|
|
1127
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
1128
|
+
protocol,
|
|
1129
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
1130
|
+
schema: protocolDefinition.types.message.schema,
|
|
1131
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1132
|
+
data: deviceXData
|
|
1133
|
+
});
|
|
1134
|
+
messageByDeviceX.message.authorization.authorDelegatedGrant = deviceXGrant2.dataEncodedMessage; // intentionally have a mismatching grant
|
|
1135
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1136
|
+
expect(deviceXWriteReply.status.code).to.equal(400);
|
|
1137
|
+
expect(deviceXWriteReply.status.detail).to.contain(DwnErrorCode.RecordsAuthorDelegatedGrantCidMismatch);
|
|
1138
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1139
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
1140
|
+
author: bob,
|
|
1141
|
+
filter: { protocol }
|
|
1142
|
+
});
|
|
1143
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1144
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
1145
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(0);
|
|
1146
|
+
}));
|
|
1147
|
+
it('should fail if author-delegated grant is revoked - write', () => __awaiter(this, void 0, void 0, function* () {
|
|
1148
|
+
var _a;
|
|
1149
|
+
// scenario:
|
|
1150
|
+
// 1. Bob has the message protocol installed
|
|
1151
|
+
// 2. Alice creates a delegated grant for device X to write as Alice
|
|
1152
|
+
// 3. Alice revokes the grant
|
|
1153
|
+
// 4. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a revoked delegated grant
|
|
1154
|
+
// 5. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1155
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1156
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1157
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
1158
|
+
// 1. Bob has the message protocol installed
|
|
1159
|
+
const protocolDefinition = messageProtocolDefinition;
|
|
1160
|
+
const protocol = protocolDefinition.protocol;
|
|
1161
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
1162
|
+
author: bob,
|
|
1163
|
+
protocolDefinition
|
|
1164
|
+
});
|
|
1165
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1166
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
1167
|
+
// 2. Alice creates a delegated grant for device X to write as Alice
|
|
1168
|
+
const scope = {
|
|
1169
|
+
interface: DwnInterfaceName.Records,
|
|
1170
|
+
method: DwnMethodName.Write,
|
|
1171
|
+
protocol
|
|
1172
|
+
};
|
|
1173
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
1174
|
+
delegated: true,
|
|
1175
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1176
|
+
grantedTo: deviceX.did,
|
|
1177
|
+
scope: scope,
|
|
1178
|
+
signer: Jws.createSigner(alice)
|
|
1179
|
+
});
|
|
1180
|
+
const deviceXGrantDataStream = DataStream.fromBytes(deviceXGrant.permissionGrantBytes);
|
|
1181
|
+
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, deviceXGrant.recordsWrite.message, { dataStream: deviceXGrantDataStream });
|
|
1182
|
+
expect(permissionGrantWriteReply.status.code).to.equal(202);
|
|
1183
|
+
// 3. Alice revokes the grant
|
|
1184
|
+
const permissionRevoke = yield PermissionsProtocol.createRevocation({
|
|
1185
|
+
signer: Jws.createSigner(alice),
|
|
1186
|
+
grant: yield PermissionGrant.parse(deviceXGrant.dataEncodedMessage),
|
|
1187
|
+
});
|
|
1188
|
+
const revocationDataStream = DataStream.fromBytes(permissionRevoke.permissionRevocationBytes);
|
|
1189
|
+
const permissionRevokeReply = yield dwn.processMessage(alice.did, permissionRevoke.recordsWrite.message, { dataStream: revocationDataStream });
|
|
1190
|
+
expect(permissionRevokeReply.status.code).to.equal(202);
|
|
1191
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
|
|
1192
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1193
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1194
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
1195
|
+
signer: Jws.createSigner(deviceX),
|
|
1196
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
1197
|
+
protocol,
|
|
1198
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
1199
|
+
schema: protocolDefinition.types.message.schema,
|
|
1200
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1201
|
+
data: deviceXData
|
|
1202
|
+
});
|
|
1203
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1204
|
+
expect(deviceXWriteReply.status.code).to.equal(401);
|
|
1205
|
+
expect(deviceXWriteReply.status.detail).to.contain(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
1206
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1207
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
1208
|
+
author: bob,
|
|
1209
|
+
filter: { protocol }
|
|
1210
|
+
});
|
|
1211
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1212
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
1213
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(0);
|
|
1214
|
+
}));
|
|
1215
|
+
it('should fail if author-delegated grant is expired - write', () => __awaiter(this, void 0, void 0, function* () {
|
|
1216
|
+
var _a;
|
|
1217
|
+
// scenario:
|
|
1218
|
+
// 1. Bob has the message protocol installed
|
|
1219
|
+
// 2. Alice creates a delegated grant for device X to write as Alice, but make it expired
|
|
1220
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using an expired delegated grant
|
|
1221
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1222
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1223
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1224
|
+
const deviceX = yield TestDataGenerator.generateDidKeyPersona();
|
|
1225
|
+
// 1. Bob has the message protocol installed
|
|
1226
|
+
const protocolDefinition = messageProtocolDefinition;
|
|
1227
|
+
const protocol = protocolDefinition.protocol;
|
|
1228
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
1229
|
+
author: bob,
|
|
1230
|
+
protocolDefinition
|
|
1231
|
+
});
|
|
1232
|
+
const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1233
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
1234
|
+
// 2. Alice creates a delegated grant for device X to write as Alice, but make it expired
|
|
1235
|
+
const scope = {
|
|
1236
|
+
interface: DwnInterfaceName.Records,
|
|
1237
|
+
method: DwnMethodName.Write,
|
|
1238
|
+
protocol
|
|
1239
|
+
};
|
|
1240
|
+
const deviceXGrant = yield PermissionsProtocol.createGrant({
|
|
1241
|
+
delegated: true,
|
|
1242
|
+
dateExpires: Time.getCurrentTimestamp(), // intentionally set to current time to make it expired immediately
|
|
1243
|
+
grantedTo: deviceX.did,
|
|
1244
|
+
scope: scope,
|
|
1245
|
+
signer: Jws.createSigner(alice)
|
|
1246
|
+
});
|
|
1247
|
+
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using an expired delegated grant
|
|
1248
|
+
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1249
|
+
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1250
|
+
const messageByDeviceX = yield RecordsWrite.create({
|
|
1251
|
+
signer: Jws.createSigner(deviceX),
|
|
1252
|
+
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
1253
|
+
protocol,
|
|
1254
|
+
protocolPath: 'message', // this comes from `types` in protocol definition
|
|
1255
|
+
schema: protocolDefinition.types.message.schema,
|
|
1256
|
+
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1257
|
+
data: deviceXData
|
|
1258
|
+
});
|
|
1259
|
+
const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1260
|
+
expect(deviceXWriteReply.status.code).to.equal(401);
|
|
1261
|
+
expect(deviceXWriteReply.status.detail).to.contain(DwnErrorCode.GrantAuthorizationGrantExpired);
|
|
1262
|
+
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1263
|
+
const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
1264
|
+
author: bob,
|
|
1265
|
+
filter: { protocol }
|
|
1266
|
+
});
|
|
1267
|
+
const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1268
|
+
expect(bobRecordsQueryReply.status.code).to.equal(200);
|
|
1269
|
+
expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(0);
|
|
1270
|
+
}));
|
|
1271
|
+
}));
|
|
1272
|
+
}
|
|
1273
|
+
//# sourceMappingURL=author-delegated-grant.spec.js.map
|