@enbox/dwn-sdk-js 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +762 -911
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/abstract-message.js +4 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -1
- package/dist/esm/src/core/auth.js +22 -33
- package/dist/esm/src/core/auth.js.map +1 -1
- package/dist/esm/src/core/constants.js +11 -0
- package/dist/esm/src/core/constants.js.map +1 -0
- package/dist/esm/src/core/core-protocol.js +44 -0
- package/dist/esm/src/core/core-protocol.js.map +1 -0
- package/dist/esm/src/core/dwn-constant.js +7 -7
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +10 -12
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +50 -52
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message.js +85 -116
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +63 -78
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +266 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization-validation.js +321 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +144 -741
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/record-chain.js +64 -0
- package/dist/esm/src/core/record-chain.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +53 -72
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +50 -65
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/tenant-gate.js +2 -13
- package/dist/esm/src/core/tenant-gate.js.map +1 -1
- package/dist/esm/src/dwn.js +108 -101
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +67 -81
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +51 -63
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +75 -89
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +153 -163
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +52 -55
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +97 -85
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +75 -93
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +116 -105
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +130 -132
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +164 -104
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +213 -280
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +5 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +24 -32
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +28 -41
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/messages-sync.js +26 -40
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +87 -65
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +55 -68
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +50 -66
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +45 -55
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +60 -76
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +51 -67
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +53 -68
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-query.js +102 -0
- package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-write-signing.js +81 -0
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +396 -610
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js +23 -35
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +56 -69
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +43 -14
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +28 -14
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +325 -227
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +42 -64
- package/dist/esm/src/smt/smt-store-level.js.map +1 -1
- package/dist/esm/src/smt/smt-store-memory.js +19 -45
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
- package/dist/esm/src/smt/smt-utils.js +28 -45
- package/dist/esm/src/smt/smt-utils.js.map +1 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +113 -150
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +54 -156
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +48 -153
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +137 -100
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level-compound.js +246 -0
- package/dist/esm/src/store/index-level-compound.js.map +1 -0
- package/dist/esm/src/store/index-level.js +307 -715
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +143 -244
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +71 -94
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/resumable-task-store-level.js +62 -101
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +131 -146
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +10 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/utils/abort.js +8 -19
- package/dist/esm/src/utils/abort.js.map +1 -1
- package/dist/esm/src/utils/array.js +15 -49
- package/dist/esm/src/utils/array.js.map +1 -1
- package/dist/esm/src/utils/cid.js +29 -77
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +37 -65
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +136 -162
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/filter.js +1 -12
- package/dist/esm/src/utils/filter.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +45 -71
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +9 -20
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +12 -23
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/messages.js +21 -33
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +9 -17
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +62 -70
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +103 -166
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +60 -96
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +54 -71
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +5 -18
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/src/utils/url.js +3 -3
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +3 -12
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +50 -59
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +10 -18
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +65 -89
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +337 -347
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +160 -172
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +78 -82
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +449 -184
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +981 -360
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +45 -54
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +99 -108
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +108 -117
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-immutable.spec.js +315 -0
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +178 -194
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +456 -463
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +88 -98
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +215 -210
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +309 -171
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +272 -199
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +247 -241
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +159 -172
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +101 -105
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +266 -279
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +984 -996
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +542 -671
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +433 -302
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1216 -1140
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +190 -219
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +36 -45
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +49 -55
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +127 -138
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +372 -36
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +55 -64
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +66 -76
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +451 -354
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +160 -108
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +404 -414
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +13 -22
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +229 -238
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +12 -13
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +16 -13
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +8 -15
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +24 -33
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +48 -57
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +229 -82
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +46 -55
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +10 -19
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +3 -12
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +18 -20
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +22 -33
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +14 -27
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +446 -467
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +44 -24
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +49 -40
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +11 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/src/core/core-protocol.d.ts +89 -0
- package/dist/types/src/core/core-protocol.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +9 -12
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +6 -2
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts +81 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +24 -106
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/record-chain.d.ts +24 -0
- package/dist/types/src/core/record-chain.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +19 -7
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +3 -8
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-sync.d.ts +3 -8
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts +3 -8
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +3 -6
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +3 -8
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -8
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +3 -8
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +4 -24
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +8 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
- package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts +34 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +13 -53
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +1 -1
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +40 -3
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
- package/dist/types/src/store/data-store-level.d.ts +20 -4
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level-compound.d.ts +70 -0
- package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +4 -58
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +4 -4
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +3 -3
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +12 -3
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +24 -3
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +7 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +41 -1
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +16 -6
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/subscriptions.d.ts +151 -13
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -9
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/messages.d.ts +7 -5
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +5 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -11
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +11 -12
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +18 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/core/constants.ts +11 -0
- package/src/core/core-protocol.ts +129 -0
- package/src/core/dwn-error.ts +15 -12
- package/src/core/grant-authorization.ts +20 -3
- package/src/core/protocol-authorization-action.ts +377 -0
- package/src/core/protocol-authorization-validation.ts +487 -0
- package/src/core/protocol-authorization.ts +111 -856
- package/src/core/record-chain.ts +99 -0
- package/src/core/records-grant-authorization.ts +6 -8
- package/src/dwn.ts +58 -73
- package/src/event-stream/event-emitter-event-log.ts +283 -0
- package/src/handlers/messages-read.ts +8 -9
- package/src/handlers/messages-subscribe.ts +24 -28
- package/src/handlers/messages-sync.ts +10 -16
- package/src/handlers/protocols-configure.ts +47 -32
- package/src/handlers/protocols-query.ts +6 -9
- package/src/handlers/records-count.ts +11 -10
- package/src/handlers/records-delete.ts +12 -21
- package/src/handlers/records-query.ts +12 -12
- package/src/handlers/records-read.ts +34 -22
- package/src/handlers/records-subscribe.ts +47 -26
- package/src/handlers/records-write.ts +47 -104
- package/src/index.ts +9 -5
- package/src/interfaces/messages-subscribe.ts +7 -1
- package/src/interfaces/protocols-configure.ts +73 -8
- package/src/interfaces/records-count.ts +1 -1
- package/src/interfaces/records-delete.ts +1 -1
- package/src/interfaces/records-query.ts +1 -1
- package/src/interfaces/records-read.ts +1 -1
- package/src/interfaces/records-subscribe.ts +8 -1
- package/src/interfaces/records-write-query.ts +139 -0
- package/src/interfaces/records-write-signing.ts +123 -0
- package/src/interfaces/records-write.ts +66 -261
- package/src/protocols/permission-grant.ts +1 -1
- package/src/protocols/permission-request.ts +1 -1
- package/src/protocols/permissions.ts +148 -6
- package/src/state-index/state-index-level.ts +5 -7
- package/src/store/data-store-level.ts +124 -34
- package/src/store/index-level-compound.ts +324 -0
- package/src/store/index-level.ts +68 -341
- package/src/store/storage-controller.ts +11 -11
- package/src/types/message-types.ts +3 -3
- package/src/types/messages-types.ts +12 -3
- package/src/types/method-handler.ts +26 -4
- package/src/types/mitt.d.ts +28 -0
- package/src/types/permission-types.ts +7 -0
- package/src/types/protocols-types.ts +46 -0
- package/src/types/records-types.ts +16 -6
- package/src/types/subscriptions.ts +178 -14
- package/src/utils/hd-key.ts +0 -9
- package/src/utils/messages.ts +17 -37
- package/src/utils/protocols.ts +8 -0
- package/src/utils/records.ts +8 -59
- package/dist/esm/src/event-stream/event-emitter-stream.js +0 -60
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -77
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +0 -123
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
- package/src/event-stream/event-emitter-stream.ts +0 -69
|
@@ -1,27 +1,18 @@
|
|
|
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
1
|
import freeForAll from '../vectors/protocol-definitions/free-for-all.json' with { type: 'json' };
|
|
11
2
|
import threadProtocol from '../vectors/protocol-definitions/thread-role.json' with { type: 'json' };
|
|
12
3
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
13
4
|
import { Poller } from '../utils/poller.js';
|
|
14
5
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
15
|
-
import {
|
|
6
|
+
import { TestEventLog } from '../test-event-stream.js';
|
|
16
7
|
import { TestStores } from '../test-stores.js';
|
|
17
8
|
import { DataStream, Dwn, DwnInterfaceName, DwnMethodName, Jws, Message, PermissionGrant, PermissionsProtocol, Time } from '../../src/index.js';
|
|
18
9
|
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
19
10
|
// NOTE: We use `Poller.pollUntilSuccessOrTimeout` to poll for the expected results.
|
|
20
|
-
// In some cases, the
|
|
11
|
+
// In some cases, the EventLog is a coordinated pub/sub system and the message events are emitted over the network
|
|
21
12
|
// this means that the messages are not processed immediately and we need to wait for the messages to be processed
|
|
22
13
|
// before we can assert the results. The `pollUntilSuccessOrTimeout` function is a utility function that will poll until the expected results are met.
|
|
23
14
|
// It is also important to note that in some cases where we are testing a negative case (the message not arriving at the subscriber)
|
|
24
|
-
// we add an alternate subscription to await results within to give the
|
|
15
|
+
// we add an alternate subscription to await results within to give the EventLog ample time to process the message.
|
|
25
16
|
// Additionally in some of these cases the order in which messages are sent to be processed or checked may matter, and they are noted as such.
|
|
26
17
|
export function testSubscriptionScenarios() {
|
|
27
18
|
describe('subscriptions', () => {
|
|
@@ -30,138 +21,147 @@ export function testSubscriptionScenarios() {
|
|
|
30
21
|
let dataStore;
|
|
31
22
|
let resumableTaskStore;
|
|
32
23
|
let stateIndex;
|
|
33
|
-
let
|
|
24
|
+
let eventLog;
|
|
34
25
|
let dwn;
|
|
35
26
|
// important to follow the `beforeAll` and `afterAll` pattern to initialize and clean the stores in tests
|
|
36
27
|
// so that different test suites can reuse the same backend store for testing
|
|
37
|
-
beforeAll(() =>
|
|
28
|
+
beforeAll(async () => {
|
|
38
29
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
39
30
|
const stores = TestStores.get();
|
|
40
31
|
messageStore = stores.messageStore;
|
|
41
32
|
dataStore = stores.dataStore;
|
|
42
33
|
resumableTaskStore = stores.resumableTaskStore;
|
|
43
34
|
stateIndex = stores.stateIndex;
|
|
44
|
-
|
|
45
|
-
dwn =
|
|
46
|
-
})
|
|
47
|
-
beforeEach(() =>
|
|
35
|
+
eventLog = TestEventLog.get();
|
|
36
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, resumableTaskStore });
|
|
37
|
+
});
|
|
38
|
+
beforeEach(async () => {
|
|
48
39
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
afterAll(() =>
|
|
55
|
-
|
|
56
|
-
})
|
|
40
|
+
await messageStore.clear();
|
|
41
|
+
await dataStore.clear();
|
|
42
|
+
await resumableTaskStore.clear();
|
|
43
|
+
await stateIndex.clear();
|
|
44
|
+
});
|
|
45
|
+
afterAll(async () => {
|
|
46
|
+
await dwn.close();
|
|
47
|
+
});
|
|
57
48
|
describe('messages subscribe', () => {
|
|
58
|
-
it('all messages', () =>
|
|
49
|
+
it('all messages', async () => {
|
|
59
50
|
// Scenario: Alice subscribes to all messages and creates 3 messages. Alice then expects to receive all 3 messages.
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
52
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
62
53
|
// create a handler that adds the messageCid of each message to an array.
|
|
63
54
|
const messageCids = [];
|
|
64
|
-
const handler = (
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
const handler = async (msg) => {
|
|
56
|
+
if (msg.type !== 'event') {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const { message } = msg.event;
|
|
60
|
+
const messageCid = await Message.getCid(message);
|
|
67
61
|
messageCids.push(messageCid);
|
|
68
|
-
}
|
|
62
|
+
};
|
|
69
63
|
// subscribe to all messages
|
|
70
|
-
const messagesSubscription =
|
|
71
|
-
const messagesSubscriptionReply =
|
|
64
|
+
const messagesSubscription = await TestDataGenerator.generateMessagesSubscribe({ author: alice });
|
|
65
|
+
const messagesSubscriptionReply = await dwn.processMessage(alice.did, messagesSubscription.message, { subscriptionHandler: handler });
|
|
72
66
|
expect(messagesSubscriptionReply.status.code).toBe(200);
|
|
73
|
-
expect(
|
|
67
|
+
expect(messagesSubscriptionReply.subscription?.id).toBe(await Message.getCid(messagesSubscription.message));
|
|
74
68
|
// generate various messages
|
|
75
|
-
const write1 =
|
|
76
|
-
const write1MessageCid =
|
|
77
|
-
const write1Reply =
|
|
69
|
+
const write1 = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
70
|
+
const write1MessageCid = await Message.getCid(write1.message);
|
|
71
|
+
const write1Reply = await dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
78
72
|
expect(write1Reply.status.code).toBe(202);
|
|
79
|
-
const protocol1 =
|
|
80
|
-
const protocol1MessageCid =
|
|
81
|
-
const protocol1Reply =
|
|
73
|
+
const protocol1 = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
74
|
+
const protocol1MessageCid = await Message.getCid(protocol1.message);
|
|
75
|
+
const protocol1Reply = await dwn.processMessage(alice.did, protocol1.message);
|
|
82
76
|
expect(protocol1Reply.status.code).toBe(202);
|
|
83
|
-
const deleteWrite1 =
|
|
84
|
-
const delete1MessageCid =
|
|
85
|
-
const deleteWrite1Reply =
|
|
77
|
+
const deleteWrite1 = await TestDataGenerator.generateRecordsDelete({ author: alice, recordId: write1.message.recordId });
|
|
78
|
+
const delete1MessageCid = await Message.getCid(deleteWrite1.message);
|
|
79
|
+
const deleteWrite1Reply = await dwn.processMessage(alice.did, deleteWrite1.message);
|
|
86
80
|
expect(deleteWrite1Reply.status.code).toBe(202);
|
|
87
81
|
// poll until the messages are received by the handler
|
|
88
|
-
|
|
82
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
89
83
|
expect(messageCids.length).toBe(3);
|
|
90
84
|
expect(messageCids).toEqual([write1MessageCid, protocol1MessageCid, delete1MessageCid]);
|
|
91
|
-
})
|
|
85
|
+
});
|
|
92
86
|
// clean up the subscription handler
|
|
93
|
-
|
|
94
|
-
})
|
|
95
|
-
it('filters by interface type', () =>
|
|
87
|
+
await messagesSubscriptionReply.subscription?.close();
|
|
88
|
+
});
|
|
89
|
+
it('filters by interface type', async () => {
|
|
96
90
|
// scenario:
|
|
97
91
|
// alice subscribes to 2 different message interfaces Records and Protocols
|
|
98
92
|
// alice creates (2) messages, RecordsWrite and ProtocolsConfigure
|
|
99
93
|
// alice checks that each handler received the appropriate message
|
|
100
94
|
// alice deletes the record
|
|
101
95
|
// alice checks that the Records handler received the delete message
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
97
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
104
98
|
// subscribe to the Records interface
|
|
105
|
-
const recordsInterfaceSubscription =
|
|
99
|
+
const recordsInterfaceSubscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
106
100
|
author: alice,
|
|
107
101
|
filters: [{ interface: DwnInterfaceName.Records }]
|
|
108
102
|
});
|
|
109
103
|
const recordsMessageCids = [];
|
|
110
|
-
const recordsSubscribeHandler = (
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
const recordsSubscribeHandler = async (msg) => {
|
|
105
|
+
if (msg.type !== 'event') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const { message } = msg.event;
|
|
109
|
+
const messageCid = await Message.getCid(message);
|
|
113
110
|
recordsMessageCids.push(messageCid);
|
|
114
|
-
}
|
|
115
|
-
const recordsInterfaceSubscriptionReply =
|
|
111
|
+
};
|
|
112
|
+
const recordsInterfaceSubscriptionReply = await dwn.processMessage(alice.did, recordsInterfaceSubscription.message, { subscriptionHandler: recordsSubscribeHandler });
|
|
116
113
|
expect(recordsInterfaceSubscriptionReply.status.code).toBe(200);
|
|
117
114
|
expect(recordsInterfaceSubscriptionReply.subscription).toBeDefined();
|
|
118
115
|
// subscribe to the Protocols interface
|
|
119
|
-
const protocolsInterfaceSubscription =
|
|
116
|
+
const protocolsInterfaceSubscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
120
117
|
author: alice,
|
|
121
118
|
filters: [{ interface: DwnInterfaceName.Protocols }]
|
|
122
119
|
});
|
|
123
120
|
const protocolsMessageCids = [];
|
|
124
|
-
const protocolsSubscribeHandler = (
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
const protocolsSubscribeHandler = async (msg) => {
|
|
122
|
+
if (msg.type !== 'event') {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { message } = msg.event;
|
|
126
|
+
const messageCid = await Message.getCid(message);
|
|
127
127
|
protocolsMessageCids.push(messageCid);
|
|
128
|
-
}
|
|
129
|
-
const protocolsInterfaceSubscriptionReply =
|
|
128
|
+
};
|
|
129
|
+
const protocolsInterfaceSubscriptionReply = await dwn.processMessage(alice.did, protocolsInterfaceSubscription.message, { subscriptionHandler: protocolsSubscribeHandler });
|
|
130
130
|
expect(protocolsInterfaceSubscriptionReply.status.code).toBe(200);
|
|
131
131
|
expect(protocolsInterfaceSubscriptionReply.subscription).toBeDefined();
|
|
132
132
|
// create one of each message types a RecordsWrite and a ProtocolsConfigure
|
|
133
|
-
const record =
|
|
134
|
-
const recordReply =
|
|
133
|
+
const record = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
134
|
+
const recordReply = await dwn.processMessage(alice.did, record.message, { dataStream: record.dataStream });
|
|
135
135
|
expect(recordReply.status.code).toBe(202, 'RecordsWrite');
|
|
136
|
-
const protocol =
|
|
137
|
-
const protocolReply =
|
|
136
|
+
const protocol = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
137
|
+
const protocolReply = await dwn.processMessage(alice.did, protocol.message);
|
|
138
138
|
expect(protocolReply.status.code).toBe(202, 'ProtocolConfigure');
|
|
139
139
|
// Poll until the messages are received by the handler
|
|
140
|
-
|
|
140
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
141
141
|
// check record message
|
|
142
142
|
expect(recordsMessageCids.length).toBe(1);
|
|
143
|
-
expect(recordsMessageCids).toEqual(expect.arrayContaining([
|
|
143
|
+
expect(recordsMessageCids).toEqual(expect.arrayContaining([await Message.getCid(record.message)]));
|
|
144
144
|
// check protocols message
|
|
145
145
|
expect(protocolsMessageCids.length).toBe(1);
|
|
146
|
-
expect(protocolsMessageCids).toEqual(expect.arrayContaining([
|
|
147
|
-
})
|
|
146
|
+
expect(protocolsMessageCids).toEqual(expect.arrayContaining([await Message.getCid(protocol.message)]));
|
|
147
|
+
});
|
|
148
148
|
// delete the record
|
|
149
|
-
const recordDelete =
|
|
150
|
-
const recordDeleteReply =
|
|
149
|
+
const recordDelete = await TestDataGenerator.generateRecordsDelete({ author: alice, recordId: record.message.recordId });
|
|
150
|
+
const recordDeleteReply = await dwn.processMessage(alice.did, recordDelete.message);
|
|
151
151
|
expect(recordDeleteReply.status.code).toBe(202, 'RecordsDelete');
|
|
152
152
|
// poll until the delete message is received by the handler
|
|
153
|
-
|
|
153
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
154
154
|
// check record messages to include the delete message
|
|
155
155
|
expect(recordsMessageCids.length).toBe(2);
|
|
156
|
-
expect(recordsMessageCids).toEqual(expect.arrayContaining([
|
|
156
|
+
expect(recordsMessageCids).toEqual(expect.arrayContaining([await Message.getCid(recordDelete.message)]));
|
|
157
157
|
// check that the protocols message array does not include the delete message
|
|
158
158
|
expect(protocolsMessageCids.length).toBe(1); // unchanged
|
|
159
|
-
})
|
|
159
|
+
});
|
|
160
160
|
// clean up the subscriptions
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
})
|
|
164
|
-
it('filters by method type', () =>
|
|
161
|
+
await recordsInterfaceSubscriptionReply.subscription?.close();
|
|
162
|
+
await protocolsInterfaceSubscriptionReply.subscription?.close();
|
|
163
|
+
});
|
|
164
|
+
it('filters by method type', async () => {
|
|
165
165
|
// scenario:
|
|
166
166
|
// Alice creates a subscription filtered to RecordsWrite messages
|
|
167
167
|
// Alice creates a second subscription filtered to RecordsDelete messages
|
|
@@ -172,66 +172,73 @@ export function testSubscriptionScenarios() {
|
|
|
172
172
|
// Alice also writes a new record with a RecordsWrite
|
|
173
173
|
// Alice checks that the RecordsWrite handler received the new record, but not the delete message
|
|
174
174
|
// Alice checks the RecordsDelete handler received the delete message
|
|
175
|
-
const alice =
|
|
175
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
176
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
176
177
|
// subscribe to records write
|
|
177
|
-
const recordsWriteSubscription =
|
|
178
|
+
const recordsWriteSubscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
178
179
|
author: alice,
|
|
179
180
|
filters: [{ interface: DwnInterfaceName.Records, method: DwnMethodName.Write }]
|
|
180
181
|
});
|
|
181
182
|
const recordsWriteMessageCids = [];
|
|
182
|
-
const recordsSubscribeHandler = (
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
const recordsSubscribeHandler = async (msg) => {
|
|
184
|
+
if (msg.type !== 'event') {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const { message } = msg.event;
|
|
188
|
+
const messageCid = await Message.getCid(message);
|
|
185
189
|
recordsWriteMessageCids.push(messageCid);
|
|
186
|
-
}
|
|
187
|
-
const recordsWriteSubscriptionReply =
|
|
190
|
+
};
|
|
191
|
+
const recordsWriteSubscriptionReply = await dwn.processMessage(alice.did, recordsWriteSubscription.message, { subscriptionHandler: recordsSubscribeHandler });
|
|
188
192
|
expect(recordsWriteSubscriptionReply.status.code).toBe(200);
|
|
189
193
|
expect(recordsWriteSubscriptionReply.subscription).toBeDefined();
|
|
190
194
|
// subscribe to records delete
|
|
191
|
-
const recordsDeleteSubscription =
|
|
195
|
+
const recordsDeleteSubscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
192
196
|
author: alice,
|
|
193
197
|
filters: [{ interface: DwnInterfaceName.Records, method: DwnMethodName.Delete }]
|
|
194
198
|
});
|
|
195
199
|
const recordsDeleteMessageCids = [];
|
|
196
|
-
const recordsDeleteSubscribeHandler = (
|
|
197
|
-
|
|
198
|
-
|
|
200
|
+
const recordsDeleteSubscribeHandler = async (msg) => {
|
|
201
|
+
if (msg.type !== 'event') {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const { message } = msg.event;
|
|
205
|
+
const messageCid = await Message.getCid(message);
|
|
199
206
|
recordsDeleteMessageCids.push(messageCid);
|
|
200
|
-
}
|
|
201
|
-
const recordsDeleteSubscriptionReply =
|
|
207
|
+
};
|
|
208
|
+
const recordsDeleteSubscriptionReply = await dwn.processMessage(alice.did, recordsDeleteSubscription.message, { subscriptionHandler: recordsDeleteSubscribeHandler });
|
|
202
209
|
expect(recordsDeleteSubscriptionReply.status.code).toBe(200);
|
|
203
210
|
expect(recordsDeleteSubscriptionReply.subscription).toBeDefined();
|
|
204
211
|
// create and updates the record, this creates two RecordsWrite messages
|
|
205
|
-
const record =
|
|
206
|
-
const recordReply =
|
|
212
|
+
const record = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
213
|
+
const recordReply = await dwn.processMessage(alice.did, record.message, { dataStream: record.dataStream });
|
|
207
214
|
expect(recordReply.status.code).toBe(202, 'RecordsWrite');
|
|
208
|
-
const record1MessageCid =
|
|
209
|
-
const recordUpdate =
|
|
210
|
-
const recordUpdateReply =
|
|
215
|
+
const record1MessageCid = await Message.getCid(record.message);
|
|
216
|
+
const recordUpdate = await TestDataGenerator.generateFromRecordsWrite({ author: alice, existingWrite: record.recordsWrite });
|
|
217
|
+
const recordUpdateReply = await dwn.processMessage(alice.did, recordUpdate.message, { dataStream: recordUpdate.dataStream });
|
|
211
218
|
expect(recordUpdateReply.status.code).toBe(202, 'RecordsUpdate');
|
|
212
|
-
const recordUpdateMessageCid =
|
|
219
|
+
const recordUpdateMessageCid = await Message.getCid(recordUpdate.message);
|
|
213
220
|
// Poll until the messages are received by the handler
|
|
214
|
-
|
|
221
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
215
222
|
// check the array for both the RecordsWrite messages
|
|
216
223
|
expect(recordsWriteMessageCids.length).toBe(2);
|
|
217
224
|
expect(recordsWriteMessageCids).toEqual(expect.arrayContaining([
|
|
218
225
|
record1MessageCid,
|
|
219
226
|
recordUpdateMessageCid,
|
|
220
227
|
]));
|
|
221
|
-
})
|
|
228
|
+
});
|
|
222
229
|
// confirm that the delete array is empty
|
|
223
230
|
expect(recordsDeleteMessageCids.length).toBe(0);
|
|
224
231
|
// delete the record
|
|
225
|
-
const recordDelete =
|
|
226
|
-
const recordDeleteReply =
|
|
232
|
+
const recordDelete = await TestDataGenerator.generateRecordsDelete({ author: alice, recordId: record.message.recordId });
|
|
233
|
+
const recordDeleteReply = await dwn.processMessage(alice.did, recordDelete.message);
|
|
227
234
|
expect(recordDeleteReply.status.code).toBe(202, 'RecordsDelete');
|
|
228
|
-
const recordDeleteMessageCid =
|
|
235
|
+
const recordDeleteMessageCid = await Message.getCid(recordDelete.message);
|
|
229
236
|
// write a second record
|
|
230
|
-
const record2 =
|
|
231
|
-
const record2Reply =
|
|
237
|
+
const record2 = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
238
|
+
const record2Reply = await dwn.processMessage(alice.did, record2.message, { dataStream: record2.dataStream });
|
|
232
239
|
expect(record2Reply.status.code).toBe(202, 'RecordsWrite');
|
|
233
|
-
const record2MessageCid =
|
|
234
|
-
|
|
240
|
+
const record2MessageCid = await Message.getCid(record2.message);
|
|
241
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
235
242
|
// ensure the new record is in the recordsWrite array, but not the delete
|
|
236
243
|
expect(recordsWriteMessageCids.length).toBe(3);
|
|
237
244
|
expect(recordsWriteMessageCids).toEqual(expect.arrayContaining([
|
|
@@ -244,9 +251,9 @@ export function testSubscriptionScenarios() {
|
|
|
244
251
|
expect(recordsDeleteMessageCids).toEqual(expect.arrayContaining([
|
|
245
252
|
recordDeleteMessageCid,
|
|
246
253
|
]));
|
|
247
|
-
})
|
|
248
|
-
})
|
|
249
|
-
it('filters by a protocol across different message types', () =>
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
it('filters by a protocol across different message types', async () => {
|
|
250
257
|
// NOTE: This test validates the ability to filter by a specific protocol across different message types.
|
|
251
258
|
// This will return any of the `RecordsWrite`, `RecordsDelete` and `ProtocolConfigure` messages that are associated with the protocol
|
|
252
259
|
// Additionally this will return permission-protocol `RecordsWrite` messages that are associated with the protocol.
|
|
@@ -260,51 +267,57 @@ export function testSubscriptionScenarios() {
|
|
|
260
267
|
// alice then deletes the records for each protocol
|
|
261
268
|
// alice revokes bob's permissions for both protocols
|
|
262
269
|
// now when checking the handler arrays, the delete and revocation messages should be present
|
|
263
|
-
const alice =
|
|
264
|
-
const bob =
|
|
270
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
271
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
265
272
|
const proto1Messages = [];
|
|
266
|
-
const proto1Handler = (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
273
|
+
const proto1Handler = async (msg) => {
|
|
274
|
+
if (msg.type !== 'event') {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const { message } = msg.event;
|
|
278
|
+
proto1Messages.push(await Message.getCid(message));
|
|
279
|
+
};
|
|
280
|
+
const proto1Subscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
271
281
|
author: alice,
|
|
272
282
|
filters: [{ protocol: 'http://proto1' }]
|
|
273
283
|
});
|
|
274
|
-
const proto1SubscriptionReply =
|
|
284
|
+
const proto1SubscriptionReply = await dwn.processMessage(alice.did, proto1Subscription.message, {
|
|
275
285
|
subscriptionHandler: proto1Handler
|
|
276
286
|
});
|
|
277
287
|
expect(proto1SubscriptionReply.status.code).toBe(200);
|
|
278
288
|
expect(proto1SubscriptionReply.subscription).toBeDefined();
|
|
279
289
|
const proto2Messages = [];
|
|
280
|
-
const proto2Handler = (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
const proto2Handler = async (msg) => {
|
|
291
|
+
if (msg.type !== 'event') {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const { message } = msg.event;
|
|
295
|
+
proto2Messages.push(await Message.getCid(message));
|
|
296
|
+
};
|
|
297
|
+
const proto2Subscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
285
298
|
author: alice,
|
|
286
299
|
filters: [{ protocol: 'http://proto2' }]
|
|
287
300
|
});
|
|
288
|
-
const proto2SubscriptionReply =
|
|
301
|
+
const proto2SubscriptionReply = await dwn.processMessage(alice.did, proto2Subscription.message, {
|
|
289
302
|
subscriptionHandler: proto2Handler
|
|
290
303
|
});
|
|
291
304
|
expect(proto2SubscriptionReply.status.code).toBe(200);
|
|
292
305
|
expect(proto2SubscriptionReply.subscription).toBeDefined();
|
|
293
306
|
// configure proto1
|
|
294
|
-
const protoConf1 =
|
|
307
|
+
const protoConf1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
295
308
|
author: alice,
|
|
296
|
-
protocolDefinition:
|
|
309
|
+
protocolDefinition: { ...freeForAll, protocol: 'http://proto1' }
|
|
297
310
|
});
|
|
298
311
|
const proto1 = protoConf1.message.descriptor.definition.protocol;
|
|
299
|
-
const protoConf1Response =
|
|
312
|
+
const protoConf1Response = await dwn.processMessage(alice.did, protoConf1.message);
|
|
300
313
|
expect(protoConf1Response.status.code).toBe(202);
|
|
301
314
|
// configure proto2
|
|
302
|
-
const protoConf2 =
|
|
315
|
+
const protoConf2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
303
316
|
author: alice,
|
|
304
|
-
protocolDefinition:
|
|
317
|
+
protocolDefinition: { ...freeForAll, protocol: 'http://proto2' }
|
|
305
318
|
});
|
|
306
319
|
const proto2 = protoConf2.message.descriptor.definition.protocol;
|
|
307
|
-
const protoConf2Response =
|
|
320
|
+
const protoConf2Response = await dwn.processMessage(alice.did, protoConf2.message);
|
|
308
321
|
expect(protoConf2Response.status.code).toBe(202);
|
|
309
322
|
const postProperties = {
|
|
310
323
|
protocolPath: 'post',
|
|
@@ -312,158 +325,165 @@ export function testSubscriptionScenarios() {
|
|
|
312
325
|
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
313
326
|
};
|
|
314
327
|
// create a record for proto1
|
|
315
|
-
const write1proto1 =
|
|
316
|
-
const write1Response =
|
|
328
|
+
const write1proto1 = await TestDataGenerator.generateRecordsWrite({ author: alice, protocol: proto1, ...postProperties });
|
|
329
|
+
const write1Response = await dwn.processMessage(alice.did, write1proto1.message, { dataStream: write1proto1.dataStream });
|
|
317
330
|
expect(write1Response.status.code).toBe(202);
|
|
318
331
|
// create a record for proto2
|
|
319
|
-
const write1proto2 =
|
|
320
|
-
const write1Proto2Response =
|
|
332
|
+
const write1proto2 = await TestDataGenerator.generateRecordsWrite({ author: alice, protocol: proto2, ...postProperties });
|
|
333
|
+
const write1Proto2Response = await dwn.processMessage(alice.did, write1proto2.message, { dataStream: write1proto2.dataStream });
|
|
321
334
|
expect(write1Proto2Response.status.code).toBe(202);
|
|
322
335
|
// bob requests permissions for proto1
|
|
323
|
-
const requestProto1 =
|
|
336
|
+
const requestProto1 = await PermissionsProtocol.createRequest({
|
|
324
337
|
signer: Jws.createSigner(bob),
|
|
325
338
|
scope: { interface: DwnInterfaceName.Records, method: DwnMethodName.Write, protocol: proto1 },
|
|
326
339
|
delegated: false,
|
|
327
340
|
});
|
|
328
|
-
const requestProto1Response =
|
|
341
|
+
const requestProto1Response = await dwn.processMessage(alice.did, requestProto1.recordsWrite.message, { dataStream: DataStream.fromBytes(requestProto1.permissionRequestBytes) });
|
|
329
342
|
expect(requestProto1Response.status.code).toBe(202);
|
|
330
343
|
// bob requests permissions for proto2
|
|
331
|
-
const requestProto2 =
|
|
344
|
+
const requestProto2 = await PermissionsProtocol.createRequest({
|
|
332
345
|
signer: Jws.createSigner(bob),
|
|
333
346
|
scope: { interface: DwnInterfaceName.Records, method: DwnMethodName.Write, protocol: proto2 },
|
|
334
347
|
delegated: false,
|
|
335
348
|
});
|
|
336
|
-
const requestProto2Response =
|
|
349
|
+
const requestProto2Response = await dwn.processMessage(alice.did, requestProto2.recordsWrite.message, { dataStream: DataStream.fromBytes(requestProto2.permissionRequestBytes) });
|
|
337
350
|
expect(requestProto2Response.status.code).toBe(202);
|
|
338
351
|
// alice grants permissions for proto1
|
|
339
|
-
const grantProto1 =
|
|
352
|
+
const grantProto1 = await PermissionsProtocol.createGrant({
|
|
340
353
|
signer: Jws.createSigner(alice),
|
|
341
354
|
scope: requestProto1.permissionRequestData.scope,
|
|
342
355
|
dateExpires: Time.createOffsetTimestamp({ seconds: 5 }),
|
|
343
356
|
grantedTo: bob.did,
|
|
344
357
|
});
|
|
345
|
-
const grantProto1Response =
|
|
358
|
+
const grantProto1Response = await dwn.processMessage(alice.did, grantProto1.recordsWrite.message, { dataStream: DataStream.fromBytes(grantProto1.permissionGrantBytes) });
|
|
346
359
|
expect(grantProto1Response.status.code).toBe(202);
|
|
347
360
|
// alice grants permissions for proto2
|
|
348
|
-
const grantProto2 =
|
|
361
|
+
const grantProto2 = await PermissionsProtocol.createGrant({
|
|
349
362
|
signer: Jws.createSigner(alice),
|
|
350
363
|
scope: requestProto2.permissionRequestData.scope,
|
|
351
364
|
dateExpires: Time.createOffsetTimestamp({ seconds: 5 }),
|
|
352
365
|
grantedTo: bob.did,
|
|
353
366
|
});
|
|
354
|
-
const grantProto2Response =
|
|
367
|
+
const grantProto2Response = await dwn.processMessage(alice.did, grantProto2.recordsWrite.message, { dataStream: DataStream.fromBytes(grantProto2.permissionGrantBytes) });
|
|
355
368
|
expect(grantProto2Response.status.code).toBe(202);
|
|
356
369
|
// poll until the messages are received by the handlers
|
|
357
|
-
|
|
370
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
358
371
|
// check for proto1 messages
|
|
359
372
|
expect(proto1Messages.length).toBe(4);
|
|
360
373
|
expect(proto1Messages).toEqual(expect.arrayContaining([
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
374
|
+
await Message.getCid(protoConf1.message),
|
|
375
|
+
await Message.getCid(write1proto1.message),
|
|
376
|
+
await Message.getCid(requestProto1.recordsWrite.message),
|
|
377
|
+
await Message.getCid(grantProto1.recordsWrite.message),
|
|
365
378
|
]));
|
|
366
379
|
// check for proto2 messages
|
|
367
380
|
expect(proto2Messages.length).toBe(4);
|
|
368
381
|
expect(proto2Messages).toEqual(expect.arrayContaining([
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
382
|
+
await Message.getCid(protoConf2.message),
|
|
383
|
+
await Message.getCid(write1proto2.message),
|
|
384
|
+
await Message.getCid(requestProto2.recordsWrite.message),
|
|
385
|
+
await Message.getCid(grantProto2.recordsWrite.message),
|
|
373
386
|
]));
|
|
374
|
-
})
|
|
387
|
+
});
|
|
375
388
|
// delete proto1 message
|
|
376
|
-
const deleteProto1Message =
|
|
377
|
-
const deleteProto1MessageReply =
|
|
389
|
+
const deleteProto1Message = await TestDataGenerator.generateRecordsDelete({ author: alice, recordId: write1proto1.message.recordId });
|
|
390
|
+
const deleteProto1MessageReply = await dwn.processMessage(alice.did, deleteProto1Message.message);
|
|
378
391
|
expect(deleteProto1MessageReply.status.code).toBe(202);
|
|
379
392
|
// delete proto2 message
|
|
380
|
-
const deleteProto2Message =
|
|
381
|
-
const deleteProto2MessageReply =
|
|
393
|
+
const deleteProto2Message = await TestDataGenerator.generateRecordsDelete({ author: alice, recordId: write1proto2.message.recordId });
|
|
394
|
+
const deleteProto2MessageReply = await dwn.processMessage(alice.did, deleteProto2Message.message);
|
|
382
395
|
expect(deleteProto2MessageReply.status.code).toBe(202);
|
|
383
396
|
// revoke permissions for proto1
|
|
384
|
-
const revokeProto1 =
|
|
397
|
+
const revokeProto1 = await PermissionsProtocol.createRevocation({
|
|
385
398
|
signer: Jws.createSigner(alice),
|
|
386
|
-
grant:
|
|
399
|
+
grant: PermissionGrant.parse(grantProto1.dataEncodedMessage),
|
|
387
400
|
});
|
|
388
|
-
const revokeProto1Response =
|
|
401
|
+
const revokeProto1Response = await dwn.processMessage(alice.did, revokeProto1.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeProto1.permissionRevocationBytes) });
|
|
389
402
|
expect(revokeProto1Response.status.code).toBe(202);
|
|
390
403
|
// revoke permissions for proto2
|
|
391
|
-
const revokeProto2 =
|
|
404
|
+
const revokeProto2 = await PermissionsProtocol.createRevocation({
|
|
392
405
|
signer: Jws.createSigner(alice),
|
|
393
|
-
grant:
|
|
406
|
+
grant: PermissionGrant.parse(grantProto2.dataEncodedMessage),
|
|
394
407
|
});
|
|
395
|
-
const revokeProto2Response =
|
|
408
|
+
const revokeProto2Response = await dwn.processMessage(alice.did, revokeProto2.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeProto2.permissionRevocationBytes) });
|
|
396
409
|
expect(revokeProto2Response.status.code).toBe(202);
|
|
397
410
|
// poll until the messages are received by the handlers
|
|
398
|
-
|
|
411
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
399
412
|
// check for the delete and revocation in proto1 messages
|
|
400
413
|
expect(proto1Messages.length).toBe(6); // 2 additional messages
|
|
401
414
|
expect(proto1Messages).toEqual(expect.arrayContaining([
|
|
402
|
-
|
|
403
|
-
|
|
415
|
+
await Message.getCid(deleteProto1Message.message),
|
|
416
|
+
await Message.getCid(revokeProto1.recordsWrite.message),
|
|
404
417
|
]));
|
|
405
418
|
// check for the delete and revocation in proto2 messages
|
|
406
419
|
expect(proto2Messages.length).toBe(6); // 2 additional messages
|
|
407
420
|
expect(proto2Messages).toEqual(expect.arrayContaining([
|
|
408
|
-
|
|
409
|
-
|
|
421
|
+
await Message.getCid(deleteProto2Message.message),
|
|
422
|
+
await Message.getCid(revokeProto2.recordsWrite.message),
|
|
410
423
|
]));
|
|
411
|
-
})
|
|
412
|
-
})
|
|
413
|
-
it('does not emit events after subscription is closed', () =>
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
it('does not emit events after subscription is closed', async () => {
|
|
414
427
|
// scenario: create two subscriptions.
|
|
415
428
|
// write a message, check that both subscriptions receive the message.
|
|
416
429
|
// close one subscription, write two more messages, check that only the open subscription receives the messages.
|
|
417
430
|
// we purposely leave one subscription open to ensure that the messages are being processed by an external pub/sub system
|
|
418
|
-
const alice =
|
|
431
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
432
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
419
433
|
// messageCids of subscription 1 messages
|
|
420
434
|
const sub1MessageCids = [];
|
|
421
|
-
const handler1 = (
|
|
422
|
-
|
|
423
|
-
|
|
435
|
+
const handler1 = async (msg) => {
|
|
436
|
+
if (msg.type !== 'event') {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const { message } = msg.event;
|
|
440
|
+
const messageCid = await Message.getCid(message);
|
|
424
441
|
sub1MessageCids.push(messageCid);
|
|
425
|
-
}
|
|
442
|
+
};
|
|
426
443
|
// messageCids of subscription 2 messages
|
|
427
444
|
const sub2MessageCids = [];
|
|
428
|
-
const handler2 = (
|
|
429
|
-
|
|
430
|
-
|
|
445
|
+
const handler2 = async (msg) => {
|
|
446
|
+
if (msg.type !== 'event') {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const { message } = msg.event;
|
|
450
|
+
const messageCid = await Message.getCid(message);
|
|
431
451
|
sub2MessageCids.push(messageCid);
|
|
432
|
-
}
|
|
452
|
+
};
|
|
433
453
|
// subscribe to all messages
|
|
434
|
-
const messagesSubscription1 =
|
|
435
|
-
const messagesSubscription1Reply =
|
|
454
|
+
const messagesSubscription1 = await TestDataGenerator.generateMessagesSubscribe({ author: alice });
|
|
455
|
+
const messagesSubscription1Reply = await dwn.processMessage(alice.did, messagesSubscription1.message, { subscriptionHandler: handler1 });
|
|
436
456
|
expect(messagesSubscription1Reply.status.code).toBe(200);
|
|
437
|
-
const messagesSubscription2 =
|
|
438
|
-
const messagesSubscription2Reply =
|
|
457
|
+
const messagesSubscription2 = await TestDataGenerator.generateMessagesSubscribe({ author: alice });
|
|
458
|
+
const messagesSubscription2Reply = await dwn.processMessage(alice.did, messagesSubscription2.message, { subscriptionHandler: handler2 });
|
|
439
459
|
expect(messagesSubscription2Reply.status.code).toBe(200);
|
|
440
460
|
// no event message exist yet
|
|
441
461
|
expect(sub1MessageCids.length).toBe(0);
|
|
442
462
|
expect(sub2MessageCids.length).toBe(0);
|
|
443
463
|
// write a record
|
|
444
|
-
const record1 =
|
|
445
|
-
const record1Reply =
|
|
464
|
+
const record1 = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
465
|
+
const record1Reply = await dwn.processMessage(alice.did, record1.message, { dataStream: record1.dataStream });
|
|
446
466
|
expect(record1Reply.status.code).toBe(202);
|
|
447
|
-
const record1MessageCid =
|
|
448
|
-
|
|
467
|
+
const record1MessageCid = await Message.getCid(record1.message);
|
|
468
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
449
469
|
// both subscriptions should have received the message
|
|
450
470
|
expect(sub1MessageCids.length).toBe(1); // message exists
|
|
451
471
|
expect(sub1MessageCids).toEqual([record1MessageCid]);
|
|
452
472
|
expect(sub2MessageCids.length).toBe(1); // message exists
|
|
453
473
|
expect(sub2MessageCids).toEqual([record1MessageCid]);
|
|
454
|
-
})
|
|
474
|
+
});
|
|
455
475
|
// unsubscribe from subscription 2
|
|
456
|
-
|
|
476
|
+
await messagesSubscription2Reply.subscription.close();
|
|
457
477
|
// write two more message.
|
|
458
|
-
const record2 =
|
|
459
|
-
const record2Reply =
|
|
478
|
+
const record2 = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
479
|
+
const record2Reply = await dwn.processMessage(alice.did, record2.message, { dataStream: record2.dataStream });
|
|
460
480
|
expect(record2Reply.status.code).toBe(202);
|
|
461
|
-
const record2MessageCid =
|
|
462
|
-
const record3 =
|
|
463
|
-
const record3Reply =
|
|
481
|
+
const record2MessageCid = await Message.getCid(record2.message);
|
|
482
|
+
const record3 = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
483
|
+
const record3Reply = await dwn.processMessage(alice.did, record3.message, { dataStream: record3.dataStream });
|
|
464
484
|
expect(record3Reply.status.code).toBe(202);
|
|
465
|
-
const record3MessageCid =
|
|
466
|
-
|
|
485
|
+
const record3MessageCid = await Message.getCid(record3.message);
|
|
486
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
467
487
|
expect(sub1MessageCids.length).toBe(3); // all three messages exist
|
|
468
488
|
expect(sub1MessageCids).toEqual([
|
|
469
489
|
record1MessageCid,
|
|
@@ -472,109 +492,122 @@ export function testSubscriptionScenarios() {
|
|
|
472
492
|
]);
|
|
473
493
|
expect(sub2MessageCids.length).toBe(1); // only the first message exists
|
|
474
494
|
expect(sub2MessageCids).toEqual([record1MessageCid]);
|
|
475
|
-
})
|
|
476
|
-
})
|
|
495
|
+
});
|
|
496
|
+
});
|
|
477
497
|
});
|
|
478
498
|
describe('records subscribe', () => {
|
|
479
|
-
it('allows for anonymous subscriptions to published records', () =>
|
|
499
|
+
it('allows for anonymous subscriptions to published records', async () => {
|
|
480
500
|
// scenario:
|
|
481
501
|
// a user creates an anonymous subscription filtered to a schema to alice's DWN
|
|
482
502
|
// alice writes two records, one not published and one published
|
|
483
503
|
// alice checks that the anonymous subscription handler only received the published record
|
|
484
504
|
// NOTE we create a control subscription to capture all messages
|
|
485
505
|
// this is to ensure that the messages are not received by the anonymous subscription handler, but have had ample time to be processed
|
|
486
|
-
const alice =
|
|
506
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
507
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
487
508
|
// create a control handler to capture ALL messages in the protocol with alice as the author
|
|
488
509
|
const allMessages = [];
|
|
489
|
-
const allHandler = (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
510
|
+
const allHandler = async (msg) => {
|
|
511
|
+
if (msg.type !== 'event') {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const { message } = msg.event;
|
|
515
|
+
allMessages.push(await Message.getCid(message));
|
|
516
|
+
};
|
|
517
|
+
const allSubscription = await TestDataGenerator.generateMessagesSubscribe({
|
|
494
518
|
author: alice,
|
|
495
519
|
});
|
|
496
|
-
const allSubscriptionReply =
|
|
520
|
+
const allSubscriptionReply = await dwn.processMessage(alice.did, allSubscription.message, { subscriptionHandler: allHandler });
|
|
497
521
|
expect(allSubscriptionReply.status.code).toBe(200);
|
|
498
522
|
// we create an anonymous subscription to capture only published messages
|
|
499
523
|
const publishedMessages = [];
|
|
500
|
-
const anonymousSubscriptionHandler = (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
524
|
+
const anonymousSubscriptionHandler = async (msg) => {
|
|
525
|
+
if (msg.type !== 'event') {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const { message } = msg.event;
|
|
529
|
+
publishedMessages.push(await Message.getCid(message));
|
|
530
|
+
};
|
|
531
|
+
const anonymousSubscription = await TestDataGenerator.generateRecordsSubscribe({
|
|
505
532
|
anonymous: true,
|
|
506
533
|
filter: { schema: 'http://schema1' }
|
|
507
534
|
});
|
|
508
|
-
const anonymousSubscriptionReply =
|
|
535
|
+
const anonymousSubscriptionReply = await dwn.processMessage(alice.did, anonymousSubscription.message, {
|
|
509
536
|
subscriptionHandler: anonymousSubscriptionHandler
|
|
510
537
|
});
|
|
511
538
|
expect(anonymousSubscriptionReply.status.code).toBe(200);
|
|
512
539
|
expect(anonymousSubscriptionReply.subscription).toBeDefined();
|
|
513
540
|
// we create a non published record, this will only show up in the control subscription
|
|
514
|
-
const writeNotPublished =
|
|
515
|
-
const writeNotPublishedReply =
|
|
541
|
+
const writeNotPublished = await TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'http://schema1' });
|
|
542
|
+
const writeNotPublishedReply = await dwn.processMessage(alice.did, writeNotPublished.message, { dataStream: writeNotPublished.dataStream });
|
|
516
543
|
expect(writeNotPublishedReply.status.code).toBe(202);
|
|
517
544
|
// we create a published record, this will show up in both the control and anonymous subscription
|
|
518
|
-
const write1 =
|
|
519
|
-
const write1Reply =
|
|
545
|
+
const write1 = await TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'http://schema1', published: true });
|
|
546
|
+
const write1Reply = await dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
520
547
|
expect(write1Reply.status.code).toBe(202);
|
|
521
548
|
// we create another published record, this will show up in both the control and anonymous subscription
|
|
522
|
-
const write2 =
|
|
523
|
-
const write2Reply =
|
|
549
|
+
const write2 = await TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'http://schema1', published: true });
|
|
550
|
+
const write2Reply = await dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
524
551
|
expect(write2Reply.status.code).toBe(202);
|
|
525
|
-
|
|
552
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
526
553
|
// publishedMessages array should only contain the two published messages
|
|
527
554
|
expect(publishedMessages.length).toBe(2);
|
|
528
555
|
expect(publishedMessages).toEqual(expect.arrayContaining([
|
|
529
|
-
|
|
530
|
-
|
|
556
|
+
await Message.getCid(write1.message),
|
|
557
|
+
await Message.getCid(write2.message),
|
|
531
558
|
]));
|
|
532
559
|
// allMessages array should contain all three messages
|
|
533
560
|
expect(allMessages.length).toBe(3);
|
|
534
561
|
expect(allMessages).toEqual(expect.arrayContaining([
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
562
|
+
await Message.getCid(writeNotPublished.message),
|
|
563
|
+
await Message.getCid(write1.message),
|
|
564
|
+
await Message.getCid(write2.message),
|
|
538
565
|
]));
|
|
539
|
-
})
|
|
540
|
-
})
|
|
541
|
-
it('allows authorized subscriptions to records intended for a recipient', () =>
|
|
542
|
-
const alice =
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
it('allows authorized subscriptions to records intended for a recipient', async () => {
|
|
569
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
543
570
|
// alice installs a freeForAll protocol
|
|
544
|
-
const protocolConfigure =
|
|
571
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
545
572
|
author: alice,
|
|
546
|
-
protocolDefinition:
|
|
573
|
+
protocolDefinition: { ...freeForAll }
|
|
547
574
|
});
|
|
548
|
-
const protocolConfigureReply =
|
|
575
|
+
const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
549
576
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
550
|
-
const bob =
|
|
551
|
-
const carol =
|
|
577
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
578
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
552
579
|
// bob subscribes to all records he's authorized to see, with alice as the recipient
|
|
553
580
|
const bobSubscribeAlice = [];
|
|
554
|
-
const bobSubscribeHandler = (
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
581
|
+
const bobSubscribeHandler = async (msg) => {
|
|
582
|
+
if (msg.type !== 'event') {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const { message } = msg.event;
|
|
586
|
+
bobSubscribeAlice.push(await Message.getCid(message));
|
|
587
|
+
};
|
|
588
|
+
const bobSubscribeToAlice = await TestDataGenerator.generateRecordsSubscribe({
|
|
559
589
|
author: bob,
|
|
560
590
|
filter: { protocol: freeForAll.protocol, recipient: alice.did }
|
|
561
591
|
});
|
|
562
|
-
const bobSubscribeReply =
|
|
592
|
+
const bobSubscribeReply = await dwn.processMessage(alice.did, bobSubscribeToAlice.message, {
|
|
563
593
|
subscriptionHandler: bobSubscribeHandler
|
|
564
594
|
});
|
|
565
595
|
expect(bobSubscribeReply.status.code).toBe(200);
|
|
566
596
|
expect(bobSubscribeReply.subscription).toBeDefined();
|
|
567
597
|
// carol subscribes to any messages that she or alice are the recipients of
|
|
568
598
|
const carolSubscribeCarolAndAlice = [];
|
|
569
|
-
const carolSubscribeHandler = (
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
599
|
+
const carolSubscribeHandler = async (msg) => {
|
|
600
|
+
if (msg.type !== 'event') {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
const { message } = msg.event;
|
|
604
|
+
carolSubscribeCarolAndAlice.push(await Message.getCid(message));
|
|
605
|
+
};
|
|
606
|
+
const carolSubscribeToCarolAndAlice = await TestDataGenerator.generateRecordsSubscribe({
|
|
574
607
|
author: carol,
|
|
575
608
|
filter: { protocol: freeForAll.protocol, recipient: [alice.did, carol.did] }
|
|
576
609
|
});
|
|
577
|
-
const carolSubscribeReply =
|
|
610
|
+
const carolSubscribeReply = await dwn.processMessage(alice.did, carolSubscribeToCarolAndAlice.message, {
|
|
578
611
|
subscriptionHandler: carolSubscribeHandler
|
|
579
612
|
});
|
|
580
613
|
expect(carolSubscribeReply.status.code).toBe(200);
|
|
@@ -586,83 +619,114 @@ export function testSubscriptionScenarios() {
|
|
|
586
619
|
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
587
620
|
};
|
|
588
621
|
// write a private and public message for alice from bob
|
|
589
|
-
const publicBobToAlice =
|
|
590
|
-
|
|
622
|
+
const publicBobToAlice = await TestDataGenerator.generateRecordsWrite({
|
|
623
|
+
...recordParams,
|
|
624
|
+
author: bob,
|
|
625
|
+
recipient: alice.did,
|
|
626
|
+
published: true
|
|
627
|
+
});
|
|
628
|
+
const publicBobToAliceReply = await dwn.processMessage(alice.did, publicBobToAlice.message, { dataStream: publicBobToAlice.dataStream });
|
|
591
629
|
expect(publicBobToAliceReply.status.code).toBe(202);
|
|
592
|
-
const privateBobToAlice =
|
|
593
|
-
|
|
630
|
+
const privateBobToAlice = await TestDataGenerator.generateRecordsWrite({
|
|
631
|
+
...recordParams,
|
|
632
|
+
author: bob,
|
|
633
|
+
recipient: alice.did,
|
|
634
|
+
published: false
|
|
635
|
+
});
|
|
636
|
+
const privateBobToAliceReply = await dwn.processMessage(alice.did, privateBobToAlice.message, { dataStream: privateBobToAlice.dataStream });
|
|
594
637
|
expect(privateBobToAliceReply.status.code).toBe(202);
|
|
595
638
|
// write a private message for alice from carol
|
|
596
|
-
const privateCarolToAlice =
|
|
597
|
-
|
|
639
|
+
const privateCarolToAlice = await TestDataGenerator.generateRecordsWrite({
|
|
640
|
+
...recordParams,
|
|
641
|
+
author: carol,
|
|
642
|
+
recipient: alice.did,
|
|
643
|
+
published: false
|
|
644
|
+
});
|
|
645
|
+
const privateCarolToAliceReply = await dwn.processMessage(alice.did, privateCarolToAlice.message, {
|
|
598
646
|
dataStream: privateCarolToAlice.dataStream
|
|
599
647
|
});
|
|
600
648
|
expect(privateCarolToAliceReply.status.code).toBe(202);
|
|
601
649
|
// write a public and private message from bob to carol
|
|
602
|
-
const publicBobToCarol =
|
|
603
|
-
|
|
650
|
+
const publicBobToCarol = await TestDataGenerator.generateRecordsWrite({
|
|
651
|
+
...recordParams,
|
|
652
|
+
author: bob,
|
|
653
|
+
recipient: carol.did,
|
|
654
|
+
published: true
|
|
655
|
+
});
|
|
656
|
+
const publicBobToCarolReply = await dwn.processMessage(alice.did, publicBobToCarol.message, {
|
|
604
657
|
dataStream: publicBobToCarol.dataStream
|
|
605
658
|
});
|
|
606
659
|
expect(publicBobToCarolReply.status.code).toBe(202);
|
|
607
|
-
const privateBobToCarol =
|
|
608
|
-
|
|
660
|
+
const privateBobToCarol = await TestDataGenerator.generateRecordsWrite({
|
|
661
|
+
...recordParams,
|
|
662
|
+
author: bob,
|
|
663
|
+
recipient: carol.did,
|
|
664
|
+
published: false
|
|
665
|
+
});
|
|
666
|
+
const privateBobToCarolReply = await dwn.processMessage(alice.did, privateBobToCarol.message, {
|
|
609
667
|
dataStream: privateBobToCarol.dataStream
|
|
610
668
|
});
|
|
611
669
|
expect(privateBobToCarolReply.status.code).toBe(202);
|
|
612
|
-
|
|
670
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
613
671
|
// carol should have received the message intended for her
|
|
614
672
|
expect(carolSubscribeCarolAndAlice.length).toBe(4);
|
|
615
673
|
expect(carolSubscribeCarolAndAlice).toEqual(expect.arrayContaining([
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
674
|
+
await Message.getCid(publicBobToAlice.message),
|
|
675
|
+
await Message.getCid(privateCarolToAlice.message),
|
|
676
|
+
await Message.getCid(publicBobToCarol.message),
|
|
677
|
+
await Message.getCid(privateBobToCarol.message),
|
|
620
678
|
]));
|
|
621
679
|
// bob should have received the two messages intended for him
|
|
622
680
|
expect(bobSubscribeAlice.length).toBe(2);
|
|
623
681
|
expect(bobSubscribeAlice).toEqual(expect.arrayContaining([
|
|
624
|
-
|
|
625
|
-
|
|
682
|
+
await Message.getCid(privateBobToAlice.message),
|
|
683
|
+
await Message.getCid(publicBobToAlice.message),
|
|
626
684
|
]));
|
|
627
|
-
})
|
|
628
|
-
})
|
|
629
|
-
it('allows for authorized subscriptions to records authored by an author(s)', () =>
|
|
630
|
-
const alice =
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
it('allows for authorized subscriptions to records authored by an author(s)', async () => {
|
|
688
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
631
689
|
// alice installs a freeForAll protocol
|
|
632
|
-
const protocolConfigure =
|
|
690
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
633
691
|
author: alice,
|
|
634
|
-
protocolDefinition:
|
|
692
|
+
protocolDefinition: { ...freeForAll }
|
|
635
693
|
});
|
|
636
|
-
const protocolConfigureReply =
|
|
694
|
+
const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
637
695
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
638
|
-
const bob =
|
|
639
|
-
const carol =
|
|
696
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
697
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
640
698
|
// bob subscribes to all records he's authorized to see, with alice as the author
|
|
641
699
|
const bobSubscribeAlice = [];
|
|
642
|
-
const bobSubscribeHandler = (
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
700
|
+
const bobSubscribeHandler = async (msg) => {
|
|
701
|
+
if (msg.type !== 'event') {
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const { message } = msg.event;
|
|
705
|
+
bobSubscribeAlice.push(await Message.getCid(message));
|
|
706
|
+
};
|
|
707
|
+
const bobSubscribeToAlice = await TestDataGenerator.generateRecordsSubscribe({
|
|
647
708
|
author: bob,
|
|
648
709
|
filter: { protocol: freeForAll.protocol, author: alice.did }
|
|
649
710
|
});
|
|
650
|
-
const bobSubscribeReply =
|
|
711
|
+
const bobSubscribeReply = await dwn.processMessage(alice.did, bobSubscribeToAlice.message, {
|
|
651
712
|
subscriptionHandler: bobSubscribeHandler
|
|
652
713
|
});
|
|
653
714
|
expect(bobSubscribeReply.status.code).toBe(200);
|
|
654
715
|
expect(bobSubscribeReply.subscription).toBeDefined();
|
|
655
716
|
// carol subscribes to any messages that she or alice are the authors of
|
|
656
717
|
const carolSubscribeCarolAndAlice = [];
|
|
657
|
-
const carolSubscribeHandler = (
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
718
|
+
const carolSubscribeHandler = async (msg) => {
|
|
719
|
+
if (msg.type !== 'event') {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const { message } = msg.event;
|
|
723
|
+
carolSubscribeCarolAndAlice.push(await Message.getCid(message));
|
|
724
|
+
};
|
|
725
|
+
const carolSubscribeToCarolAndAlice = await TestDataGenerator.generateRecordsSubscribe({
|
|
662
726
|
author: carol,
|
|
663
727
|
filter: { protocol: freeForAll.protocol, author: [alice.did, carol.did] }
|
|
664
728
|
});
|
|
665
|
-
const carolSubscribeReply =
|
|
729
|
+
const carolSubscribeReply = await dwn.processMessage(alice.did, carolSubscribeToCarolAndAlice.message, {
|
|
666
730
|
subscriptionHandler: carolSubscribeHandler
|
|
667
731
|
});
|
|
668
732
|
expect(carolSubscribeReply.status.code).toBe(200);
|
|
@@ -674,57 +738,87 @@ export function testSubscriptionScenarios() {
|
|
|
674
738
|
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
675
739
|
};
|
|
676
740
|
//control: write a public message to bob (will not show up)
|
|
677
|
-
const publicAliceToBob =
|
|
678
|
-
|
|
741
|
+
const publicAliceToBob = await TestDataGenerator.generateRecordsWrite({
|
|
742
|
+
...recordParams,
|
|
743
|
+
author: alice,
|
|
744
|
+
recipient: bob.did,
|
|
745
|
+
published: true
|
|
746
|
+
});
|
|
747
|
+
const publicAliceToBobReply = await dwn.processMessage(alice.did, publicAliceToBob.message, {
|
|
679
748
|
dataStream: publicAliceToBob.dataStream
|
|
680
749
|
});
|
|
681
750
|
expect(publicAliceToBobReply.status.code).toBe(202);
|
|
682
751
|
// write a private and public message from alice to carol
|
|
683
|
-
const publicAliceToCarol =
|
|
684
|
-
|
|
752
|
+
const publicAliceToCarol = await TestDataGenerator.generateRecordsWrite({
|
|
753
|
+
...recordParams,
|
|
754
|
+
author: alice,
|
|
755
|
+
recipient: carol.did,
|
|
756
|
+
published: true
|
|
757
|
+
});
|
|
758
|
+
const publicAliceToCarolReply = await dwn.processMessage(alice.did, publicAliceToCarol.message, {
|
|
685
759
|
dataStream: publicAliceToCarol.dataStream
|
|
686
760
|
});
|
|
687
761
|
expect(publicAliceToCarolReply.status.code).toBe(202);
|
|
688
|
-
const privateAliceToCarol =
|
|
689
|
-
|
|
762
|
+
const privateAliceToCarol = await TestDataGenerator.generateRecordsWrite({
|
|
763
|
+
...recordParams,
|
|
764
|
+
author: alice,
|
|
765
|
+
recipient: carol.did,
|
|
766
|
+
published: false
|
|
767
|
+
});
|
|
768
|
+
const privateAliceToCarolReply = await dwn.processMessage(alice.did, privateAliceToCarol.message, {
|
|
690
769
|
dataStream: privateAliceToCarol.dataStream
|
|
691
770
|
});
|
|
692
771
|
expect(privateAliceToCarolReply.status.code).toBe(202);
|
|
693
772
|
// write a private message for alice from carol
|
|
694
|
-
const privateCarolToAlice =
|
|
695
|
-
|
|
773
|
+
const privateCarolToAlice = await TestDataGenerator.generateRecordsWrite({
|
|
774
|
+
...recordParams,
|
|
775
|
+
author: carol,
|
|
776
|
+
recipient: alice.did,
|
|
777
|
+
published: false
|
|
778
|
+
});
|
|
779
|
+
const privateCarolToAliceReply = await dwn.processMessage(alice.did, privateCarolToAlice.message, {
|
|
696
780
|
dataStream: privateCarolToAlice.dataStream
|
|
697
781
|
});
|
|
698
782
|
expect(privateCarolToAliceReply.status.code).toBe(202);
|
|
699
783
|
// write a public and private message from bob to carol
|
|
700
|
-
const publicBobToCarol =
|
|
701
|
-
|
|
784
|
+
const publicBobToCarol = await TestDataGenerator.generateRecordsWrite({
|
|
785
|
+
...recordParams,
|
|
786
|
+
author: bob,
|
|
787
|
+
recipient: carol.did,
|
|
788
|
+
published: true
|
|
789
|
+
});
|
|
790
|
+
const publicBobToCarolReply = await dwn.processMessage(alice.did, publicBobToCarol.message, {
|
|
702
791
|
dataStream: publicBobToCarol.dataStream
|
|
703
792
|
});
|
|
704
793
|
expect(publicBobToCarolReply.status.code).toBe(202);
|
|
705
|
-
const privateBobToCarol =
|
|
706
|
-
|
|
794
|
+
const privateBobToCarol = await TestDataGenerator.generateRecordsWrite({
|
|
795
|
+
...recordParams,
|
|
796
|
+
author: bob,
|
|
797
|
+
recipient: carol.did,
|
|
798
|
+
published: false
|
|
799
|
+
});
|
|
800
|
+
const privateBobToCarolReply = await dwn.processMessage(alice.did, privateBobToCarol.message, {
|
|
707
801
|
dataStream: privateBobToCarol.dataStream
|
|
708
802
|
});
|
|
709
803
|
expect(privateBobToCarolReply.status.code).toBe(202);
|
|
710
|
-
|
|
804
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
711
805
|
// carol should have received the message intended for her
|
|
712
806
|
expect(carolSubscribeCarolAndAlice.length).toBe(4);
|
|
713
807
|
expect(carolSubscribeCarolAndAlice).toEqual(expect.arrayContaining([
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
808
|
+
await Message.getCid(publicAliceToCarol.message),
|
|
809
|
+
await Message.getCid(privateAliceToCarol.message),
|
|
810
|
+
await Message.getCid(publicAliceToBob.message),
|
|
811
|
+
await Message.getCid(privateCarolToAlice.message),
|
|
718
812
|
]));
|
|
719
813
|
// bob should have received the two messages intended for him
|
|
720
814
|
expect(bobSubscribeAlice.length).toBe(2);
|
|
721
815
|
expect(bobSubscribeAlice).toEqual(expect.arrayContaining([
|
|
722
|
-
|
|
723
|
-
|
|
816
|
+
await Message.getCid(publicAliceToBob.message),
|
|
817
|
+
await Message.getCid(publicAliceToCarol.message)
|
|
724
818
|
]));
|
|
725
|
-
})
|
|
726
|
-
})
|
|
727
|
-
it('filters by protocol & contextId across multiple protocolPaths', () =>
|
|
819
|
+
});
|
|
820
|
+
});
|
|
821
|
+
it('filters by protocol & contextId across multiple protocolPaths', async () => {
|
|
728
822
|
// scenario: subscribe to multiple protocolPaths for a given protocol and contextId
|
|
729
823
|
// alice installs a protocol and creates a thread
|
|
730
824
|
// alice subscribes to update to that thread, it's participant as well as thread chats
|
|
@@ -732,99 +826,102 @@ export function testSubscriptionScenarios() {
|
|
|
732
826
|
// alice, bob, and carol all create messages
|
|
733
827
|
// alice deletes carol participant message
|
|
734
828
|
// alice checks that the correct messages were omitted
|
|
735
|
-
const alice =
|
|
736
|
-
const bob =
|
|
737
|
-
const carol =
|
|
829
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
830
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
831
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
738
832
|
// create protocol
|
|
739
|
-
const protocolConfigure =
|
|
833
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
740
834
|
author: alice,
|
|
741
|
-
protocolDefinition:
|
|
835
|
+
protocolDefinition: { ...threadProtocol }
|
|
742
836
|
});
|
|
743
|
-
const protocolConfigureReply =
|
|
837
|
+
const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
744
838
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
745
839
|
const protocol = protocolConfigure.message.descriptor.definition.protocol;
|
|
746
840
|
// alice creates thread
|
|
747
|
-
const thread =
|
|
841
|
+
const thread = await TestDataGenerator.generateRecordsWrite({
|
|
748
842
|
author: alice,
|
|
749
843
|
protocol: protocol,
|
|
750
844
|
protocolPath: 'thread'
|
|
751
845
|
});
|
|
752
|
-
const threadReply =
|
|
846
|
+
const threadReply = await dwn.processMessage(alice.did, thread.message, { dataStream: thread.dataStream });
|
|
753
847
|
expect(threadReply.status.code).toBe(202);
|
|
754
848
|
// subscribe to this thread's messages
|
|
755
849
|
const messages = [];
|
|
756
850
|
const initialWrites = [];
|
|
757
|
-
const subscriptionHandler = (
|
|
758
|
-
|
|
851
|
+
const subscriptionHandler = async (msg) => {
|
|
852
|
+
if (msg.type !== 'event') {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
const { message, initialWrite } = msg.event;
|
|
759
856
|
if (initialWrite !== undefined) {
|
|
760
|
-
initialWrites.push(
|
|
857
|
+
initialWrites.push(await Message.getCid(initialWrite));
|
|
761
858
|
}
|
|
762
|
-
messages.push(
|
|
763
|
-
}
|
|
764
|
-
const threadSubscription =
|
|
859
|
+
messages.push(await Message.getCid(message));
|
|
860
|
+
};
|
|
861
|
+
const threadSubscription = await TestDataGenerator.generateRecordsSubscribe({
|
|
765
862
|
author: alice,
|
|
766
863
|
filter: { protocol: protocol, protocolPath: 'thread', contextId: thread.message.contextId }, // thread updates
|
|
767
864
|
});
|
|
768
|
-
const threadSubscriptionReply =
|
|
865
|
+
const threadSubscriptionReply = await dwn.processMessage(alice.did, threadSubscription.message, {
|
|
769
866
|
subscriptionHandler
|
|
770
867
|
});
|
|
771
868
|
expect(threadSubscriptionReply.status.code).toBe(200);
|
|
772
869
|
expect(threadSubscriptionReply.subscription).toBeDefined();
|
|
773
|
-
const participantSubscription =
|
|
870
|
+
const participantSubscription = await TestDataGenerator.generateRecordsSubscribe({
|
|
774
871
|
author: alice,
|
|
775
872
|
filter: { protocol: protocol, protocolPath: 'thread/participant', contextId: thread.message.contextId }, // participant updates
|
|
776
873
|
});
|
|
777
|
-
const participantSubscriptionReply =
|
|
874
|
+
const participantSubscriptionReply = await dwn.processMessage(alice.did, participantSubscription.message, {
|
|
778
875
|
subscriptionHandler
|
|
779
876
|
});
|
|
780
877
|
expect(participantSubscriptionReply.status.code).toBe(200);
|
|
781
878
|
expect(participantSubscriptionReply.subscription).toBeDefined();
|
|
782
|
-
const chatSubscription =
|
|
879
|
+
const chatSubscription = await TestDataGenerator.generateRecordsSubscribe({
|
|
783
880
|
author: alice,
|
|
784
881
|
filter: { protocol: protocol, protocolPath: 'thread/chat', contextId: thread.message.contextId } // chat updates
|
|
785
882
|
});
|
|
786
|
-
const chatSubscriptionReply =
|
|
883
|
+
const chatSubscriptionReply = await dwn.processMessage(alice.did, chatSubscription.message, {
|
|
787
884
|
subscriptionHandler
|
|
788
885
|
});
|
|
789
886
|
expect(chatSubscriptionReply.status.code).toBe(200);
|
|
790
887
|
expect(chatSubscriptionReply.subscription).toBeDefined();
|
|
791
888
|
// add bob as participant
|
|
792
|
-
const bobParticipant =
|
|
889
|
+
const bobParticipant = await TestDataGenerator.generateRecordsWrite({
|
|
793
890
|
author: alice,
|
|
794
891
|
recipient: bob.did,
|
|
795
892
|
parentContextId: thread.message.contextId,
|
|
796
893
|
protocol: protocol,
|
|
797
894
|
protocolPath: 'thread/participant'
|
|
798
895
|
});
|
|
799
|
-
const bobParticipantReply =
|
|
896
|
+
const bobParticipantReply = await dwn.processMessage(alice.did, bobParticipant.message, { dataStream: bobParticipant.dataStream });
|
|
800
897
|
expect(bobParticipantReply.status.code).toBe(202);
|
|
801
898
|
// add carol as participant
|
|
802
|
-
const carolParticipant =
|
|
899
|
+
const carolParticipant = await TestDataGenerator.generateRecordsWrite({
|
|
803
900
|
author: alice,
|
|
804
901
|
recipient: carol.did,
|
|
805
902
|
parentContextId: thread.message.contextId,
|
|
806
903
|
protocol: protocol,
|
|
807
904
|
protocolPath: 'thread/participant'
|
|
808
905
|
});
|
|
809
|
-
const carolParticipantReply =
|
|
906
|
+
const carolParticipantReply = await dwn.processMessage(alice.did, carolParticipant.message, { dataStream: carolParticipant.dataStream });
|
|
810
907
|
expect(carolParticipantReply.status.code).toBe(202);
|
|
811
908
|
// add another thread as a control, will not show up in handled message events
|
|
812
|
-
const additionalThread =
|
|
909
|
+
const additionalThread = await TestDataGenerator.generateRecordsWrite({
|
|
813
910
|
author: alice,
|
|
814
911
|
protocol: protocol,
|
|
815
912
|
protocolPath: 'thread'
|
|
816
913
|
});
|
|
817
|
-
const additionalThreadReply =
|
|
914
|
+
const additionalThreadReply = await dwn.processMessage(alice.did, additionalThread.message, { dataStream: additionalThread.dataStream });
|
|
818
915
|
expect(additionalThreadReply.status.code).toBe(202);
|
|
819
|
-
|
|
916
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
820
917
|
expect(messages.length).toBe(2);
|
|
821
918
|
expect(messages).toEqual(expect.arrayContaining([
|
|
822
|
-
|
|
823
|
-
|
|
919
|
+
await Message.getCid(bobParticipant.message),
|
|
920
|
+
await Message.getCid(carolParticipant.message),
|
|
824
921
|
]));
|
|
825
|
-
})
|
|
922
|
+
});
|
|
826
923
|
// add a message to protocol1
|
|
827
|
-
const message1 =
|
|
924
|
+
const message1 = await TestDataGenerator.generateRecordsWrite({
|
|
828
925
|
author: bob,
|
|
829
926
|
recipient: alice.did,
|
|
830
927
|
parentContextId: thread.message.contextId,
|
|
@@ -832,9 +929,9 @@ export function testSubscriptionScenarios() {
|
|
|
832
929
|
protocolPath: 'thread/chat',
|
|
833
930
|
protocolRole: 'thread/participant',
|
|
834
931
|
});
|
|
835
|
-
const message1Reply =
|
|
932
|
+
const message1Reply = await dwn.processMessage(alice.did, message1.message, { dataStream: message1.dataStream });
|
|
836
933
|
expect(message1Reply.status.code).toBe(202);
|
|
837
|
-
const message2 =
|
|
934
|
+
const message2 = await TestDataGenerator.generateRecordsWrite({
|
|
838
935
|
author: bob,
|
|
839
936
|
recipient: alice.did,
|
|
840
937
|
parentContextId: thread.message.contextId,
|
|
@@ -842,9 +939,9 @@ export function testSubscriptionScenarios() {
|
|
|
842
939
|
protocolPath: 'thread/chat',
|
|
843
940
|
protocolRole: 'thread/participant',
|
|
844
941
|
});
|
|
845
|
-
const message2Reply =
|
|
942
|
+
const message2Reply = await dwn.processMessage(alice.did, message2.message, { dataStream: message2.dataStream });
|
|
846
943
|
expect(message2Reply.status.code).toBe(202);
|
|
847
|
-
const message3 =
|
|
944
|
+
const message3 = await TestDataGenerator.generateRecordsWrite({
|
|
848
945
|
author: carol,
|
|
849
946
|
recipient: alice.did,
|
|
850
947
|
parentContextId: thread.message.contextId,
|
|
@@ -852,34 +949,34 @@ export function testSubscriptionScenarios() {
|
|
|
852
949
|
protocolPath: 'thread/chat',
|
|
853
950
|
protocolRole: 'thread/participant',
|
|
854
951
|
});
|
|
855
|
-
const message3Reply =
|
|
952
|
+
const message3Reply = await dwn.processMessage(alice.did, message3.message, { dataStream: message3.dataStream });
|
|
856
953
|
expect(message3Reply.status.code).toBe(202);
|
|
857
|
-
|
|
954
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
858
955
|
expect(messages.length).toBe(5);
|
|
859
956
|
expect(messages).toEqual(expect.arrayContaining([
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
957
|
+
await Message.getCid(message1.message),
|
|
958
|
+
await Message.getCid(message2.message),
|
|
959
|
+
await Message.getCid(message3.message),
|
|
863
960
|
]));
|
|
864
|
-
})
|
|
961
|
+
});
|
|
865
962
|
// delete carol participant
|
|
866
|
-
const deleteCarol =
|
|
963
|
+
const deleteCarol = await TestDataGenerator.generateRecordsDelete({
|
|
867
964
|
author: alice,
|
|
868
965
|
recordId: carolParticipant.message.recordId
|
|
869
966
|
});
|
|
870
|
-
const deleteCarolReply =
|
|
967
|
+
const deleteCarolReply = await dwn.processMessage(alice.did, deleteCarol.message);
|
|
871
968
|
expect(deleteCarolReply.status.code).toBe(202);
|
|
872
|
-
|
|
969
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
873
970
|
expect(messages.length).toBe(6);
|
|
874
971
|
expect(messages).toEqual(expect.arrayContaining([
|
|
875
|
-
|
|
972
|
+
await Message.getCid(deleteCarol.message)
|
|
876
973
|
]));
|
|
877
974
|
// check the initial write was included with the delete
|
|
878
975
|
expect(initialWrites).toEqual(expect.arrayContaining([
|
|
879
|
-
|
|
976
|
+
await Message.getCid(carolParticipant.message)
|
|
880
977
|
]));
|
|
881
|
-
})
|
|
882
|
-
})
|
|
978
|
+
});
|
|
979
|
+
});
|
|
883
980
|
});
|
|
884
981
|
});
|
|
885
982
|
}
|