@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,815 @@
|
|
|
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 sinon from 'sinon';
|
|
12
|
+
import chai, { expect } from 'chai';
|
|
13
|
+
import { DataStream } from '../../src/utils/data-stream.js';
|
|
14
|
+
import { Dwn } from '../../src/dwn.js';
|
|
15
|
+
import { Jws } from '../../src/utils/jws.js';
|
|
16
|
+
import { PermissionGrant } from '../../src/protocols/permission-grant.js';
|
|
17
|
+
import { PermissionsProtocol } from '../../src/protocols/permissions.js';
|
|
18
|
+
import { RecordsRead } from '../../src/interfaces/records-read.js';
|
|
19
|
+
import { RecordsWrite } from '../../src/interfaces/records-write.js';
|
|
20
|
+
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
21
|
+
import { TestEventStream } from '../test-event-stream.js';
|
|
22
|
+
import { TestStores } from '../test-stores.js';
|
|
23
|
+
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
24
|
+
import { DwnErrorCode, DwnInterfaceName, DwnMethodName, Encoder, RecordsQuery, Time } from '../../src/index.js';
|
|
25
|
+
chai.use(chaiAsPromised);
|
|
26
|
+
export function testPermissions() {
|
|
27
|
+
describe('permissions', () => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
let didResolver;
|
|
29
|
+
let messageStore;
|
|
30
|
+
let dataStore;
|
|
31
|
+
let resumableTaskStore;
|
|
32
|
+
let eventLog;
|
|
33
|
+
let eventStream;
|
|
34
|
+
let dwn;
|
|
35
|
+
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
36
|
+
// so that different test suites can reuse the same backend store for testing
|
|
37
|
+
before(() => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
39
|
+
const stores = TestStores.get();
|
|
40
|
+
messageStore = stores.messageStore;
|
|
41
|
+
dataStore = stores.dataStore;
|
|
42
|
+
resumableTaskStore = stores.resumableTaskStore;
|
|
43
|
+
eventLog = stores.eventLog;
|
|
44
|
+
eventStream = TestEventStream.get();
|
|
45
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, eventLog, eventStream, resumableTaskStore });
|
|
46
|
+
}));
|
|
47
|
+
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
49
|
+
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
50
|
+
yield messageStore.clear();
|
|
51
|
+
yield dataStore.clear();
|
|
52
|
+
yield resumableTaskStore.clear();
|
|
53
|
+
yield eventLog.clear();
|
|
54
|
+
}));
|
|
55
|
+
after(() => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
sinon.restore();
|
|
57
|
+
yield dwn.close();
|
|
58
|
+
}));
|
|
59
|
+
it('should include record tags using the createRequest, createGrant and createRevocation if provided', () => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
61
|
+
const testProtocol = 'https://example.com/protocol/test';
|
|
62
|
+
// createRequest with a protocol
|
|
63
|
+
const requestWrite = yield PermissionsProtocol.createRequest({
|
|
64
|
+
signer: Jws.createSigner(alice),
|
|
65
|
+
description: 'Requesting to write',
|
|
66
|
+
delegated: false,
|
|
67
|
+
scope: {
|
|
68
|
+
interface: DwnInterfaceName.Records,
|
|
69
|
+
method: DwnMethodName.Write,
|
|
70
|
+
protocol: testProtocol,
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
expect(requestWrite.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: testProtocol });
|
|
74
|
+
// createGrant with a protocol
|
|
75
|
+
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
76
|
+
signer: Jws.createSigner(alice),
|
|
77
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
78
|
+
description: 'Allow Bob to write',
|
|
79
|
+
grantedTo: alice.did,
|
|
80
|
+
scope: {
|
|
81
|
+
interface: DwnInterfaceName.Records,
|
|
82
|
+
method: DwnMethodName.Write,
|
|
83
|
+
protocol: testProtocol,
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
expect(grantWrite.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: testProtocol });
|
|
87
|
+
// createRevocation with a protocol derived from the grant
|
|
88
|
+
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
89
|
+
signer: Jws.createSigner(alice),
|
|
90
|
+
grant: yield PermissionGrant.parse(grantWrite.dataEncodedMessage),
|
|
91
|
+
dateRevoked: Time.getCurrentTimestamp()
|
|
92
|
+
});
|
|
93
|
+
expect(revokeWrite.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: testProtocol });
|
|
94
|
+
}));
|
|
95
|
+
it('should normalize the protocol URL in the scope of a Request, Grant, and Revocation', () => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
97
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
98
|
+
// createRequest with a protocol that will be normalized to `http://any-protocol`
|
|
99
|
+
const requestWrite = yield PermissionsProtocol.createRequest({
|
|
100
|
+
signer: Jws.createSigner(bob),
|
|
101
|
+
description: 'Requesting to write',
|
|
102
|
+
delegated: false,
|
|
103
|
+
scope: {
|
|
104
|
+
interface: DwnInterfaceName.Records,
|
|
105
|
+
method: DwnMethodName.Write,
|
|
106
|
+
protocol: 'any-protocol' // URL will normalize to `http://any-protocol`
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
expect(requestWrite.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: 'http://any-protocol' });
|
|
110
|
+
// createRequest with a protocol that is already normalized to `https://any-protocol`
|
|
111
|
+
const requestWrite2 = yield PermissionsProtocol.createRequest({
|
|
112
|
+
signer: Jws.createSigner(bob),
|
|
113
|
+
description: 'Requesting to write',
|
|
114
|
+
delegated: false,
|
|
115
|
+
scope: {
|
|
116
|
+
interface: DwnInterfaceName.Records,
|
|
117
|
+
method: DwnMethodName.Write,
|
|
118
|
+
protocol: 'https://any-protocol'
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
expect(requestWrite2.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: 'https://any-protocol' });
|
|
122
|
+
// createGrant with a protocol that will be normalized to `http://any-protocol`
|
|
123
|
+
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
124
|
+
signer: Jws.createSigner(alice),
|
|
125
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
126
|
+
description: 'Allow Bob to write',
|
|
127
|
+
grantedTo: bob.did,
|
|
128
|
+
scope: {
|
|
129
|
+
interface: DwnInterfaceName.Records,
|
|
130
|
+
method: DwnMethodName.Write,
|
|
131
|
+
protocol: 'any-protocol' // URL will normalize to `http://any-protocol`
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
expect(grantWrite.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: 'http://any-protocol' });
|
|
135
|
+
// createGrant with a protocol that is already normalized to `https://any-protocol`
|
|
136
|
+
const grantWrite2 = yield PermissionsProtocol.createGrant({
|
|
137
|
+
signer: Jws.createSigner(alice),
|
|
138
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
139
|
+
description: 'Allow Bob to write',
|
|
140
|
+
grantedTo: bob.did,
|
|
141
|
+
scope: {
|
|
142
|
+
interface: DwnInterfaceName.Records,
|
|
143
|
+
method: DwnMethodName.Write,
|
|
144
|
+
protocol: 'https://any-protocol'
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
expect(grantWrite2.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: 'https://any-protocol' });
|
|
148
|
+
}));
|
|
149
|
+
it('should derive the grantId and protocol from the grant record when creating a revocation', () => __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
151
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
152
|
+
const grantProtocol = 'https://example.com/protocol/test';
|
|
153
|
+
// alice creates a grant for bob
|
|
154
|
+
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
155
|
+
signer: Jws.createSigner(alice),
|
|
156
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
157
|
+
description: 'Allow Bob to write',
|
|
158
|
+
grantedTo: bob.did,
|
|
159
|
+
scope: {
|
|
160
|
+
interface: DwnInterfaceName.Records,
|
|
161
|
+
method: DwnMethodName.Write,
|
|
162
|
+
protocol: grantProtocol,
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const grantWriteReply = yield dwn.processMessage(alice.did, grantWrite.recordsWrite.message, {
|
|
166
|
+
dataStream: DataStream.fromBytes(grantWrite.permissionGrantBytes)
|
|
167
|
+
});
|
|
168
|
+
expect(grantWriteReply.status.code).to.equal(202);
|
|
169
|
+
// derive the grantId and protocol from the grant record
|
|
170
|
+
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
171
|
+
signer: Jws.createSigner(alice),
|
|
172
|
+
grant: yield PermissionGrant.parse(grantWrite.dataEncodedMessage),
|
|
173
|
+
dateRevoked: Time.getCurrentTimestamp()
|
|
174
|
+
});
|
|
175
|
+
// check that the protocol is in the revocation record's tags
|
|
176
|
+
expect(revokeWrite.recordsWrite.message.descriptor.tags).to.deep.equal({ protocol: grantProtocol });
|
|
177
|
+
// check that the revocation's parentId is the grant's recordId
|
|
178
|
+
expect(revokeWrite.recordsWrite.message.descriptor.parentId).to.equal(grantWrite.recordsWrite.message.recordId);
|
|
179
|
+
}));
|
|
180
|
+
it('should support permission management through use of Request, Grants, and Revocations', () => __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
// scenario:
|
|
182
|
+
// 1. Verify anyone (Bob) can send a permission request to Alice
|
|
183
|
+
// 2. Alice queries her DWN for new permission requests
|
|
184
|
+
// 3. Verify a non-owner cannot create a grant for Bob in Alice's DWN
|
|
185
|
+
// 4. Alice creates a permission grant for Bob in her DWN
|
|
186
|
+
// 5. Verify that Bob can query the permission grant from Alice's DWN (even though Alice can also send it directly to Bob)
|
|
187
|
+
// 6. Verify that any third-party can fetch revocation of the grant and find it is still active (not revoked)
|
|
188
|
+
// 7. Verify that non-owner cannot revoke the grant
|
|
189
|
+
// 8. Alice revokes the permission grant for Bob
|
|
190
|
+
// 9. Verify that any third-party can fetch the revocation status of the permission grant
|
|
191
|
+
var _a, _b, _c, _d, _e;
|
|
192
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
193
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
194
|
+
// 1. Verify anyone (Bob) can send a permission request to Alice
|
|
195
|
+
const permissionScope = {
|
|
196
|
+
interface: DwnInterfaceName.Records,
|
|
197
|
+
method: DwnMethodName.Write,
|
|
198
|
+
protocol: `any-protocol`
|
|
199
|
+
};
|
|
200
|
+
const requestToAlice = yield PermissionsProtocol.createRequest({
|
|
201
|
+
signer: Jws.createSigner(bob),
|
|
202
|
+
description: `Requesting to write to Alice's DWN`,
|
|
203
|
+
delegated: false,
|
|
204
|
+
scope: permissionScope
|
|
205
|
+
});
|
|
206
|
+
const requestWriteReply = yield dwn.processMessage(alice.did, requestToAlice.recordsWrite.message, { dataStream: DataStream.fromBytes(requestToAlice.permissionRequestBytes) });
|
|
207
|
+
expect(requestWriteReply.status.code).to.equal(202);
|
|
208
|
+
// 2. Alice queries her DWN for new permission requests
|
|
209
|
+
const requestQuery = yield RecordsQuery.create({
|
|
210
|
+
signer: Jws.createSigner(alice),
|
|
211
|
+
filter: {
|
|
212
|
+
protocolPath: PermissionsProtocol.requestPath,
|
|
213
|
+
protocol: PermissionsProtocol.uri,
|
|
214
|
+
dateUpdated: { from: Time.createOffsetTimestamp({ seconds: -1 * 60 * 60 * 24 }) } // last 24 hours
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
const requestQueryReply = yield dwn.processMessage(alice.did, requestQuery.message);
|
|
218
|
+
const requestFromBob = (_a = requestQueryReply.entries) === null || _a === void 0 ? void 0 : _a[0];
|
|
219
|
+
expect(requestQueryReply.status.code).to.equal(200);
|
|
220
|
+
expect((_b = requestQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
221
|
+
expect(requestFromBob.recordId).to.equal(requestToAlice.recordsWrite.message.recordId);
|
|
222
|
+
// 3. Verify a non-owner cannot create a grant for Bob in Alice's DWN
|
|
223
|
+
const decodedRequest = PermissionsProtocol.parseRequest(requestFromBob.encodedData);
|
|
224
|
+
const unauthorizedGrantWrite = yield PermissionsProtocol.createGrant({
|
|
225
|
+
signer: Jws.createSigner(bob),
|
|
226
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
227
|
+
description: 'Allow Bob to write',
|
|
228
|
+
grantedTo: bob.did,
|
|
229
|
+
scope: decodedRequest.scope
|
|
230
|
+
});
|
|
231
|
+
const unauthorizedGrantWriteReply = yield dwn.processMessage(alice.did, unauthorizedGrantWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(unauthorizedGrantWrite.permissionGrantBytes) });
|
|
232
|
+
expect(unauthorizedGrantWriteReply.status.code).to.equal(401);
|
|
233
|
+
expect(unauthorizedGrantWriteReply.status.detail).to.contain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
234
|
+
// 4. Alice creates a permission grant for Bob in her DWN
|
|
235
|
+
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
236
|
+
signer: Jws.createSigner(alice),
|
|
237
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
238
|
+
description: 'Allow Bob to write',
|
|
239
|
+
grantedTo: bob.did,
|
|
240
|
+
scope: decodedRequest.scope
|
|
241
|
+
});
|
|
242
|
+
const grantWriteReply = yield dwn.processMessage(alice.did, grantWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(grantWrite.permissionGrantBytes) });
|
|
243
|
+
expect(grantWriteReply.status.code).to.equal(202);
|
|
244
|
+
// 5. Verify that Bob can query the permission grant from Alice's DWN (even though Alice can also send it directly to Bob)
|
|
245
|
+
const grantQuery = yield RecordsQuery.create({
|
|
246
|
+
signer: Jws.createSigner(bob),
|
|
247
|
+
filter: {
|
|
248
|
+
protocolPath: PermissionsProtocol.grantPath,
|
|
249
|
+
protocol: PermissionsProtocol.uri,
|
|
250
|
+
dateUpdated: { from: Time.createOffsetTimestamp({ seconds: -1 * 60 * 60 * 24 }) } // last 24 hours
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const grantQueryReply = yield dwn.processMessage(alice.did, grantQuery.message);
|
|
254
|
+
const grantFromBob = (_c = grantQueryReply.entries) === null || _c === void 0 ? void 0 : _c[0];
|
|
255
|
+
expect(grantQueryReply.status.code).to.equal(200);
|
|
256
|
+
expect((_d = grantQueryReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(1);
|
|
257
|
+
expect(grantFromBob.recordId).to.equal(grantWrite.recordsWrite.message.recordId);
|
|
258
|
+
// 6. Verify that any third-party can fetch revocation of the grant and find it is still active (not revoked)
|
|
259
|
+
const revocationRead = yield RecordsRead.create({
|
|
260
|
+
signer: Jws.createSigner(bob),
|
|
261
|
+
filter: {
|
|
262
|
+
contextId: grantWrite.recordsWrite.message.contextId,
|
|
263
|
+
protocolPath: PermissionsProtocol.revocationPath
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
const revocationReadReply = yield dwn.processMessage(alice.did, revocationRead.message);
|
|
267
|
+
expect(revocationReadReply.status.code).to.equal(404);
|
|
268
|
+
// 7. Verify that non-owner cannot revoke the grant
|
|
269
|
+
const unauthorizedRevokeWrite = yield PermissionsProtocol.createRevocation({
|
|
270
|
+
signer: Jws.createSigner(bob),
|
|
271
|
+
grant: yield PermissionGrant.parse(grantWrite.dataEncodedMessage),
|
|
272
|
+
dateRevoked: Time.getCurrentTimestamp(),
|
|
273
|
+
});
|
|
274
|
+
const unauthorizedRevokeWriteReply = yield dwn.processMessage(alice.did, unauthorizedRevokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(unauthorizedRevokeWrite.permissionRevocationBytes) });
|
|
275
|
+
expect(unauthorizedRevokeWriteReply.status.code).to.equal(401);
|
|
276
|
+
expect(unauthorizedGrantWriteReply.status.detail).to.contain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
277
|
+
// 8. Alice revokes the permission grant for Bob
|
|
278
|
+
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
279
|
+
signer: Jws.createSigner(alice),
|
|
280
|
+
grant: yield PermissionGrant.parse(grantWrite.dataEncodedMessage),
|
|
281
|
+
dateRevoked: Time.getCurrentTimestamp(),
|
|
282
|
+
});
|
|
283
|
+
const revokeWriteReply = yield dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
|
|
284
|
+
expect(revokeWriteReply.status.code).to.equal(202);
|
|
285
|
+
// 9. Verify that any third-party can fetch the revocation status of the permission grant
|
|
286
|
+
const revocationReadReply2 = yield dwn.processMessage(alice.did, revocationRead.message);
|
|
287
|
+
expect(revocationReadReply2.status.code).to.equal(200);
|
|
288
|
+
expect((_e = revocationReadReply2.entry.recordsWrite) === null || _e === void 0 ? void 0 : _e.recordId).to.equal(revokeWrite.recordsWrite.message.recordId);
|
|
289
|
+
}));
|
|
290
|
+
it('should fail if a RecordsPermissionScope in a Request or Grant record is created without a protocol', () => __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
292
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
293
|
+
const permissionScope = {
|
|
294
|
+
interface: DwnInterfaceName.Records,
|
|
295
|
+
method: DwnMethodName.Write
|
|
296
|
+
};
|
|
297
|
+
const requestWrite = PermissionsProtocol.createRequest({
|
|
298
|
+
signer: Jws.createSigner(bob),
|
|
299
|
+
description: `Requesting to write to Alice's DWN`,
|
|
300
|
+
delegated: false,
|
|
301
|
+
scope: permissionScope // explicity as any to test the validation
|
|
302
|
+
});
|
|
303
|
+
yield expect(requestWrite).to.eventually.be.rejectedWith(DwnErrorCode.PermissionsProtocolCreateRequestRecordsScopeMissingProtocol);
|
|
304
|
+
const grantWrite = PermissionsProtocol.createGrant({
|
|
305
|
+
signer: Jws.createSigner(alice),
|
|
306
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
307
|
+
description: 'Allow Bob to write',
|
|
308
|
+
grantedTo: bob.did,
|
|
309
|
+
scope: permissionScope // explicity as any to test the validation
|
|
310
|
+
});
|
|
311
|
+
yield expect(grantWrite).to.eventually.be.rejectedWith(DwnErrorCode.PermissionsProtocolCreateGrantRecordsScopeMissingProtocol);
|
|
312
|
+
}));
|
|
313
|
+
it('should fail if an invalid protocolPath is used during Permissions schema validation', () => __awaiter(this, void 0, void 0, function* () {
|
|
314
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
315
|
+
const { message, dataBytes } = yield TestDataGenerator.generateRecordsWrite({
|
|
316
|
+
author: alice,
|
|
317
|
+
protocol: PermissionsProtocol.uri,
|
|
318
|
+
protocolPath: 'invalid/path',
|
|
319
|
+
data: Encoder.stringToBytes(JSON.stringify({}))
|
|
320
|
+
});
|
|
321
|
+
expect(() => PermissionsProtocol.validateSchema(message, dataBytes)).to.throw(DwnErrorCode.PermissionsProtocolValidateSchemaUnexpectedRecord);
|
|
322
|
+
}));
|
|
323
|
+
it('performs additional validation to the tagged protocol in a Revocation message ensuring it matches the Grant it is revoking', () => __awaiter(this, void 0, void 0, function* () {
|
|
324
|
+
// scenario:
|
|
325
|
+
// Alice creates a grant scoped to a protocol.
|
|
326
|
+
// Alice then tries to revoke the grant without a protocol set, it should fail.
|
|
327
|
+
// Alice then tries to revoke the grant with an invalid protocol, it should fail.
|
|
328
|
+
// Alice finally tries to revoke the grant with a valid protocol, it should succeed.
|
|
329
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
330
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
331
|
+
const grantProtocol = 'https://example.com/protocol/test';
|
|
332
|
+
const invalidProtocol = 'https://example.com/protocol/invalid';
|
|
333
|
+
// alice creates a grant for bob
|
|
334
|
+
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
335
|
+
signer: Jws.createSigner(alice),
|
|
336
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
337
|
+
description: 'Allow Bob to write',
|
|
338
|
+
grantedTo: bob.did,
|
|
339
|
+
scope: {
|
|
340
|
+
interface: DwnInterfaceName.Records,
|
|
341
|
+
method: DwnMethodName.Write,
|
|
342
|
+
protocol: grantProtocol,
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
const grantWriteReply = yield dwn.processMessage(alice.did, grantWrite.recordsWrite.message, {
|
|
346
|
+
dataStream: DataStream.fromBytes(grantWrite.permissionGrantBytes)
|
|
347
|
+
});
|
|
348
|
+
expect(grantWriteReply.status.code).to.equal(202);
|
|
349
|
+
// attempt to revoke the grant without a protocol set
|
|
350
|
+
const permissionRevocationBytes = Encoder.objectToBytes({ description: 'Revoking the grant' });
|
|
351
|
+
const revokeWithoutProtocolRecordsWrite = yield RecordsWrite.create({
|
|
352
|
+
signer: Jws.createSigner(alice),
|
|
353
|
+
parentContextId: grantWrite.dataEncodedMessage.recordId,
|
|
354
|
+
protocol: PermissionsProtocol.uri,
|
|
355
|
+
protocolPath: PermissionsProtocol.revocationPath,
|
|
356
|
+
dataFormat: 'application/json',
|
|
357
|
+
data: permissionRevocationBytes,
|
|
358
|
+
});
|
|
359
|
+
const revokeWriteWithoutProtocolReply = yield dwn.processMessage(alice.did, revokeWithoutProtocolRecordsWrite.message, {
|
|
360
|
+
dataStream: DataStream.fromBytes(permissionRevocationBytes)
|
|
361
|
+
});
|
|
362
|
+
expect(revokeWriteWithoutProtocolReply.status.code).to.equal(400);
|
|
363
|
+
expect(revokeWriteWithoutProtocolReply.status.detail).to.contain(DwnErrorCode.PermissionsProtocolValidateRevocationProtocolTagMismatch);
|
|
364
|
+
expect(revokeWriteWithoutProtocolReply.status.detail).to.contain(`Revocation protocol undefined does not match grant protocol ${grantProtocol}`);
|
|
365
|
+
// revoke the grant with an invalid protocol
|
|
366
|
+
const revokeWriteWithMissMatchedProtocol = yield RecordsWrite.create({
|
|
367
|
+
signer: Jws.createSigner(alice),
|
|
368
|
+
parentContextId: grantWrite.dataEncodedMessage.recordId,
|
|
369
|
+
protocol: PermissionsProtocol.uri,
|
|
370
|
+
protocolPath: PermissionsProtocol.revocationPath,
|
|
371
|
+
dataFormat: 'application/json',
|
|
372
|
+
data: permissionRevocationBytes,
|
|
373
|
+
tags: { protocol: invalidProtocol }
|
|
374
|
+
});
|
|
375
|
+
const revokeWriteWithMissMatchedProtocolReply = yield dwn.processMessage(alice.did, revokeWriteWithMissMatchedProtocol.message, {
|
|
376
|
+
dataStream: DataStream.fromBytes(permissionRevocationBytes)
|
|
377
|
+
});
|
|
378
|
+
expect(revokeWriteWithMissMatchedProtocolReply.status.code).to.equal(400);
|
|
379
|
+
expect(revokeWriteWithMissMatchedProtocolReply.status.detail).to.contain(DwnErrorCode.PermissionsProtocolValidateRevocationProtocolTagMismatch);
|
|
380
|
+
expect(revokeWriteWithMissMatchedProtocolReply.status.detail).to.contain(`Revocation protocol ${invalidProtocol} does not match grant protocol ${grantProtocol}`);
|
|
381
|
+
// revoke the grant with a valid protocol
|
|
382
|
+
const revokeWrite = yield RecordsWrite.create({
|
|
383
|
+
signer: Jws.createSigner(alice),
|
|
384
|
+
parentContextId: grantWrite.dataEncodedMessage.recordId,
|
|
385
|
+
protocol: PermissionsProtocol.uri,
|
|
386
|
+
protocolPath: PermissionsProtocol.revocationPath,
|
|
387
|
+
dataFormat: 'application/json',
|
|
388
|
+
data: permissionRevocationBytes,
|
|
389
|
+
tags: { protocol: grantProtocol }
|
|
390
|
+
});
|
|
391
|
+
const revokeWriteReply = yield dwn.processMessage(alice.did, revokeWrite.message, {
|
|
392
|
+
dataStream: DataStream.fromBytes(permissionRevocationBytes)
|
|
393
|
+
});
|
|
394
|
+
expect(revokeWriteReply.status.code).to.equal(202);
|
|
395
|
+
}));
|
|
396
|
+
// These set of tets are primarily to ensure SchemaValidation passes for the various permission request and grant messages and their scopes
|
|
397
|
+
describe('ensure loaded scope properties for permission requests are processed', () => {
|
|
398
|
+
it('MessagesQuery', () => __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
400
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
401
|
+
// create a permission grant with protocol
|
|
402
|
+
const messagesQueryPermissions = yield PermissionsProtocol.createGrant({
|
|
403
|
+
signer: Jws.createSigner(alice),
|
|
404
|
+
grantedTo: bob.did,
|
|
405
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
406
|
+
description: 'Requesting to query from Alice test-context',
|
|
407
|
+
scope: {
|
|
408
|
+
interface: DwnInterfaceName.Messages,
|
|
409
|
+
method: DwnMethodName.Query,
|
|
410
|
+
protocol: 'https://example.com/protocol/test',
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
const messagesQueryPermissionsReply = yield dwn.processMessage(alice.did, messagesQueryPermissions.recordsWrite.message, {
|
|
414
|
+
dataStream: DataStream.fromBytes(messagesQueryPermissions.permissionGrantBytes)
|
|
415
|
+
});
|
|
416
|
+
expect(messagesQueryPermissionsReply.status.code).to.equal(202);
|
|
417
|
+
}));
|
|
418
|
+
it('MessagesRead', () => __awaiter(this, void 0, void 0, function* () {
|
|
419
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
420
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
421
|
+
// create a permission grant with protocol
|
|
422
|
+
const messagesReadPermissions = yield PermissionsProtocol.createGrant({
|
|
423
|
+
signer: Jws.createSigner(alice),
|
|
424
|
+
grantedTo: bob.did,
|
|
425
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
426
|
+
description: 'Requesting to read from Alice test-context',
|
|
427
|
+
scope: {
|
|
428
|
+
interface: DwnInterfaceName.Messages,
|
|
429
|
+
method: DwnMethodName.Read,
|
|
430
|
+
protocol: 'https://example.com/protocol/test',
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
const messagesReadPermissionsReply = yield dwn.processMessage(alice.did, messagesReadPermissions.recordsWrite.message, {
|
|
434
|
+
dataStream: DataStream.fromBytes(messagesReadPermissions.permissionGrantBytes)
|
|
435
|
+
});
|
|
436
|
+
expect(messagesReadPermissionsReply.status.code).to.equal(202);
|
|
437
|
+
}));
|
|
438
|
+
it('MessagesSubscribe', () => __awaiter(this, void 0, void 0, function* () {
|
|
439
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
440
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
441
|
+
// create a permission grant with protocol
|
|
442
|
+
const messagesSubscribePermissions = yield PermissionsProtocol.createGrant({
|
|
443
|
+
signer: Jws.createSigner(alice),
|
|
444
|
+
grantedTo: bob.did,
|
|
445
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
446
|
+
description: 'Requesting to subscribe from Alice test-context',
|
|
447
|
+
scope: {
|
|
448
|
+
interface: DwnInterfaceName.Messages,
|
|
449
|
+
method: DwnMethodName.Subscribe,
|
|
450
|
+
protocol: 'https://example.com/protocol/test',
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
const messagesSubscribePermissionsReply = yield dwn.processMessage(alice.did, messagesSubscribePermissions.recordsWrite.message, {
|
|
454
|
+
dataStream: DataStream.fromBytes(messagesSubscribePermissions.permissionGrantBytes)
|
|
455
|
+
});
|
|
456
|
+
expect(messagesSubscribePermissionsReply.status.code).to.equal(202);
|
|
457
|
+
}));
|
|
458
|
+
it('RecordsDelete', () => __awaiter(this, void 0, void 0, function* () {
|
|
459
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
460
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
461
|
+
// create a permission grant with protocol and contextId
|
|
462
|
+
const withContextId = yield PermissionsProtocol.createGrant({
|
|
463
|
+
signer: Jws.createSigner(alice),
|
|
464
|
+
grantedTo: bob.did,
|
|
465
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
466
|
+
description: 'Requesting to delete from Alice test-context',
|
|
467
|
+
scope: {
|
|
468
|
+
interface: DwnInterfaceName.Records,
|
|
469
|
+
method: DwnMethodName.Delete,
|
|
470
|
+
protocol: 'https://example.com/protocol/test',
|
|
471
|
+
contextId: 'test-context'
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
475
|
+
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
476
|
+
});
|
|
477
|
+
expect(withContextIdReply.status.code).to.equal(202);
|
|
478
|
+
// create a permission request with protocol and protocolPath
|
|
479
|
+
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
480
|
+
signer: Jws.createSigner(alice),
|
|
481
|
+
grantedTo: bob.did,
|
|
482
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
483
|
+
description: 'Requesting to delete from Alice foo/bar',
|
|
484
|
+
scope: {
|
|
485
|
+
interface: DwnInterfaceName.Records,
|
|
486
|
+
method: DwnMethodName.Delete,
|
|
487
|
+
protocol: 'https://example.com/protocol/test',
|
|
488
|
+
protocolPath: 'foo/bar'
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
492
|
+
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
493
|
+
});
|
|
494
|
+
expect(withProtocolPathReply.status.code).to.equal(202);
|
|
495
|
+
}));
|
|
496
|
+
it('RecordsQuery', () => __awaiter(this, void 0, void 0, function* () {
|
|
497
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
498
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
499
|
+
// create a permission grant with protocol and contextId scope
|
|
500
|
+
const withContextId = yield PermissionsProtocol.createGrant({
|
|
501
|
+
signer: Jws.createSigner(alice),
|
|
502
|
+
grantedTo: bob.did,
|
|
503
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
504
|
+
description: 'Requesting to query from Alice test-context',
|
|
505
|
+
delegated: true,
|
|
506
|
+
scope: {
|
|
507
|
+
interface: DwnInterfaceName.Records,
|
|
508
|
+
method: DwnMethodName.Query,
|
|
509
|
+
protocol: 'https://example.com/protocol/test',
|
|
510
|
+
contextId: 'test-context'
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
514
|
+
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
515
|
+
});
|
|
516
|
+
expect(withContextIdReply.status.code).to.equal(202);
|
|
517
|
+
// create a permission request with protocol and protocolPath scope
|
|
518
|
+
const withProtocolPath = yield PermissionsProtocol.createRequest({
|
|
519
|
+
signer: Jws.createSigner(bob),
|
|
520
|
+
description: 'Requesting to query from Alice foo/bar',
|
|
521
|
+
delegated: true,
|
|
522
|
+
scope: {
|
|
523
|
+
interface: DwnInterfaceName.Records,
|
|
524
|
+
method: DwnMethodName.Query,
|
|
525
|
+
protocol: 'https://example.com/protocol/test',
|
|
526
|
+
protocolPath: 'foo/bar'
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
const withProtocolPathReply = yield dwn.processMessage(bob.did, withProtocolPath.recordsWrite.message, {
|
|
530
|
+
dataStream: DataStream.fromBytes(withProtocolPath.permissionRequestBytes)
|
|
531
|
+
});
|
|
532
|
+
expect(withProtocolPathReply.status.code).to.equal(202);
|
|
533
|
+
}));
|
|
534
|
+
it('RecordsRead', () => __awaiter(this, void 0, void 0, function* () {
|
|
535
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
536
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
537
|
+
// create a permission grant with protocol and contextId scope
|
|
538
|
+
const withContextId = yield PermissionsProtocol.createGrant({
|
|
539
|
+
signer: Jws.createSigner(alice),
|
|
540
|
+
grantedTo: bob.did,
|
|
541
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
542
|
+
description: 'Requesting to read to Alice test-context',
|
|
543
|
+
delegated: true,
|
|
544
|
+
scope: {
|
|
545
|
+
interface: DwnInterfaceName.Records,
|
|
546
|
+
method: DwnMethodName.Read,
|
|
547
|
+
protocol: 'https://example.com/protocol/test',
|
|
548
|
+
contextId: 'test-context'
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
552
|
+
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
553
|
+
});
|
|
554
|
+
expect(withContextIdReply.status.code).to.equal(202);
|
|
555
|
+
// create a permission request with protocol and protocolPath scope
|
|
556
|
+
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
557
|
+
signer: Jws.createSigner(alice),
|
|
558
|
+
grantedTo: bob.did,
|
|
559
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
560
|
+
description: 'Requesting to read to Alice foo/bar',
|
|
561
|
+
delegated: true,
|
|
562
|
+
scope: {
|
|
563
|
+
interface: DwnInterfaceName.Records,
|
|
564
|
+
method: DwnMethodName.Read,
|
|
565
|
+
protocol: 'https://example.com/protocol/test',
|
|
566
|
+
protocolPath: 'foo/bar'
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
570
|
+
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
571
|
+
});
|
|
572
|
+
expect(withProtocolPathReply.status.code).to.equal(202);
|
|
573
|
+
}));
|
|
574
|
+
it('RecordsSubscribe', () => __awaiter(this, void 0, void 0, function* () {
|
|
575
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
576
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
577
|
+
// create a permission grant with protocol and contextId scope
|
|
578
|
+
const withContextId = yield PermissionsProtocol.createGrant({
|
|
579
|
+
signer: Jws.createSigner(alice),
|
|
580
|
+
grantedTo: bob.did,
|
|
581
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
582
|
+
description: 'Requesting to subscribe to Alice test-context',
|
|
583
|
+
delegated: true,
|
|
584
|
+
scope: {
|
|
585
|
+
interface: DwnInterfaceName.Records,
|
|
586
|
+
method: DwnMethodName.Subscribe,
|
|
587
|
+
protocol: 'https://example.com/protocol/test',
|
|
588
|
+
contextId: 'test-context'
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
592
|
+
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
593
|
+
});
|
|
594
|
+
expect(withContextIdReply.status.code).to.equal(202);
|
|
595
|
+
// create a permission request with protocol and protocolPath scope
|
|
596
|
+
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
597
|
+
signer: Jws.createSigner(alice),
|
|
598
|
+
grantedTo: bob.did,
|
|
599
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
600
|
+
description: 'Requesting to subscribe to Alice foo/bar',
|
|
601
|
+
delegated: true,
|
|
602
|
+
scope: {
|
|
603
|
+
interface: DwnInterfaceName.Records,
|
|
604
|
+
method: DwnMethodName.Subscribe,
|
|
605
|
+
protocol: 'https://example.com/protocol/test',
|
|
606
|
+
protocolPath: 'foo/bar'
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
610
|
+
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
611
|
+
});
|
|
612
|
+
expect(withProtocolPathReply.status.code).to.equal(202);
|
|
613
|
+
}));
|
|
614
|
+
it('RecordsWrite', () => __awaiter(this, void 0, void 0, function* () {
|
|
615
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
616
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
617
|
+
// create a permission grant with protocol and contextId scope
|
|
618
|
+
const withContextId = yield PermissionsProtocol.createGrant({
|
|
619
|
+
signer: Jws.createSigner(alice),
|
|
620
|
+
grantedTo: bob.did,
|
|
621
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
622
|
+
description: 'Requesting to write to Alice test-context',
|
|
623
|
+
delegated: true,
|
|
624
|
+
scope: {
|
|
625
|
+
interface: DwnInterfaceName.Records,
|
|
626
|
+
method: DwnMethodName.Write,
|
|
627
|
+
protocol: 'https://example.com/protocol/test',
|
|
628
|
+
contextId: 'test-context'
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
632
|
+
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
633
|
+
});
|
|
634
|
+
expect(withContextIdReply.status.code).to.equal(202);
|
|
635
|
+
// create a permission request with protocol and protocolPath scope
|
|
636
|
+
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
637
|
+
signer: Jws.createSigner(alice),
|
|
638
|
+
grantedTo: bob.did,
|
|
639
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
640
|
+
description: 'Requesting to write to Alice foo/bar',
|
|
641
|
+
delegated: true,
|
|
642
|
+
scope: {
|
|
643
|
+
interface: DwnInterfaceName.Records,
|
|
644
|
+
method: DwnMethodName.Write,
|
|
645
|
+
protocol: 'https://example.com/protocol/test',
|
|
646
|
+
protocolPath: 'foo/bar'
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
650
|
+
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
651
|
+
});
|
|
652
|
+
expect(withProtocolPathReply.status.code).to.equal(202);
|
|
653
|
+
}));
|
|
654
|
+
it('ProtocolsQuery', () => __awaiter(this, void 0, void 0, function* () {
|
|
655
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
656
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
657
|
+
// create a permission grant with protocol query that is unrestricted
|
|
658
|
+
const protocolQueryPermissions = yield PermissionsProtocol.createGrant({
|
|
659
|
+
signer: Jws.createSigner(alice),
|
|
660
|
+
grantedTo: bob.did,
|
|
661
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
662
|
+
description: 'Requesting to query from Alice test-context',
|
|
663
|
+
scope: {
|
|
664
|
+
interface: DwnInterfaceName.Protocols,
|
|
665
|
+
method: DwnMethodName.Query,
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
const protocolQueryPermissionsReply = yield dwn.processMessage(alice.did, protocolQueryPermissions.recordsWrite.message, {
|
|
669
|
+
dataStream: DataStream.fromBytes(protocolQueryPermissions.permissionGrantBytes)
|
|
670
|
+
});
|
|
671
|
+
expect(protocolQueryPermissionsReply.status.code).to.equal(202);
|
|
672
|
+
}));
|
|
673
|
+
});
|
|
674
|
+
describe('validateScopeAndTags', () => __awaiter(this, void 0, void 0, function* () {
|
|
675
|
+
it('should be called for a Request or Grant record', () => __awaiter(this, void 0, void 0, function* () {
|
|
676
|
+
// spy on `validateScope`
|
|
677
|
+
const validateScopeSpy = sinon.spy(PermissionsProtocol, 'validateScopeAndTags');
|
|
678
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
679
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
680
|
+
const permissionScope = {
|
|
681
|
+
interface: DwnInterfaceName.Records,
|
|
682
|
+
method: DwnMethodName.Write,
|
|
683
|
+
protocol: 'https://example.com/protocol/test'
|
|
684
|
+
};
|
|
685
|
+
// create a request
|
|
686
|
+
const requestToAlice = yield PermissionsProtocol.createRequest({
|
|
687
|
+
signer: Jws.createSigner(bob),
|
|
688
|
+
description: `Requesting to write to Alice's DWN`,
|
|
689
|
+
delegated: false,
|
|
690
|
+
scope: permissionScope
|
|
691
|
+
});
|
|
692
|
+
const requestToAliceReply = yield dwn.processMessage(alice.did, requestToAlice.recordsWrite.message, { dataStream: DataStream.fromBytes(requestToAlice.permissionRequestBytes) });
|
|
693
|
+
expect(requestToAliceReply.status.code).to.equal(202);
|
|
694
|
+
expect(validateScopeSpy.calledOnce).to.be.true;
|
|
695
|
+
// create a grant
|
|
696
|
+
const grantedToBob = yield PermissionsProtocol.createGrant({
|
|
697
|
+
signer: Jws.createSigner(alice),
|
|
698
|
+
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
699
|
+
description: 'Allow Bob to write',
|
|
700
|
+
grantedTo: bob.did,
|
|
701
|
+
scope: permissionScope
|
|
702
|
+
});
|
|
703
|
+
const grantWriteReply = yield dwn.processMessage(alice.did, grantedToBob.recordsWrite.message, { dataStream: DataStream.fromBytes(grantedToBob.permissionGrantBytes) });
|
|
704
|
+
expect(grantWriteReply.status.code).to.equal(202);
|
|
705
|
+
expect(validateScopeSpy.calledTwice).to.be.true; // called twice, once for the request and once for the grant
|
|
706
|
+
}));
|
|
707
|
+
it('should throw if the scope is a RecordsPermissionScope and a protocol tag is not defined on the Request and Grant record', () => __awaiter(this, void 0, void 0, function* () {
|
|
708
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
709
|
+
const permissionScope = {
|
|
710
|
+
interface: DwnInterfaceName.Records,
|
|
711
|
+
method: DwnMethodName.Write,
|
|
712
|
+
protocol: 'https://example.com/protocol/test'
|
|
713
|
+
};
|
|
714
|
+
// create a permission request without a protocol tag
|
|
715
|
+
const requestWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
716
|
+
author: alice,
|
|
717
|
+
protocol: PermissionsProtocol.uri,
|
|
718
|
+
protocolPath: PermissionsProtocol.requestPath,
|
|
719
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
720
|
+
tags: { someTag: 'someValue' } // not a protocol tag
|
|
721
|
+
});
|
|
722
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
723
|
+
// create a permission grant without a protocol tag
|
|
724
|
+
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
725
|
+
author: alice,
|
|
726
|
+
protocol: PermissionsProtocol.uri,
|
|
727
|
+
protocolPath: PermissionsProtocol.grantPath,
|
|
728
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
729
|
+
tags: { someTag: 'someValue' } // not a protocol tag
|
|
730
|
+
});
|
|
731
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
732
|
+
}));
|
|
733
|
+
it('should throw if the scope is a RecordsPermissionScope and the Request and Grant record has no tags', () => __awaiter(this, void 0, void 0, function* () {
|
|
734
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
735
|
+
const permissionScope = {
|
|
736
|
+
interface: DwnInterfaceName.Records,
|
|
737
|
+
method: DwnMethodName.Write,
|
|
738
|
+
protocol: 'https://example.com/protocol/test'
|
|
739
|
+
};
|
|
740
|
+
// create a permission request without a protocol tag
|
|
741
|
+
const requestWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
742
|
+
author: alice,
|
|
743
|
+
protocol: PermissionsProtocol.uri,
|
|
744
|
+
protocolPath: PermissionsProtocol.requestPath,
|
|
745
|
+
data: Encoder.stringToBytes(JSON.stringify({}))
|
|
746
|
+
});
|
|
747
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
748
|
+
// create a permission grant without a protocol tag
|
|
749
|
+
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
750
|
+
author: alice,
|
|
751
|
+
protocol: PermissionsProtocol.uri,
|
|
752
|
+
protocolPath: PermissionsProtocol.grantPath,
|
|
753
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
754
|
+
});
|
|
755
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
756
|
+
}));
|
|
757
|
+
it('should throw if the protocol tag in the Request and Grant record does not match the protocol defined in the scope', () => __awaiter(this, void 0, void 0, function* () {
|
|
758
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
759
|
+
// create a permission scope to test against
|
|
760
|
+
const permissionScope = {
|
|
761
|
+
interface: DwnInterfaceName.Records,
|
|
762
|
+
method: DwnMethodName.Write,
|
|
763
|
+
protocol: 'https://example.com/protocol/test'
|
|
764
|
+
};
|
|
765
|
+
// create a permission request with a protocol tag that does not match the scope
|
|
766
|
+
const requestWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
767
|
+
author: alice,
|
|
768
|
+
protocol: PermissionsProtocol.uri,
|
|
769
|
+
protocolPath: PermissionsProtocol.requestPath,
|
|
770
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
771
|
+
tags: { protocol: 'https://example.com/protocol/invalid' }
|
|
772
|
+
});
|
|
773
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeProtocolMismatch);
|
|
774
|
+
// create a permission grant with a protocol tag that does not match the scope
|
|
775
|
+
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
776
|
+
author: alice,
|
|
777
|
+
protocol: PermissionsProtocol.uri,
|
|
778
|
+
protocolPath: PermissionsProtocol.grantPath,
|
|
779
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
780
|
+
tags: { protocol: 'https://example.com/protocol/invalid' }
|
|
781
|
+
});
|
|
782
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeProtocolMismatch);
|
|
783
|
+
}));
|
|
784
|
+
it('should throw if protocolPath and contextId are both defined in the scope for a Request and Grant record', () => __awaiter(this, void 0, void 0, function* () {
|
|
785
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
786
|
+
const permissionScope = {
|
|
787
|
+
interface: DwnInterfaceName.Records,
|
|
788
|
+
method: DwnMethodName.Write,
|
|
789
|
+
protocol: 'https://example.com/protocol/test',
|
|
790
|
+
protocolPath: 'test/path',
|
|
791
|
+
contextId: 'test-context'
|
|
792
|
+
};
|
|
793
|
+
// create a permission request with a scope that has both protocolPath and contextId
|
|
794
|
+
const requestRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
795
|
+
author: alice,
|
|
796
|
+
protocol: PermissionsProtocol.uri,
|
|
797
|
+
protocolPath: PermissionsProtocol.requestPath,
|
|
798
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
799
|
+
tags: { protocol: 'https://example.com/protocol/test' }
|
|
800
|
+
});
|
|
801
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestRecordsWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeContextIdProhibitedProperties);
|
|
802
|
+
// create a permission grant with a scope that has both protocolPath and contextId
|
|
803
|
+
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
804
|
+
author: alice,
|
|
805
|
+
protocol: PermissionsProtocol.uri,
|
|
806
|
+
protocolPath: PermissionsProtocol.grantPath,
|
|
807
|
+
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
808
|
+
tags: { protocol: 'https://example.com/protocol/test' }
|
|
809
|
+
});
|
|
810
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).to.throw(DwnErrorCode.PermissionsProtocolValidateScopeContextIdProhibitedProperties);
|
|
811
|
+
}));
|
|
812
|
+
}));
|
|
813
|
+
}));
|
|
814
|
+
}
|
|
815
|
+
//# sourceMappingURL=permissions.spec.js.map
|