@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,19 +1,10 @@
|
|
|
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 messageProtocolDefinition from '../vectors/protocol-definitions/message.json' with { type: 'json' };
|
|
11
2
|
import nestedProtocolDefinition from '../vectors/protocol-definitions/nested.json' with { type: 'json' };
|
|
12
3
|
import sinon from 'sinon';
|
|
13
4
|
import { DwnInterfaceName } from '../../src/enums/dwn-interface-method.js';
|
|
14
5
|
import { Message } from '../../src/core/message.js';
|
|
15
6
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
16
|
-
import {
|
|
7
|
+
import { TestEventLog } from '../test-event-stream.js';
|
|
17
8
|
import { TestStores } from '../test-stores.js';
|
|
18
9
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
19
10
|
import { DataStream, Dwn, DwnConstant, DwnErrorCode, Jws, ProtocolsConfigure, RecordsDelete, RecordsQuery, RecordsWrite, SortDirection } from '../../src/index.js';
|
|
@@ -25,41 +16,40 @@ export function testRecordsPrune() {
|
|
|
25
16
|
let dataStore;
|
|
26
17
|
let resumableTaskStore;
|
|
27
18
|
let stateIndex;
|
|
28
|
-
let
|
|
19
|
+
let eventLog;
|
|
29
20
|
let dwn;
|
|
30
21
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
31
22
|
// so that different test suites can reuse the same backend store for testing
|
|
32
|
-
beforeAll(() =>
|
|
23
|
+
beforeAll(async () => {
|
|
33
24
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
34
25
|
const stores = TestStores.get();
|
|
35
26
|
messageStore = stores.messageStore;
|
|
36
27
|
dataStore = stores.dataStore;
|
|
37
28
|
resumableTaskStore = stores.resumableTaskStore;
|
|
38
29
|
stateIndex = stores.stateIndex;
|
|
39
|
-
|
|
40
|
-
dwn =
|
|
41
|
-
})
|
|
42
|
-
beforeEach(() =>
|
|
30
|
+
eventLog = TestEventLog.get();
|
|
31
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, resumableTaskStore });
|
|
32
|
+
});
|
|
33
|
+
beforeEach(async () => {
|
|
43
34
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
44
35
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
afterAll(() =>
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
it('should prune all descendants when given RecordsDelete with `prune` set to `true`', () =>
|
|
54
|
-
|
|
55
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
36
|
+
await messageStore.clear();
|
|
37
|
+
await dataStore.clear();
|
|
38
|
+
await resumableTaskStore.clear();
|
|
39
|
+
await stateIndex.clear();
|
|
40
|
+
});
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
await dwn.close();
|
|
43
|
+
});
|
|
44
|
+
it('should prune all descendants when given RecordsDelete with `prune` set to `true`', async () => {
|
|
45
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
56
46
|
// install a protocol with foo <- bar <- baz structure
|
|
57
47
|
const nestedProtocol = nestedProtocolDefinition;
|
|
58
|
-
const protocolsConfig =
|
|
48
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
59
49
|
definition: nestedProtocol,
|
|
60
50
|
signer: Jws.createSigner(alice)
|
|
61
51
|
});
|
|
62
|
-
const protocolsConfigureReply =
|
|
52
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
63
53
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
64
54
|
// writes 2 foos, 2 bars under foo1, and 2 bazes under bar1
|
|
65
55
|
// write 2 foos
|
|
@@ -72,11 +62,11 @@ export function testRecordsPrune() {
|
|
|
72
62
|
dataFormat: nestedProtocol.types.foo.dataFormats[0],
|
|
73
63
|
data: fooData
|
|
74
64
|
};
|
|
75
|
-
const foo1 =
|
|
76
|
-
const foo1WriteResponse =
|
|
65
|
+
const foo1 = await RecordsWrite.create(fooOptions);
|
|
66
|
+
const foo1WriteResponse = await dwn.processMessage(alice.did, foo1.message, { dataStream: DataStream.fromBytes(fooData) });
|
|
77
67
|
expect(foo1WriteResponse.status.code).toBe(202);
|
|
78
|
-
const foo2 =
|
|
79
|
-
const foo2WriteResponse =
|
|
68
|
+
const foo2 = await RecordsWrite.create(fooOptions);
|
|
69
|
+
const foo2WriteResponse = await dwn.processMessage(alice.did, foo2.message, { dataStream: DataStream.fromBytes(fooData) });
|
|
80
70
|
expect(foo2WriteResponse.status.code).toBe(202);
|
|
81
71
|
// write 2 bars under foo1 with data large enough to be required to be stored in the data store so we can test purge in data store
|
|
82
72
|
const barData = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1);
|
|
@@ -89,11 +79,11 @@ export function testRecordsPrune() {
|
|
|
89
79
|
parentContextId: foo1.message.contextId,
|
|
90
80
|
data: barData
|
|
91
81
|
};
|
|
92
|
-
const bar1 =
|
|
93
|
-
const bar1WriteResponse =
|
|
82
|
+
const bar1 = await RecordsWrite.create({ ...barOptions });
|
|
83
|
+
const bar1WriteResponse = await dwn.processMessage(alice.did, bar1.message, { dataStream: DataStream.fromBytes(barData) });
|
|
94
84
|
expect(bar1WriteResponse.status.code).toBe(202);
|
|
95
|
-
const bar2 =
|
|
96
|
-
const bar2WriteResponse =
|
|
85
|
+
const bar2 = await RecordsWrite.create({ ...barOptions });
|
|
86
|
+
const bar2WriteResponse = await dwn.processMessage(alice.did, bar2.message, { dataStream: DataStream.fromBytes(barData) });
|
|
97
87
|
expect(bar2WriteResponse.status.code).toBe(202);
|
|
98
88
|
// write 2 bazes under bar1, each has more than 1 message associated with the record so we can test multi-message purge
|
|
99
89
|
const bazData = TestDataGenerator.randomBytes(100);
|
|
@@ -106,95 +96,94 @@ export function testRecordsPrune() {
|
|
|
106
96
|
parentContextId: bar1.message.contextId,
|
|
107
97
|
data: bazData
|
|
108
98
|
};
|
|
109
|
-
const baz1 =
|
|
110
|
-
const baz1WriteResponse =
|
|
99
|
+
const baz1 = await RecordsWrite.create({ ...bazOptions });
|
|
100
|
+
const baz1WriteResponse = await dwn.processMessage(alice.did, baz1.message, { dataStream: DataStream.fromBytes(bazData) });
|
|
111
101
|
expect(baz1WriteResponse.status.code).toBe(202);
|
|
112
|
-
const baz2 =
|
|
113
|
-
const baz2WriteResponse =
|
|
102
|
+
const baz2 = await RecordsWrite.create({ ...bazOptions });
|
|
103
|
+
const baz2WriteResponse = await dwn.processMessage(alice.did, baz2.message, { dataStream: DataStream.fromBytes(bazData) });
|
|
114
104
|
expect(baz2WriteResponse.status.code).toBe(202);
|
|
115
105
|
// make latest state of baz1 a `RecordsWrite`
|
|
116
106
|
const newBaz1Data = TestDataGenerator.randomBytes(100);
|
|
117
|
-
const baz1Update =
|
|
107
|
+
const baz1Update = await RecordsWrite.createFrom({
|
|
118
108
|
signer: Jws.createSigner(alice),
|
|
119
109
|
recordsWriteMessage: baz1.message,
|
|
120
110
|
data: newBaz1Data
|
|
121
111
|
});
|
|
122
|
-
const baz1UpdateResponse =
|
|
112
|
+
const baz1UpdateResponse = await dwn.processMessage(alice.did, baz1Update.message, { dataStream: DataStream.fromBytes(newBaz1Data) });
|
|
123
113
|
expect(baz1UpdateResponse.status.code).toBe(202);
|
|
124
114
|
// make latest state of baz2 a `RecordsDelete`
|
|
125
|
-
const baz2Delete =
|
|
115
|
+
const baz2Delete = await RecordsDelete.create({
|
|
126
116
|
signer: Jws.createSigner(alice),
|
|
127
117
|
recordId: baz2.message.recordId
|
|
128
118
|
});
|
|
129
|
-
const baz2DeleteResponse =
|
|
119
|
+
const baz2DeleteResponse = await dwn.processMessage(alice.did, baz2Delete.message);
|
|
130
120
|
expect(baz2DeleteResponse.status.code).toBe(202);
|
|
131
121
|
// sanity test messages are inserted in message store
|
|
132
122
|
const queryFilter = [{
|
|
133
123
|
interface: DwnInterfaceName.Records,
|
|
134
124
|
protocol: nestedProtocol.protocol
|
|
135
125
|
}];
|
|
136
|
-
const queryResult =
|
|
126
|
+
const queryResult = await messageStore.query(alice.did, queryFilter);
|
|
137
127
|
expect(queryResult.messages.length).toBe(8); // 2 foos, 2 bars, 2 bazes x 2 messages each
|
|
138
128
|
// sanity test events are inserted in state index
|
|
139
129
|
// NOTE: getLeaves returns ALL messageCids (including ProtocolsConfigure), so count is 9 not 8
|
|
140
|
-
const events =
|
|
130
|
+
const events = await stateIndex.getLeaves(alice.did, []);
|
|
141
131
|
expect(events.length).toBe(9);
|
|
142
132
|
// sanity test data is inserted in data store
|
|
143
|
-
const bar1DataGetResult =
|
|
144
|
-
const bar2DataGetResult =
|
|
133
|
+
const bar1DataGetResult = await dataStore.get(alice.did, bar1.message.recordId, bar1.message.descriptor.dataCid);
|
|
134
|
+
const bar2DataGetResult = await dataStore.get(alice.did, bar2.message.recordId, bar2.message.descriptor.dataCid);
|
|
145
135
|
expect(bar1DataGetResult).toBeDefined();
|
|
146
136
|
expect(bar2DataGetResult).toBeDefined();
|
|
147
137
|
// Delete foo1 with prune enabled
|
|
148
|
-
const foo1Delete =
|
|
138
|
+
const foo1Delete = await RecordsDelete.create({
|
|
149
139
|
recordId: foo1.message.recordId,
|
|
150
140
|
prune: true,
|
|
151
141
|
signer: Jws.createSigner(alice)
|
|
152
142
|
});
|
|
153
|
-
const deleteReply =
|
|
143
|
+
const deleteReply = await dwn.processMessage(alice.did, foo1Delete.message);
|
|
154
144
|
expect(deleteReply.status.code).toBe(202);
|
|
155
145
|
// verify all bar and baz message are permanently deleted
|
|
156
|
-
const queryResult2 =
|
|
146
|
+
const queryResult2 = await messageStore.query(alice.did, queryFilter, { messageTimestamp: SortDirection.Ascending });
|
|
157
147
|
expect(queryResult2.messages.length).toBe(3); // foo2 RecordsWrite, foo1 RecordsWrite and RecordsDelete
|
|
158
148
|
expect(queryResult2.messages[0]).toEqual(expect.objectContaining(foo1.message));
|
|
159
149
|
expect(queryResult2.messages[1]).toEqual(expect.objectContaining(foo2.message));
|
|
160
150
|
expect(queryResult2.messages[2]).toEqual(expect.objectContaining(foo1Delete.message));
|
|
161
151
|
// verify all bar and baz events are permanently deleted
|
|
162
152
|
// NOTE: getLeaves returns ALL messageCids (including ProtocolsConfigure), so count is 4 not 3
|
|
163
|
-
const events2 =
|
|
153
|
+
const events2 = await stateIndex.getLeaves(alice.did, []);
|
|
164
154
|
expect(events2.length).toBe(4);
|
|
165
|
-
const foo1RecordsWriteCid =
|
|
166
|
-
const foo2RecordsWriteCid =
|
|
167
|
-
const foo2RecordsDeleteCid =
|
|
155
|
+
const foo1RecordsWriteCid = await Message.getCid(foo1.message);
|
|
156
|
+
const foo2RecordsWriteCid = await Message.getCid(foo2.message);
|
|
157
|
+
const foo2RecordsDeleteCid = await Message.getCid(foo1Delete.message);
|
|
168
158
|
expect(events2).toEqual(expect.arrayContaining([foo1RecordsWriteCid, foo2RecordsWriteCid, foo2RecordsDeleteCid]));
|
|
169
159
|
// verify all bar data are permanently deleted
|
|
170
|
-
const bar1DataGetResult2 =
|
|
171
|
-
const bar2DataGetResult2 =
|
|
160
|
+
const bar1DataGetResult2 = await dataStore.get(alice.did, bar1.message.recordId, bar1.message.descriptor.dataCid);
|
|
161
|
+
const bar2DataGetResult2 = await dataStore.get(alice.did, bar2.message.recordId, bar2.message.descriptor.dataCid);
|
|
172
162
|
expect(bar1DataGetResult2).toBeUndefined();
|
|
173
163
|
expect(bar2DataGetResult2).toBeUndefined();
|
|
174
164
|
// sanity test an external query will no longer return the deleted records
|
|
175
|
-
const queryData =
|
|
165
|
+
const queryData = await RecordsQuery.create({
|
|
176
166
|
signer: Jws.createSigner(alice),
|
|
177
167
|
filter: { protocol: nestedProtocol.protocol }
|
|
178
168
|
});
|
|
179
|
-
const reply2 =
|
|
169
|
+
const reply2 = await dwn.processMessage(alice.did, queryData.message);
|
|
180
170
|
expect(reply2.status.code).toBe(200);
|
|
181
|
-
expect(
|
|
171
|
+
expect(reply2.entries?.length).toBe(1); // only foo2 is left
|
|
182
172
|
expect(reply2.entries[0]).toEqual(expect.objectContaining(foo2.message));
|
|
183
|
-
})
|
|
184
|
-
it('should allow pruning against a deleted record that is not already pruned', () =>
|
|
173
|
+
});
|
|
174
|
+
it('should allow pruning against a deleted record that is not already pruned', async () => {
|
|
185
175
|
// Scenario:
|
|
186
176
|
// 1. Alice has a record `foo` with a descendent chain
|
|
187
177
|
// 2. Alice deletes the record `foo` WITHOUT prune, leaving the descendants intact
|
|
188
178
|
// 3. Verify that Alice is able to perform a prune on `foo` to delete all its descendants
|
|
189
|
-
|
|
190
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
179
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
191
180
|
// install a protocol with foo <- bar <- baz structure
|
|
192
181
|
const nestedProtocol = nestedProtocolDefinition;
|
|
193
|
-
const protocolsConfig =
|
|
182
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
194
183
|
definition: nestedProtocol,
|
|
195
184
|
signer: Jws.createSigner(alice)
|
|
196
185
|
});
|
|
197
|
-
const protocolsConfigureReply =
|
|
186
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
198
187
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
199
188
|
// 1. Alice has a record `foo` with a descendent chain
|
|
200
189
|
// write foo <- bar <- baz records
|
|
@@ -207,8 +196,8 @@ export function testRecordsPrune() {
|
|
|
207
196
|
dataFormat: nestedProtocol.types.foo.dataFormats[0],
|
|
208
197
|
data: fooData
|
|
209
198
|
};
|
|
210
|
-
const foo =
|
|
211
|
-
const fooWriteResponse =
|
|
199
|
+
const foo = await RecordsWrite.create(fooOptions);
|
|
200
|
+
const fooWriteResponse = await dwn.processMessage(alice.did, foo.message, { dataStream: DataStream.fromBytes(fooData) });
|
|
212
201
|
expect(fooWriteResponse.status.code).toBe(202);
|
|
213
202
|
const barData = TestDataGenerator.randomBytes(100);
|
|
214
203
|
const barOptions = {
|
|
@@ -220,8 +209,8 @@ export function testRecordsPrune() {
|
|
|
220
209
|
parentContextId: foo.message.contextId,
|
|
221
210
|
data: barData
|
|
222
211
|
};
|
|
223
|
-
const bar =
|
|
224
|
-
const barWriteResponse =
|
|
212
|
+
const bar = await RecordsWrite.create({ ...barOptions });
|
|
213
|
+
const barWriteResponse = await dwn.processMessage(alice.did, bar.message, { dataStream: DataStream.fromBytes(barData) });
|
|
225
214
|
expect(barWriteResponse.status.code).toBe(202);
|
|
226
215
|
const bazData = TestDataGenerator.randomBytes(100);
|
|
227
216
|
const bazOptions = {
|
|
@@ -233,71 +222,70 @@ export function testRecordsPrune() {
|
|
|
233
222
|
parentContextId: bar.message.contextId,
|
|
234
223
|
data: bazData
|
|
235
224
|
};
|
|
236
|
-
const baz =
|
|
237
|
-
const bazWriteResponse =
|
|
225
|
+
const baz = await RecordsWrite.create({ ...bazOptions });
|
|
226
|
+
const bazWriteResponse = await dwn.processMessage(alice.did, baz.message, { dataStream: DataStream.fromBytes(bazData) });
|
|
238
227
|
expect(bazWriteResponse.status.code).toBe(202);
|
|
239
228
|
// sanity records are inserted in message store
|
|
240
229
|
const queryFilter = [{
|
|
241
230
|
interface: DwnInterfaceName.Records,
|
|
242
231
|
protocol: nestedProtocol.protocol
|
|
243
232
|
}];
|
|
244
|
-
const messagesBeforeDelete =
|
|
233
|
+
const messagesBeforeDelete = await messageStore.query(alice.did, queryFilter);
|
|
245
234
|
expect(messagesBeforeDelete.messages.length).toBe(3);
|
|
246
235
|
// sanity verify RecordsQuery returns no records
|
|
247
|
-
const recordsQuery =
|
|
236
|
+
const recordsQuery = await RecordsQuery.create({
|
|
248
237
|
signer: Jws.createSigner(alice),
|
|
249
238
|
filter: { protocol: nestedProtocol.protocol }
|
|
250
239
|
});
|
|
251
|
-
const recordsQueryBeforeDeleteReply =
|
|
240
|
+
const recordsQueryBeforeDeleteReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
252
241
|
expect(recordsQueryBeforeDeleteReply.status.code).toBe(200);
|
|
253
|
-
expect(
|
|
242
|
+
expect(recordsQueryBeforeDeleteReply.entries?.length).toBe(3);
|
|
254
243
|
// 2. Alice deletes the record `foo` WITHOUT prune, leaving the descendants intact
|
|
255
|
-
const fooDelete =
|
|
244
|
+
const fooDelete = await RecordsDelete.create({
|
|
256
245
|
recordId: foo.message.recordId,
|
|
257
246
|
// prune : true, // intentionally showing that this is a RecordsDelete WITHOUT pruning
|
|
258
247
|
signer: Jws.createSigner(alice)
|
|
259
248
|
});
|
|
260
|
-
const deleteReply =
|
|
249
|
+
const deleteReply = await dwn.processMessage(alice.did, fooDelete.message);
|
|
261
250
|
expect(deleteReply.status.code).toBe(202);
|
|
262
251
|
// verify bar and baz messages still exists
|
|
263
|
-
const messagesAfterDelete =
|
|
252
|
+
const messagesAfterDelete = await messageStore.query(alice.did, queryFilter, { messageTimestamp: SortDirection.Ascending });
|
|
264
253
|
expect(messagesAfterDelete.messages.length).toBe(4); // RecordsWrite for foo, bar, baz, and RecordsDelete for foo
|
|
265
254
|
// sanity verify RecordsQuery returns the descendants
|
|
266
|
-
const recordsQueryAfterDeleteReply =
|
|
255
|
+
const recordsQueryAfterDeleteReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
267
256
|
expect(recordsQueryAfterDeleteReply.status.code).toBe(200);
|
|
268
|
-
expect(
|
|
257
|
+
expect(recordsQueryAfterDeleteReply.entries?.length).toBe(2);
|
|
269
258
|
// 3. Verify that Alice is able to perform a prune on `foo` to delete all its descendants
|
|
270
|
-
const fooPrune =
|
|
259
|
+
const fooPrune = await RecordsDelete.create({
|
|
271
260
|
recordId: foo.message.recordId,
|
|
272
261
|
prune: true,
|
|
273
262
|
signer: Jws.createSigner(alice)
|
|
274
263
|
});
|
|
275
|
-
const pruneReply =
|
|
264
|
+
const pruneReply = await dwn.processMessage(alice.did, fooPrune.message);
|
|
276
265
|
expect(pruneReply.status.code).toBe(202);
|
|
277
266
|
// verify bar and baz messages are permanently deleted
|
|
278
|
-
const messagesAfterPrune =
|
|
267
|
+
const messagesAfterPrune = await messageStore.query(alice.did, queryFilter, { messageTimestamp: SortDirection.Ascending });
|
|
279
268
|
expect(messagesAfterPrune.messages.length).toBe(2); // just RecordsWrite and RecordsDelete for foo
|
|
280
269
|
expect(messagesAfterPrune.messages[0]).toEqual(expect.objectContaining(foo.message));
|
|
281
270
|
expect(messagesAfterPrune.messages[1]).toEqual(expect.objectContaining(fooPrune.message));
|
|
282
271
|
// sanity verify RecordsQuery returns no records
|
|
283
|
-
const recordsQueryAfterPruneReply =
|
|
272
|
+
const recordsQueryAfterPruneReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
284
273
|
expect(recordsQueryAfterPruneReply.status.code).toBe(200);
|
|
285
|
-
expect(
|
|
286
|
-
})
|
|
287
|
-
it('should return 404 when attempting to prune against a record that is already pruned', () =>
|
|
274
|
+
expect(recordsQueryAfterPruneReply.entries?.length).toBe(0);
|
|
275
|
+
});
|
|
276
|
+
it('should return 404 when attempting to prune against a record that is already pruned', async () => {
|
|
288
277
|
// Scenario:
|
|
289
278
|
// 1. Alice has a record `foo` with a descendent chain
|
|
290
279
|
// 2. Alice prunes the record `foo`
|
|
291
280
|
// 3. Verify that Alice is unable to perform a prune on `foo` again
|
|
292
|
-
|
|
293
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
281
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
294
282
|
// install a protocol with foo <- bar <- baz structure
|
|
295
283
|
const nestedProtocol = nestedProtocolDefinition;
|
|
296
|
-
const protocolsConfig =
|
|
284
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
297
285
|
definition: nestedProtocol,
|
|
298
286
|
signer: Jws.createSigner(alice)
|
|
299
287
|
});
|
|
300
|
-
const protocolsConfigureReply =
|
|
288
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
301
289
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
302
290
|
// 1. Alice has a record `foo` with a descendent chain
|
|
303
291
|
// write foo <- bar <- baz records
|
|
@@ -310,8 +298,8 @@ export function testRecordsPrune() {
|
|
|
310
298
|
dataFormat: nestedProtocol.types.foo.dataFormats[0],
|
|
311
299
|
data: fooData
|
|
312
300
|
};
|
|
313
|
-
const foo =
|
|
314
|
-
const fooWriteResponse =
|
|
301
|
+
const foo = await RecordsWrite.create(fooOptions);
|
|
302
|
+
const fooWriteResponse = await dwn.processMessage(alice.did, foo.message, { dataStream: DataStream.fromBytes(fooData) });
|
|
315
303
|
expect(fooWriteResponse.status.code).toBe(202);
|
|
316
304
|
const barData = TestDataGenerator.randomBytes(100);
|
|
317
305
|
const barOptions = {
|
|
@@ -323,8 +311,8 @@ export function testRecordsPrune() {
|
|
|
323
311
|
parentContextId: foo.message.contextId,
|
|
324
312
|
data: barData
|
|
325
313
|
};
|
|
326
|
-
const bar =
|
|
327
|
-
const barWriteResponse =
|
|
314
|
+
const bar = await RecordsWrite.create({ ...barOptions });
|
|
315
|
+
const barWriteResponse = await dwn.processMessage(alice.did, bar.message, { dataStream: DataStream.fromBytes(barData) });
|
|
328
316
|
expect(barWriteResponse.status.code).toBe(202);
|
|
329
317
|
const bazData = TestDataGenerator.randomBytes(100);
|
|
330
318
|
const bazOptions = {
|
|
@@ -336,51 +324,50 @@ export function testRecordsPrune() {
|
|
|
336
324
|
parentContextId: bar.message.contextId,
|
|
337
325
|
data: bazData
|
|
338
326
|
};
|
|
339
|
-
const baz =
|
|
340
|
-
const bazWriteResponse =
|
|
327
|
+
const baz = await RecordsWrite.create({ ...bazOptions });
|
|
328
|
+
const bazWriteResponse = await dwn.processMessage(alice.did, baz.message, { dataStream: DataStream.fromBytes(bazData) });
|
|
341
329
|
expect(bazWriteResponse.status.code).toBe(202);
|
|
342
330
|
// sanity records are inserted in message store
|
|
343
331
|
const queryFilter = [{
|
|
344
332
|
interface: DwnInterfaceName.Records,
|
|
345
333
|
protocol: nestedProtocol.protocol
|
|
346
334
|
}];
|
|
347
|
-
const queryResult =
|
|
335
|
+
const queryResult = await messageStore.query(alice.did, queryFilter);
|
|
348
336
|
expect(queryResult.messages.length).toBe(3);
|
|
349
337
|
// sanity verify RecordsQuery returns no records
|
|
350
|
-
const recordsQuery =
|
|
338
|
+
const recordsQuery = await RecordsQuery.create({
|
|
351
339
|
signer: Jws.createSigner(alice),
|
|
352
340
|
filter: { protocol: nestedProtocol.protocol }
|
|
353
341
|
});
|
|
354
|
-
const recordsQueryBeforeDeleteReply =
|
|
342
|
+
const recordsQueryBeforeDeleteReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
355
343
|
expect(recordsQueryBeforeDeleteReply.status.code).toBe(200);
|
|
356
|
-
expect(
|
|
344
|
+
expect(recordsQueryBeforeDeleteReply.entries?.length).toBe(3);
|
|
357
345
|
// 2. Alice prunes the record `foo`
|
|
358
|
-
const fooPrune1 =
|
|
346
|
+
const fooPrune1 = await RecordsDelete.create({
|
|
359
347
|
recordId: foo.message.recordId,
|
|
360
348
|
prune: true,
|
|
361
349
|
signer: Jws.createSigner(alice)
|
|
362
350
|
});
|
|
363
|
-
const prune1Reply =
|
|
351
|
+
const prune1Reply = await dwn.processMessage(alice.did, fooPrune1.message);
|
|
364
352
|
expect(prune1Reply.status.code).toBe(202);
|
|
365
353
|
// 3. Verify that Alice is unable to perform a prune on `foo` again
|
|
366
|
-
const fooPrune2 =
|
|
354
|
+
const fooPrune2 = await RecordsDelete.create({
|
|
367
355
|
recordId: foo.message.recordId,
|
|
368
356
|
prune: true,
|
|
369
357
|
signer: Jws.createSigner(alice)
|
|
370
358
|
});
|
|
371
|
-
const prune2Reply =
|
|
359
|
+
const prune2Reply = await dwn.processMessage(alice.did, fooPrune2.message);
|
|
372
360
|
expect(prune2Reply.status.code).toBe(404);
|
|
373
|
-
})
|
|
361
|
+
});
|
|
374
362
|
describe('prune and co-prune protocol action', () => {
|
|
375
|
-
it('should only allow a non-owner author to prune if `prune` is allowed and set to `true` in RecordsDelete', () =>
|
|
363
|
+
it('should only allow a non-owner author to prune if `prune` is allowed and set to `true` in RecordsDelete', async () => {
|
|
376
364
|
// Scenario:
|
|
377
365
|
// 1. Alice installs a protocol allowing others to add and prune records.
|
|
378
366
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
379
367
|
// 3. Verify Bob cannot prune the records if `prune` is not set to `true` in RecordsDelete.
|
|
380
368
|
// 4. Verify Bob can prune the records by setting `prune` to `true` in RecordsDelete.
|
|
381
|
-
|
|
382
|
-
const
|
|
383
|
-
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
369
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
370
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
384
371
|
// 1. Alice installs a protocol allowing others to add and prune records.
|
|
385
372
|
const protocolDefinition = {
|
|
386
373
|
protocol: 'http://post-protocol.xyz',
|
|
@@ -417,11 +404,11 @@ export function testRecordsPrune() {
|
|
|
417
404
|
}
|
|
418
405
|
}
|
|
419
406
|
};
|
|
420
|
-
const protocolsConfig =
|
|
407
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
421
408
|
definition: protocolDefinition,
|
|
422
409
|
signer: Jws.createSigner(alice)
|
|
423
410
|
});
|
|
424
|
-
const protocolsConfigureReply =
|
|
411
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
425
412
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
426
413
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
427
414
|
const postData = TestDataGenerator.randomBytes(100);
|
|
@@ -432,8 +419,8 @@ export function testRecordsPrune() {
|
|
|
432
419
|
dataFormat: 'application/json',
|
|
433
420
|
data: postData
|
|
434
421
|
};
|
|
435
|
-
const post =
|
|
436
|
-
const postWriteResponse =
|
|
422
|
+
const post = await RecordsWrite.create(postOptions);
|
|
423
|
+
const postWriteResponse = await dwn.processMessage(alice.did, post.message, { dataStream: DataStream.fromBytes(postData) });
|
|
437
424
|
expect(postWriteResponse.status.code).toBe(202);
|
|
438
425
|
const attachmentData = TestDataGenerator.randomBytes(100);
|
|
439
426
|
const attachmentOptions = {
|
|
@@ -444,50 +431,49 @@ export function testRecordsPrune() {
|
|
|
444
431
|
dataFormat: 'application/octet-stream',
|
|
445
432
|
data: attachmentData
|
|
446
433
|
};
|
|
447
|
-
const attachment =
|
|
448
|
-
const attachmentWriteResponse =
|
|
434
|
+
const attachment = await RecordsWrite.create(attachmentOptions);
|
|
435
|
+
const attachmentWriteResponse = await dwn.processMessage(alice.did, attachment.message, { dataStream: DataStream.fromBytes(attachmentData) });
|
|
449
436
|
expect(attachmentWriteResponse.status.code).toBe(202);
|
|
450
437
|
// 3. Verify Bob cannot prune the records if `prune` is not set to `true` in RecordsDelete.
|
|
451
|
-
const unauthorizedPostPrune =
|
|
438
|
+
const unauthorizedPostPrune = await RecordsDelete.create({
|
|
452
439
|
recordId: post.message.recordId,
|
|
453
440
|
// prune : true, // intentionally not setting `prune` to true
|
|
454
441
|
signer: Jws.createSigner(bob)
|
|
455
442
|
});
|
|
456
|
-
const unauthorizedPostPruneReply =
|
|
443
|
+
const unauthorizedPostPruneReply = await dwn.processMessage(alice.did, unauthorizedPostPrune.message);
|
|
457
444
|
expect(unauthorizedPostPruneReply.status.code).toBe(401);
|
|
458
445
|
expect(unauthorizedPostPruneReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
459
446
|
// 4. Verify Bob can prune the records by setting `prune` to `true` in RecordsDelete.
|
|
460
|
-
const postPrune =
|
|
447
|
+
const postPrune = await RecordsDelete.create({
|
|
461
448
|
recordId: post.message.recordId,
|
|
462
449
|
prune: true,
|
|
463
450
|
signer: Jws.createSigner(bob)
|
|
464
451
|
});
|
|
465
|
-
const pruneReply =
|
|
452
|
+
const pruneReply = await dwn.processMessage(alice.did, postPrune.message);
|
|
466
453
|
expect(pruneReply.status.code).toBe(202);
|
|
467
454
|
// sanity test `RecordsQuery` no longer returns the deleted record
|
|
468
|
-
const recordsQuery =
|
|
455
|
+
const recordsQuery = await RecordsQuery.create({
|
|
469
456
|
signer: Jws.createSigner(bob),
|
|
470
457
|
filter: { protocol: protocolDefinition.protocol }
|
|
471
458
|
});
|
|
472
|
-
const recordsQueryReply =
|
|
459
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
473
460
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
474
|
-
expect(
|
|
475
|
-
})
|
|
476
|
-
it('should not allow a non-owner author to prune if `prune` is not an authorized action', () =>
|
|
461
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
462
|
+
});
|
|
463
|
+
it('should not allow a non-owner author to prune if `prune` is not an authorized action', async () => {
|
|
477
464
|
// Scenario:
|
|
478
465
|
// 1. Alice installs a protocol allowing others to add records but not prune.
|
|
479
466
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
480
467
|
// 3. Verify Bob cannot prune the records.
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
468
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
469
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
484
470
|
// 1. Alice installs a protocol allowing others to add records but not prune.
|
|
485
471
|
const protocolDefinition = messageProtocolDefinition;
|
|
486
|
-
const protocolsConfig =
|
|
472
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
487
473
|
definition: protocolDefinition,
|
|
488
474
|
signer: Jws.createSigner(alice)
|
|
489
475
|
});
|
|
490
|
-
const protocolsConfigureReply =
|
|
476
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
491
477
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
492
478
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
493
479
|
const messageData = TestDataGenerator.randomBytes(100);
|
|
@@ -499,8 +485,8 @@ export function testRecordsPrune() {
|
|
|
499
485
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
500
486
|
data: messageData
|
|
501
487
|
};
|
|
502
|
-
const message =
|
|
503
|
-
const messageWriteResponse =
|
|
488
|
+
const message = await RecordsWrite.create(messageOptions);
|
|
489
|
+
const messageWriteResponse = await dwn.processMessage(alice.did, message.message, { dataStream: DataStream.fromBytes(messageData) });
|
|
504
490
|
expect(messageWriteResponse.status.code).toBe(202);
|
|
505
491
|
const attachmentData = TestDataGenerator.randomBytes(100);
|
|
506
492
|
const attachmentOptions = {
|
|
@@ -511,37 +497,36 @@ export function testRecordsPrune() {
|
|
|
511
497
|
dataFormat: 'application/octet-stream',
|
|
512
498
|
data: attachmentData
|
|
513
499
|
};
|
|
514
|
-
const attachment =
|
|
515
|
-
const attachmentWriteResponse =
|
|
500
|
+
const attachment = await RecordsWrite.create(attachmentOptions);
|
|
501
|
+
const attachmentWriteResponse = await dwn.processMessage(alice.did, attachment.message, { dataStream: DataStream.fromBytes(attachmentData) });
|
|
516
502
|
expect(attachmentWriteResponse.status.code).toBe(202);
|
|
517
503
|
// 3. Verify Bob cannot prune the records.
|
|
518
|
-
const messagePrune =
|
|
504
|
+
const messagePrune = await RecordsDelete.create({
|
|
519
505
|
recordId: message.message.recordId,
|
|
520
506
|
prune: true,
|
|
521
507
|
signer: Jws.createSigner(bob)
|
|
522
508
|
});
|
|
523
|
-
const deleteReply =
|
|
509
|
+
const deleteReply = await dwn.processMessage(alice.did, messagePrune.message);
|
|
524
510
|
expect(deleteReply.status.code).toBe(401);
|
|
525
511
|
expect(deleteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
526
512
|
// sanity test `RecordsQuery` still returns the records
|
|
527
|
-
const recordsQuery =
|
|
513
|
+
const recordsQuery = await RecordsQuery.create({
|
|
528
514
|
signer: Jws.createSigner(alice),
|
|
529
515
|
filter: { protocol: protocolDefinition.protocol }
|
|
530
516
|
});
|
|
531
|
-
const recordsQueryReply =
|
|
517
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
532
518
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
533
|
-
expect(
|
|
534
|
-
})
|
|
535
|
-
it('should allow a non-author to prune if `co-prune` is allowed and `prune` is set to `true` in RecordsDelete', () =>
|
|
519
|
+
expect(recordsQueryReply.entries?.length).toBe(2);
|
|
520
|
+
});
|
|
521
|
+
it('should allow a non-author to prune if `co-prune` is allowed and `prune` is set to `true` in RecordsDelete', async () => {
|
|
536
522
|
// Scenario:
|
|
537
523
|
// 1. Alice installs a protocol allowing others to add and prune records.
|
|
538
524
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
539
525
|
// 3. Verify Carol cannot prune the records if `prune` is not set to `true` in RecordsDelete.
|
|
540
526
|
// 4. Verify Carol can prune the records by setting `prune` to `true` in RecordsDelete.
|
|
541
|
-
|
|
542
|
-
const
|
|
543
|
-
const
|
|
544
|
-
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
527
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
528
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
529
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
545
530
|
// 1. Alice installs a protocol allowing others to add and prune records.
|
|
546
531
|
const protocolDefinition = {
|
|
547
532
|
protocol: 'http://post-protocol.xyz',
|
|
@@ -576,11 +561,11 @@ export function testRecordsPrune() {
|
|
|
576
561
|
}
|
|
577
562
|
}
|
|
578
563
|
};
|
|
579
|
-
const protocolsConfig =
|
|
564
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
580
565
|
definition: protocolDefinition,
|
|
581
566
|
signer: Jws.createSigner(alice)
|
|
582
567
|
});
|
|
583
|
-
const protocolsConfigureReply =
|
|
568
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
584
569
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
585
570
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
586
571
|
const postData = TestDataGenerator.randomBytes(100);
|
|
@@ -591,8 +576,8 @@ export function testRecordsPrune() {
|
|
|
591
576
|
dataFormat: 'application/json',
|
|
592
577
|
data: postData
|
|
593
578
|
};
|
|
594
|
-
const post =
|
|
595
|
-
const postWriteResponse =
|
|
579
|
+
const post = await RecordsWrite.create(postOptions);
|
|
580
|
+
const postWriteResponse = await dwn.processMessage(alice.did, post.message, { dataStream: DataStream.fromBytes(postData) });
|
|
596
581
|
expect(postWriteResponse.status.code).toBe(202);
|
|
597
582
|
const attachmentData = TestDataGenerator.randomBytes(100);
|
|
598
583
|
const attachmentOptions = {
|
|
@@ -603,44 +588,43 @@ export function testRecordsPrune() {
|
|
|
603
588
|
dataFormat: 'application/octet-stream',
|
|
604
589
|
data: attachmentData
|
|
605
590
|
};
|
|
606
|
-
const attachment =
|
|
607
|
-
const attachmentWriteResponse =
|
|
591
|
+
const attachment = await RecordsWrite.create(attachmentOptions);
|
|
592
|
+
const attachmentWriteResponse = await dwn.processMessage(alice.did, attachment.message, { dataStream: DataStream.fromBytes(attachmentData) });
|
|
608
593
|
expect(attachmentWriteResponse.status.code).toBe(202);
|
|
609
594
|
// 3. Verify Carol cannot prune the records if `prune` is not set to `true` in RecordsDelete.
|
|
610
|
-
const unauthorizedPostPrune =
|
|
595
|
+
const unauthorizedPostPrune = await RecordsDelete.create({
|
|
611
596
|
recordId: post.message.recordId,
|
|
612
597
|
// prune : true, // intentionally not setting `prune` to true
|
|
613
598
|
signer: Jws.createSigner(carol)
|
|
614
599
|
});
|
|
615
|
-
const unauthorizedPostPruneReply =
|
|
600
|
+
const unauthorizedPostPruneReply = await dwn.processMessage(alice.did, unauthorizedPostPrune.message);
|
|
616
601
|
expect(unauthorizedPostPruneReply.status.code).toBe(401);
|
|
617
602
|
expect(unauthorizedPostPruneReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
618
603
|
// 4. Verify Carol can prune the records by setting `prune` to `true` in RecordsDelete.
|
|
619
|
-
const postPrune =
|
|
604
|
+
const postPrune = await RecordsDelete.create({
|
|
620
605
|
recordId: post.message.recordId,
|
|
621
606
|
prune: true,
|
|
622
607
|
signer: Jws.createSigner(carol)
|
|
623
608
|
});
|
|
624
|
-
const deleteReply =
|
|
609
|
+
const deleteReply = await dwn.processMessage(alice.did, postPrune.message);
|
|
625
610
|
expect(deleteReply.status.code).toBe(202);
|
|
626
611
|
// sanity test `RecordsQuery` no longer returns the deleted record
|
|
627
|
-
const recordsQuery =
|
|
612
|
+
const recordsQuery = await RecordsQuery.create({
|
|
628
613
|
signer: Jws.createSigner(bob),
|
|
629
614
|
filter: { protocol: protocolDefinition.protocol }
|
|
630
615
|
});
|
|
631
|
-
const recordsQueryReply =
|
|
616
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
632
617
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
633
|
-
expect(
|
|
634
|
-
})
|
|
635
|
-
it('should not allow a non-author to prune if `prune` is allowed but `co-prune` is not allowed', () =>
|
|
618
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
619
|
+
});
|
|
620
|
+
it('should not allow a non-author to prune if `prune` is allowed but `co-prune` is not allowed', async () => {
|
|
636
621
|
// Scenario:
|
|
637
622
|
// 1. Alice installs a protocol allowing others to add records AND only author to prune.
|
|
638
623
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
639
624
|
// 3. Verify Carol cannot prune the records.
|
|
640
|
-
|
|
641
|
-
const
|
|
642
|
-
const
|
|
643
|
-
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
625
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
626
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
627
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
644
628
|
// 1. Alice installs a protocol allowing others to add records AND only author to prune.
|
|
645
629
|
const protocolDefinition = {
|
|
646
630
|
protocol: 'http://post-protocol.xyz',
|
|
@@ -677,11 +661,11 @@ export function testRecordsPrune() {
|
|
|
677
661
|
}
|
|
678
662
|
}
|
|
679
663
|
};
|
|
680
|
-
const protocolsConfig =
|
|
664
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
681
665
|
definition: protocolDefinition,
|
|
682
666
|
signer: Jws.createSigner(alice)
|
|
683
667
|
});
|
|
684
|
-
const protocolsConfigureReply =
|
|
668
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
685
669
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
686
670
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
687
671
|
const postData = TestDataGenerator.randomBytes(100);
|
|
@@ -692,8 +676,8 @@ export function testRecordsPrune() {
|
|
|
692
676
|
dataFormat: 'application/json',
|
|
693
677
|
data: postData
|
|
694
678
|
};
|
|
695
|
-
const post =
|
|
696
|
-
const postWriteResponse =
|
|
679
|
+
const post = await RecordsWrite.create(postOptions);
|
|
680
|
+
const postWriteResponse = await dwn.processMessage(alice.did, post.message, { dataStream: DataStream.fromBytes(postData) });
|
|
697
681
|
expect(postWriteResponse.status.code).toBe(202);
|
|
698
682
|
const attachmentData = TestDataGenerator.randomBytes(100);
|
|
699
683
|
const attachmentOptions = {
|
|
@@ -704,34 +688,34 @@ export function testRecordsPrune() {
|
|
|
704
688
|
dataFormat: 'application/octet-stream',
|
|
705
689
|
data: attachmentData
|
|
706
690
|
};
|
|
707
|
-
const attachment =
|
|
708
|
-
const attachmentWriteResponse =
|
|
691
|
+
const attachment = await RecordsWrite.create(attachmentOptions);
|
|
692
|
+
const attachmentWriteResponse = await dwn.processMessage(alice.did, attachment.message, { dataStream: DataStream.fromBytes(attachmentData) });
|
|
709
693
|
expect(attachmentWriteResponse.status.code).toBe(202);
|
|
710
694
|
// 3. Verify Carol cannot prune the records.
|
|
711
|
-
const postPrune =
|
|
695
|
+
const postPrune = await RecordsDelete.create({
|
|
712
696
|
recordId: post.message.recordId,
|
|
713
697
|
prune: true,
|
|
714
698
|
signer: Jws.createSigner(carol)
|
|
715
699
|
});
|
|
716
|
-
const deleteReply =
|
|
700
|
+
const deleteReply = await dwn.processMessage(alice.did, postPrune.message);
|
|
717
701
|
expect(deleteReply.status.code).toBe(401);
|
|
718
702
|
expect(deleteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
719
703
|
// sanity test `RecordsQuery` still returns the records
|
|
720
|
-
const recordsQuery =
|
|
704
|
+
const recordsQuery = await RecordsQuery.create({
|
|
721
705
|
signer: Jws.createSigner(bob),
|
|
722
706
|
filter: { protocol: protocolDefinition.protocol }
|
|
723
707
|
});
|
|
724
|
-
const recordsQueryReply =
|
|
708
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
725
709
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
726
|
-
expect(
|
|
727
|
-
})
|
|
728
|
-
it('should throw if only `delete` is allowed but received a RecordsDelete with `prune` set to `true`', () =>
|
|
710
|
+
expect(recordsQueryReply.entries?.length).toBe(2);
|
|
711
|
+
});
|
|
712
|
+
it('should throw if only `delete` is allowed but received a RecordsDelete with `prune` set to `true`', async () => {
|
|
729
713
|
// Scenario:
|
|
730
714
|
// 1. Alice installs a protocol allowing others to add and delete (not prune) records.
|
|
731
715
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
732
716
|
// 3. Verify Bob cannot prune the records.
|
|
733
|
-
const alice =
|
|
734
|
-
const bob =
|
|
717
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
718
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
735
719
|
// 1. Alice installs a protocol allowing others to add and delete (not prune) records.
|
|
736
720
|
const protocolDefinition = {
|
|
737
721
|
protocol: 'http://post-protocol.xyz',
|
|
@@ -766,11 +750,11 @@ export function testRecordsPrune() {
|
|
|
766
750
|
}
|
|
767
751
|
}
|
|
768
752
|
};
|
|
769
|
-
const protocolsConfig =
|
|
753
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
770
754
|
definition: protocolDefinition,
|
|
771
755
|
signer: Jws.createSigner(alice)
|
|
772
756
|
});
|
|
773
|
-
const protocolsConfigureReply =
|
|
757
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
774
758
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
775
759
|
// 2. Bob writes a record + a descendant in Alice's DWN.
|
|
776
760
|
const postData = TestDataGenerator.randomBytes(100);
|
|
@@ -781,8 +765,8 @@ export function testRecordsPrune() {
|
|
|
781
765
|
dataFormat: 'application/json',
|
|
782
766
|
data: postData
|
|
783
767
|
};
|
|
784
|
-
const post =
|
|
785
|
-
const postWriteResponse =
|
|
768
|
+
const post = await RecordsWrite.create(postOptions);
|
|
769
|
+
const postWriteResponse = await dwn.processMessage(alice.did, post.message, { dataStream: DataStream.fromBytes(postData) });
|
|
786
770
|
expect(postWriteResponse.status.code).toBe(202);
|
|
787
771
|
const attachmentData = TestDataGenerator.randomBytes(100);
|
|
788
772
|
const attachmentOptions = {
|
|
@@ -793,21 +777,21 @@ export function testRecordsPrune() {
|
|
|
793
777
|
dataFormat: 'application/octet-stream',
|
|
794
778
|
data: attachmentData
|
|
795
779
|
};
|
|
796
|
-
const attachment =
|
|
797
|
-
const attachmentWriteResponse =
|
|
780
|
+
const attachment = await RecordsWrite.create(attachmentOptions);
|
|
781
|
+
const attachmentWriteResponse = await dwn.processMessage(alice.did, attachment.message, { dataStream: DataStream.fromBytes(attachmentData) });
|
|
798
782
|
expect(attachmentWriteResponse.status.code).toBe(202);
|
|
799
783
|
// 3. Verify Bob cannot prune the records.
|
|
800
|
-
const unauthorizedPostPrune =
|
|
784
|
+
const unauthorizedPostPrune = await RecordsDelete.create({
|
|
801
785
|
recordId: post.message.recordId,
|
|
802
786
|
prune: true,
|
|
803
787
|
signer: Jws.createSigner(bob)
|
|
804
788
|
});
|
|
805
|
-
const unauthorizedPostPruneReply =
|
|
789
|
+
const unauthorizedPostPruneReply = await dwn.processMessage(alice.did, unauthorizedPostPrune.message);
|
|
806
790
|
expect(unauthorizedPostPruneReply.status.code).toBe(401);
|
|
807
791
|
expect(unauthorizedPostPruneReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
808
|
-
})
|
|
809
|
-
it('should not allow creation of a protocol definition with action rule containing `prune` without `create`', () =>
|
|
810
|
-
const alice =
|
|
792
|
+
});
|
|
793
|
+
it('should not allow creation of a protocol definition with action rule containing `prune` without `create`', async () => {
|
|
794
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
811
795
|
const protocolDefinition = {
|
|
812
796
|
protocol: 'http://prune-without-create.xyz',
|
|
813
797
|
published: true,
|
|
@@ -829,9 +813,9 @@ export function testRecordsPrune() {
|
|
|
829
813
|
definition: protocolDefinition,
|
|
830
814
|
signer: Jws.createSigner(alice)
|
|
831
815
|
});
|
|
832
|
-
|
|
816
|
+
await expect(protocolsConfigureCreatePromise)
|
|
833
817
|
.rejects.toThrow(DwnErrorCode.ProtocolsConfigureInvalidActionPruneWithoutCreate);
|
|
834
|
-
})
|
|
818
|
+
});
|
|
835
819
|
});
|
|
836
820
|
});
|
|
837
821
|
}
|