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