@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,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 dexProtocolDefinition from '../vectors/protocol-definitions/dex.json' with { type: 'json' };
|
|
11
2
|
import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' with { type: 'json' };
|
|
12
3
|
import sinon from 'sinon';
|
|
@@ -15,7 +6,7 @@ import { lexicographicalCompare } from '../../src/utils/string.js';
|
|
|
15
6
|
import { Message } from '../../src/core/message.js';
|
|
16
7
|
import { ProtocolAction } from '../../src/types/protocols-types.js';
|
|
17
8
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
18
|
-
import {
|
|
9
|
+
import { TestEventLog } from '../test-event-stream.js';
|
|
19
10
|
import { TestStores } from '../test-stores.js';
|
|
20
11
|
import { TestStubGenerator } from '../utils/test-stub-generator.js';
|
|
21
12
|
import { Time } from '../../src/utils/time.js';
|
|
@@ -29,202 +20,209 @@ export function testProtocolsConfigureHandler() {
|
|
|
29
20
|
let dataStore;
|
|
30
21
|
let resumableTaskStore;
|
|
31
22
|
let stateIndex;
|
|
32
|
-
let
|
|
23
|
+
let eventLog;
|
|
33
24
|
let dwn;
|
|
34
25
|
describe('functional tests', () => {
|
|
35
26
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
36
27
|
// so that different test suites can reuse the same backend store for testing
|
|
37
|
-
beforeAll(() =>
|
|
28
|
+
beforeAll(async () => {
|
|
38
29
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
39
30
|
const stores = TestStores.get();
|
|
40
31
|
messageStore = stores.messageStore;
|
|
41
32
|
dataStore = stores.dataStore;
|
|
42
33
|
resumableTaskStore = stores.resumableTaskStore;
|
|
43
34
|
stateIndex = stores.stateIndex;
|
|
44
|
-
|
|
45
|
-
dwn =
|
|
46
|
-
})
|
|
47
|
-
beforeEach(() =>
|
|
35
|
+
eventLog = TestEventLog.get();
|
|
36
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, resumableTaskStore });
|
|
37
|
+
});
|
|
38
|
+
beforeEach(async () => {
|
|
48
39
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
49
40
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
afterAll(() =>
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
it('should allow a protocol definition with schema or dataFormat omitted', () =>
|
|
59
|
-
const alice =
|
|
41
|
+
await messageStore.clear();
|
|
42
|
+
await dataStore.clear();
|
|
43
|
+
await resumableTaskStore.clear();
|
|
44
|
+
await stateIndex.clear();
|
|
45
|
+
});
|
|
46
|
+
afterAll(async () => {
|
|
47
|
+
await dwn.close();
|
|
48
|
+
});
|
|
49
|
+
it('should allow a protocol definition with schema or dataFormat omitted', async () => {
|
|
50
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
60
51
|
const protocolDefinition = minimalProtocolDefinition;
|
|
61
|
-
const protocolsConfig =
|
|
52
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
62
53
|
author: alice,
|
|
63
54
|
protocolDefinition,
|
|
64
55
|
});
|
|
65
|
-
const reply =
|
|
56
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
66
57
|
expect(reply.status.code).toBe(202);
|
|
67
|
-
})
|
|
68
|
-
it('should return 400 if more than 1 signature is provided in `authorization`', () =>
|
|
69
|
-
const { author, message, protocolsConfigure } =
|
|
58
|
+
});
|
|
59
|
+
it('should return 400 if more than 1 signature is provided in `authorization`', async () => {
|
|
60
|
+
const { author, message, protocolsConfigure } = await TestDataGenerator.generateProtocolsConfigure();
|
|
70
61
|
const tenant = author.did;
|
|
71
62
|
// intentionally create more than one signature, which is not allowed
|
|
72
|
-
const extraRandomPersona =
|
|
63
|
+
const extraRandomPersona = await TestDataGenerator.generatePersona();
|
|
73
64
|
const signer1 = Jws.createSigner(author);
|
|
74
65
|
const signer2 = Jws.createSigner(extraRandomPersona);
|
|
75
66
|
const signaturePayloadBytes = Encoder.objectToBytes(protocolsConfigure.signaturePayload);
|
|
76
|
-
const jwsBuilder =
|
|
67
|
+
const jwsBuilder = await GeneralJwsBuilder.create(signaturePayloadBytes, [signer1, signer2]);
|
|
77
68
|
message.authorization = { signature: jwsBuilder.getJws() };
|
|
78
69
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
79
|
-
const reply =
|
|
70
|
+
const reply = await dwn.processMessage(tenant, message);
|
|
80
71
|
expect(reply.status.code).toBe(400);
|
|
81
72
|
expect(reply.status.detail).toContain('expected no more than 1 signature');
|
|
82
|
-
})
|
|
83
|
-
it('should return 401 if auth fails', () =>
|
|
84
|
-
const alice =
|
|
85
|
-
const { message } =
|
|
73
|
+
});
|
|
74
|
+
it('should return 401 if auth fails', async () => {
|
|
75
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
76
|
+
const { message } = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
86
77
|
// use a bad signature to fail authentication
|
|
87
|
-
const badSignature =
|
|
78
|
+
const badSignature = await TestDataGenerator.randomSignatureString();
|
|
88
79
|
message.authorization.signature.signatures[0].signature = badSignature;
|
|
89
|
-
const reply =
|
|
80
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
90
81
|
expect(reply.status.code).toBe(401);
|
|
91
82
|
expect(reply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
|
|
92
|
-
})
|
|
93
|
-
it('should store all protocol versions and query should only return the latest', () =>
|
|
94
|
-
|
|
95
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
83
|
+
});
|
|
84
|
+
it('should store all protocol versions and query should only return the latest', async () => {
|
|
85
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
96
86
|
const protocolDefinition = minimalProtocolDefinition;
|
|
97
|
-
const oldProtocolsConfigure =
|
|
87
|
+
const oldProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
98
88
|
author: alice,
|
|
99
89
|
protocolDefinition,
|
|
100
90
|
});
|
|
101
|
-
|
|
102
|
-
const middleProtocolsConfigure =
|
|
91
|
+
await Time.minimalSleep();
|
|
92
|
+
const middleProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
103
93
|
author: alice,
|
|
104
94
|
protocolDefinition,
|
|
105
95
|
});
|
|
106
96
|
// first ProtocolsConfigure
|
|
107
|
-
const reply1 =
|
|
97
|
+
const reply1 = await dwn.processMessage(alice.did, middleProtocolsConfigure.message);
|
|
108
98
|
expect(reply1.status.code).toBe(202);
|
|
109
99
|
// older messages are also accepted (stored as historical versions)
|
|
110
|
-
const reply2 =
|
|
100
|
+
const reply2 = await dwn.processMessage(alice.did, oldProtocolsConfigure.message);
|
|
111
101
|
expect(reply2.status.code).toBe(202);
|
|
112
102
|
// newer message is also accepted and becomes the latest
|
|
113
|
-
const newProtocolsConfigure =
|
|
103
|
+
const newProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
114
104
|
author: alice,
|
|
115
105
|
protocolDefinition,
|
|
116
106
|
});
|
|
117
|
-
const reply3 =
|
|
107
|
+
const reply3 = await dwn.processMessage(alice.did, newProtocolsConfigure.message);
|
|
118
108
|
expect(reply3.status.code).toBe(202);
|
|
119
109
|
// only the newest protocol should be returned by query (ProtocolsQuery returns only latest)
|
|
120
|
-
const queryMessageData =
|
|
110
|
+
const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
|
|
121
111
|
author: alice,
|
|
122
112
|
filter: { protocol: protocolDefinition.protocol }
|
|
123
113
|
});
|
|
124
|
-
const queryReply =
|
|
114
|
+
const queryReply = await dwn.processMessage(alice.did, queryMessageData.message);
|
|
125
115
|
expect(queryReply.status.code).toBe(200);
|
|
126
|
-
expect(
|
|
127
|
-
})
|
|
128
|
-
it('should store all protocol versions with identical timestamps and query should only return the newest (by CID tiebreak)', () =>
|
|
129
|
-
|
|
130
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
116
|
+
expect(queryReply.entries?.length).toBe(1);
|
|
117
|
+
});
|
|
118
|
+
it('should store all protocol versions with identical timestamps and query should only return the newest (by CID tiebreak)', async () => {
|
|
119
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
131
120
|
// Alter each protocol slightly to create lexicographic difference between them
|
|
132
|
-
const protocolDefinition1 =
|
|
133
|
-
|
|
134
|
-
|
|
121
|
+
const protocolDefinition1 = {
|
|
122
|
+
...minimalProtocolDefinition,
|
|
123
|
+
types: { ...minimalProtocolDefinition.types, foo1: { dataFormats: ['bar1'] } }
|
|
124
|
+
};
|
|
125
|
+
const protocolDefinition2 = {
|
|
126
|
+
...minimalProtocolDefinition,
|
|
127
|
+
types: { ...minimalProtocolDefinition.types, foo2: { dataFormats: ['bar2'] } }
|
|
128
|
+
};
|
|
129
|
+
const protocolDefinition3 = {
|
|
130
|
+
...minimalProtocolDefinition,
|
|
131
|
+
types: { ...minimalProtocolDefinition.types, foo3: { dataFormats: ['bar3'] } }
|
|
132
|
+
};
|
|
135
133
|
// Create three `ProtocolsConfigure` with identical timestamp
|
|
136
|
-
const messageData1 =
|
|
134
|
+
const messageData1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
137
135
|
author: alice,
|
|
138
136
|
protocolDefinition: protocolDefinition1
|
|
139
137
|
});
|
|
140
|
-
const messageData2 =
|
|
138
|
+
const messageData2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
141
139
|
author: alice,
|
|
142
140
|
protocolDefinition: protocolDefinition2,
|
|
143
141
|
messageTimestamp: messageData1.message.descriptor.messageTimestamp
|
|
144
142
|
});
|
|
145
|
-
const messageData3 =
|
|
143
|
+
const messageData3 = await TestDataGenerator.generateProtocolsConfigure({
|
|
146
144
|
author: alice,
|
|
147
145
|
protocolDefinition: protocolDefinition3,
|
|
148
146
|
messageTimestamp: messageData1.message.descriptor.messageTimestamp
|
|
149
147
|
});
|
|
150
148
|
const messageDataWithCid = [];
|
|
151
149
|
for (const messageData of [messageData1, messageData2, messageData3]) {
|
|
152
|
-
const cid =
|
|
153
|
-
messageDataWithCid.push(
|
|
150
|
+
const cid = await Message.getCid(messageData.message);
|
|
151
|
+
messageDataWithCid.push({ cid, ...messageData });
|
|
154
152
|
}
|
|
155
153
|
// sort the message in lexicographic order
|
|
156
154
|
const [lowestProtocolsConfigure, middleProtocolsConfigure, highestProtocolsConfigure] = messageDataWithCid.sort((messageDataA, messageDataB) => { return lexicographicalCompare(messageDataA.cid, messageDataB.cid); });
|
|
157
155
|
// write the protocol with the middle lexicographic value
|
|
158
|
-
const reply1 =
|
|
156
|
+
const reply1 = await dwn.processMessage(alice.did, middleProtocolsConfigure.message);
|
|
159
157
|
expect(reply1.status.code).toBe(202);
|
|
160
158
|
// all versions are accepted (stored as historical versions)
|
|
161
|
-
const reply2 =
|
|
159
|
+
const reply2 = await dwn.processMessage(alice.did, lowestProtocolsConfigure.message);
|
|
162
160
|
expect(reply2.status.code).toBe(202);
|
|
163
161
|
// highest lexicographic value is also accepted and becomes the latest
|
|
164
|
-
const reply3 =
|
|
162
|
+
const reply3 = await dwn.processMessage(alice.did, highestProtocolsConfigure.message);
|
|
165
163
|
expect(reply3.status.code).toBe(202);
|
|
166
164
|
// query should only return the latest protocol definition (highest by CID tiebreak)
|
|
167
|
-
const queryMessageData =
|
|
165
|
+
const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
|
|
168
166
|
author: alice,
|
|
169
167
|
filter: { protocol: protocolDefinition1.protocol }
|
|
170
168
|
});
|
|
171
|
-
const queryReply =
|
|
169
|
+
const queryReply = await dwn.processMessage(alice.did, queryMessageData.message);
|
|
172
170
|
expect(queryReply.status.code).toBe(200);
|
|
173
|
-
expect(
|
|
174
|
-
})
|
|
175
|
-
it('should return 400 if protocol is not normalized', () =>
|
|
176
|
-
const alice =
|
|
171
|
+
expect(queryReply.entries?.length).toBe(1);
|
|
172
|
+
});
|
|
173
|
+
it('should return 400 if protocol is not normalized', async () => {
|
|
174
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
177
175
|
// query for non-normalized protocol
|
|
178
|
-
const protocolsConfig =
|
|
176
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
179
177
|
author: alice,
|
|
180
178
|
protocolDefinition: minimalProtocolDefinition
|
|
181
179
|
});
|
|
182
180
|
// overwrite protocol because #create auto-normalizes protocol
|
|
183
181
|
protocolsConfig.message.descriptor.definition.protocol = 'example.com/';
|
|
184
182
|
// Re-create auth because we altered the descriptor after signing
|
|
185
|
-
protocolsConfig.message.authorization =
|
|
183
|
+
protocolsConfig.message.authorization = await Message.createAuthorization({
|
|
186
184
|
descriptor: protocolsConfig.message.descriptor,
|
|
187
185
|
signer: Jws.createSigner(alice)
|
|
188
186
|
});
|
|
189
187
|
// Send records write message
|
|
190
|
-
const reply =
|
|
188
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
191
189
|
expect(reply.status.code).toBe(400);
|
|
192
190
|
expect(reply.status.detail).toContain(DwnErrorCode.UrlProtocolNotNormalized);
|
|
193
|
-
})
|
|
194
|
-
it('should return 400 if schema is not normalized', () =>
|
|
195
|
-
const alice =
|
|
191
|
+
});
|
|
192
|
+
it('should return 400 if schema is not normalized', async () => {
|
|
193
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
196
194
|
const protocolDefinition = dexProtocolDefinition;
|
|
197
|
-
const protocolsConfig =
|
|
195
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
198
196
|
author: alice,
|
|
199
197
|
protocolDefinition,
|
|
200
198
|
});
|
|
201
199
|
// overwrite schema because #create auto-normalizes schema
|
|
202
200
|
protocolsConfig.message.descriptor.definition.types.ask.schema = 'ask';
|
|
203
201
|
// Re-create auth because we altered the descriptor after signing
|
|
204
|
-
protocolsConfig.message.authorization =
|
|
202
|
+
protocolsConfig.message.authorization = await Message.createAuthorization({
|
|
205
203
|
descriptor: protocolsConfig.message.descriptor,
|
|
206
204
|
signer: Jws.createSigner(alice)
|
|
207
205
|
});
|
|
208
206
|
// Send records write message
|
|
209
|
-
const reply =
|
|
207
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
210
208
|
expect(reply.status.code).toBe(400);
|
|
211
209
|
expect(reply.status.detail).toContain(DwnErrorCode.UrlSchemaNotNormalized);
|
|
212
|
-
})
|
|
213
|
-
it('rejects non-tenant non-granted ProtocolsConfigures with 401', () =>
|
|
210
|
+
});
|
|
211
|
+
it('rejects non-tenant non-granted ProtocolsConfigures with 401', async () => {
|
|
214
212
|
// Bob tries to ProtocolsConfigure to Alice's DWN without a permission grant
|
|
215
|
-
const alice =
|
|
216
|
-
const bob =
|
|
213
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
214
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
217
215
|
const protocolDefinition = dexProtocolDefinition;
|
|
218
|
-
const protocolsConfig =
|
|
216
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
219
217
|
author: bob,
|
|
220
218
|
protocolDefinition,
|
|
221
219
|
});
|
|
222
|
-
const protocolsConfigureReply =
|
|
220
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
223
221
|
expect(protocolsConfigureReply.status.code).toBe(401);
|
|
224
222
|
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureAuthorizationFailed);
|
|
225
|
-
})
|
|
226
|
-
it('should reject ProtocolsConfigure with action rule containing duplicated actor (`who` or `who` + `of` combination) within a rule set', () =>
|
|
227
|
-
const alice =
|
|
223
|
+
});
|
|
224
|
+
it('should reject ProtocolsConfigure with action rule containing duplicated actor (`who` or `who` + `of` combination) within a rule set', async () => {
|
|
225
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
228
226
|
const protocolDefinition = {
|
|
229
227
|
protocol: 'http://foo-bar',
|
|
230
228
|
published: true,
|
|
@@ -254,12 +252,12 @@ export function testProtocolsConfigureHandler() {
|
|
|
254
252
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
255
253
|
definition: protocolDefinition
|
|
256
254
|
};
|
|
257
|
-
const authorization =
|
|
255
|
+
const authorization = await Message.createAuthorization({
|
|
258
256
|
descriptor,
|
|
259
257
|
signer: Jws.createSigner(alice)
|
|
260
258
|
});
|
|
261
259
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
262
|
-
const protocolsConfigureReply =
|
|
260
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
263
261
|
expect(protocolsConfigureReply.status.code).toBe(400);
|
|
264
262
|
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateActorInRuleSet);
|
|
265
263
|
// similar test as above but with `of` property
|
|
@@ -296,17 +294,17 @@ export function testProtocolsConfigureHandler() {
|
|
|
296
294
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
297
295
|
definition: protocolDefinition2
|
|
298
296
|
};
|
|
299
|
-
const authorization2 =
|
|
297
|
+
const authorization2 = await Message.createAuthorization({
|
|
300
298
|
descriptor: descriptor2,
|
|
301
299
|
signer: Jws.createSigner(alice)
|
|
302
300
|
});
|
|
303
301
|
const protocolsConfigureMessage2 = { descriptor: descriptor2, authorization: authorization2 };
|
|
304
|
-
const protocolsConfigure2Reply =
|
|
302
|
+
const protocolsConfigure2Reply = await dwn.processMessage(alice.did, protocolsConfigureMessage2);
|
|
305
303
|
expect(protocolsConfigure2Reply.status.code).toBe(400);
|
|
306
304
|
expect(protocolsConfigure2Reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateActorInRuleSet);
|
|
307
|
-
})
|
|
308
|
-
it('should reject ProtocolsConfigure with action rule containing duplicated role within a rule set', () =>
|
|
309
|
-
const alice =
|
|
305
|
+
});
|
|
306
|
+
it('should reject ProtocolsConfigure with action rule containing duplicated role within a rule set', async () => {
|
|
307
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
310
308
|
const protocolDefinition = {
|
|
311
309
|
protocol: 'http://foo',
|
|
312
310
|
published: true,
|
|
@@ -340,17 +338,17 @@ export function testProtocolsConfigureHandler() {
|
|
|
340
338
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
341
339
|
definition: protocolDefinition
|
|
342
340
|
};
|
|
343
|
-
const authorization =
|
|
341
|
+
const authorization = await Message.createAuthorization({
|
|
344
342
|
descriptor,
|
|
345
343
|
signer: Jws.createSigner(alice)
|
|
346
344
|
});
|
|
347
345
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
348
|
-
const protocolsConfigureReply =
|
|
346
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
349
347
|
expect(protocolsConfigureReply.status.code).toBe(400);
|
|
350
348
|
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateRoleInRuleSet);
|
|
351
|
-
})
|
|
352
|
-
it('should reject ProtocolsConfigure with action rule `of` pointing to a sibling type (not an ancestor)', () =>
|
|
353
|
-
const alice =
|
|
349
|
+
});
|
|
350
|
+
it('should reject ProtocolsConfigure with action rule `of` pointing to a sibling type (not an ancestor)', async () => {
|
|
351
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
354
352
|
// `bar` and `baz` are siblings under `foo`, so `baz` action rule cannot reference `of: 'foo/bar'`
|
|
355
353
|
const protocolDefinition = {
|
|
356
354
|
protocol: 'http://example.com/sibling-of-test',
|
|
@@ -382,17 +380,17 @@ export function testProtocolsConfigureHandler() {
|
|
|
382
380
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
383
381
|
definition: protocolDefinition
|
|
384
382
|
};
|
|
385
|
-
const authorization =
|
|
383
|
+
const authorization = await Message.createAuthorization({
|
|
386
384
|
descriptor,
|
|
387
385
|
signer: Jws.createSigner(alice)
|
|
388
386
|
});
|
|
389
387
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
390
|
-
const reply =
|
|
388
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
391
389
|
expect(reply.status.code).toBe(400);
|
|
392
390
|
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidActionOfNotAnAncestor);
|
|
393
|
-
})
|
|
394
|
-
it('should reject ProtocolsConfigure with action rule `of` pointing to an unrelated type', () =>
|
|
395
|
-
const alice =
|
|
391
|
+
});
|
|
392
|
+
it('should reject ProtocolsConfigure with action rule `of` pointing to an unrelated type', async () => {
|
|
393
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
396
394
|
// `comment` is a top-level type unrelated to the nested `thread/reply` path
|
|
397
395
|
const protocolDefinition = {
|
|
398
396
|
protocol: 'http://example.com/unrelated-of-test',
|
|
@@ -423,17 +421,17 @@ export function testProtocolsConfigureHandler() {
|
|
|
423
421
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
424
422
|
definition: protocolDefinition
|
|
425
423
|
};
|
|
426
|
-
const authorization =
|
|
424
|
+
const authorization = await Message.createAuthorization({
|
|
427
425
|
descriptor,
|
|
428
426
|
signer: Jws.createSigner(alice)
|
|
429
427
|
});
|
|
430
428
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
431
|
-
const reply =
|
|
429
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
432
430
|
expect(reply.status.code).toBe(400);
|
|
433
431
|
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidActionOfNotAnAncestor);
|
|
434
|
-
})
|
|
435
|
-
it('should accept ProtocolsConfigure with action rule `of` pointing to itself (same protocol path)', () =>
|
|
436
|
-
const alice =
|
|
432
|
+
});
|
|
433
|
+
it('should accept ProtocolsConfigure with action rule `of` pointing to itself (same protocol path)', async () => {
|
|
434
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
437
435
|
// `of` pointing to the same protocol path is valid: "the author of this record can update it"
|
|
438
436
|
const protocolDefinition = {
|
|
439
437
|
protocol: 'http://example.com/self-of-test',
|
|
@@ -456,15 +454,15 @@ export function testProtocolsConfigureHandler() {
|
|
|
456
454
|
}
|
|
457
455
|
}
|
|
458
456
|
};
|
|
459
|
-
const protocolsConfigure =
|
|
457
|
+
const protocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
460
458
|
author: alice,
|
|
461
459
|
protocolDefinition,
|
|
462
460
|
});
|
|
463
|
-
const reply =
|
|
461
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
464
462
|
expect(reply.status.code).toBe(202);
|
|
465
|
-
})
|
|
466
|
-
it('should accept ProtocolsConfigure with action rule `of` pointing to a valid ancestor', () =>
|
|
467
|
-
const alice =
|
|
463
|
+
});
|
|
464
|
+
it('should accept ProtocolsConfigure with action rule `of` pointing to a valid ancestor', async () => {
|
|
465
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
468
466
|
// `of: 'thread'` is a valid ancestor of `thread/reply/reaction`
|
|
469
467
|
const protocolDefinition = {
|
|
470
468
|
protocol: 'http://example.com/valid-ancestor-of-test',
|
|
@@ -497,138 +495,147 @@ export function testProtocolsConfigureHandler() {
|
|
|
497
495
|
}
|
|
498
496
|
}
|
|
499
497
|
};
|
|
500
|
-
const protocolsConfigure =
|
|
498
|
+
const protocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
501
499
|
author: alice,
|
|
502
500
|
protocolDefinition,
|
|
503
501
|
});
|
|
504
|
-
const reply =
|
|
502
|
+
const reply = await dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
505
503
|
expect(reply.status.code).toBe(202);
|
|
506
|
-
})
|
|
504
|
+
});
|
|
507
505
|
describe('Grant authorization', () => {
|
|
508
|
-
it('allows an external party to ProtocolsConfigure only if they have a valid grant', () =>
|
|
506
|
+
it('allows an external party to ProtocolsConfigure only if they have a valid grant', async () => {
|
|
509
507
|
// scenario:
|
|
510
508
|
// 1. Alice grants Bob the access to ProtocolsConfigure on her DWN
|
|
511
509
|
// 2. Verify Bob can perform a ProtocolsConfigure
|
|
512
510
|
// 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
|
|
513
511
|
// 4. Alice revokes Bob's grant
|
|
514
512
|
// 5. Verify Bob cannot perform ProtocolsConfigure with the revoked grant
|
|
515
|
-
const alice =
|
|
516
|
-
const bob =
|
|
517
|
-
const mallory =
|
|
513
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
514
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
515
|
+
const mallory = await TestDataGenerator.generateDidKeyPersona();
|
|
518
516
|
// 1. Alice grants Bob the access to ProtocolsConfigure on her DWN
|
|
519
|
-
const permissionGrant =
|
|
517
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
520
518
|
signer: Jws.createSigner(alice),
|
|
521
519
|
grantedTo: bob.did,
|
|
522
520
|
dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
|
|
523
521
|
scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Configure }
|
|
524
522
|
});
|
|
525
523
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
526
|
-
const grantRecordsWriteReply =
|
|
524
|
+
const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
527
525
|
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
528
526
|
// 2. Verify Bob can perform a ProtocolsConfigure
|
|
529
527
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
530
|
-
const protocolsConfigure =
|
|
528
|
+
const protocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
531
529
|
permissionGrantId,
|
|
532
530
|
author: bob,
|
|
533
531
|
protocolDefinition: minimalProtocolDefinition
|
|
534
532
|
});
|
|
535
|
-
const protocolsConfigureReply =
|
|
533
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
536
534
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
537
535
|
// 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
|
|
538
|
-
const malloryProtocolsQuery =
|
|
536
|
+
const malloryProtocolsQuery = await TestDataGenerator.generateProtocolsConfigure({
|
|
539
537
|
permissionGrantId,
|
|
540
538
|
author: mallory,
|
|
541
539
|
protocolDefinition: minimalProtocolDefinition
|
|
542
540
|
});
|
|
543
|
-
const malloryProtocolsQueryReply =
|
|
541
|
+
const malloryProtocolsQueryReply = await dwn.processMessage(alice.did, malloryProtocolsQuery.message);
|
|
544
542
|
expect(malloryProtocolsQueryReply.status.code).toBe(401);
|
|
545
543
|
expect(malloryProtocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationNotGrantedToAuthor);
|
|
546
544
|
// 4. Alice revokes Bob's grant
|
|
547
|
-
const revokeWrite =
|
|
545
|
+
const revokeWrite = await PermissionsProtocol.createRevocation({
|
|
548
546
|
signer: Jws.createSigner(alice),
|
|
549
|
-
grant:
|
|
547
|
+
grant: PermissionGrant.parse(permissionGrant.dataEncodedMessage),
|
|
550
548
|
dateRevoked: Time.getCurrentTimestamp()
|
|
551
549
|
});
|
|
552
|
-
const revokeWriteReply =
|
|
550
|
+
const revokeWriteReply = await dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
|
|
553
551
|
expect(revokeWriteReply.status.code).toBe(202);
|
|
554
552
|
// 5. Verify Bob cannot perform ProtocolsQuery with the revoked grant
|
|
555
|
-
const unauthorizedProtocolsConfigure =
|
|
553
|
+
const unauthorizedProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
556
554
|
permissionGrantId,
|
|
557
555
|
author: bob,
|
|
558
|
-
protocolDefinition:
|
|
556
|
+
protocolDefinition: {
|
|
557
|
+
...minimalProtocolDefinition,
|
|
558
|
+
protocol: 'https://example.com/protocol/another-protocol'
|
|
559
|
+
}
|
|
559
560
|
});
|
|
560
|
-
const unauthorizedProtocolsConfigureReply =
|
|
561
|
+
const unauthorizedProtocolsConfigureReply = await dwn.processMessage(alice.did, unauthorizedProtocolsConfigure.message);
|
|
561
562
|
expect(unauthorizedProtocolsConfigureReply.status.code).toBe(401);
|
|
562
563
|
expect(unauthorizedProtocolsConfigureReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
563
|
-
})
|
|
564
|
-
it('should allow to scope a ProtocolsConfigure to a specific protocol', () =>
|
|
565
|
-
const alice =
|
|
566
|
-
const bob =
|
|
564
|
+
});
|
|
565
|
+
it('should allow to scope a ProtocolsConfigure to a specific protocol', async () => {
|
|
566
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
567
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
567
568
|
// Alice grants Bob the access to ProtocolsConfigure on her DWN for a specific protocol
|
|
568
|
-
const permissionGrant =
|
|
569
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
569
570
|
signer: Jws.createSigner(alice),
|
|
570
571
|
grantedTo: bob.did,
|
|
571
572
|
dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
|
|
572
573
|
scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Configure, protocol: 'https://example.com/protocol/allowed' }
|
|
573
574
|
});
|
|
574
575
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
575
|
-
const grantRecordsWriteReply =
|
|
576
|
+
const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
576
577
|
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
577
578
|
// Bob tries to ProtocolsConfigure to Alice's DWN for the allowed protocol
|
|
578
|
-
const protocolConfigureAllowed =
|
|
579
|
+
const protocolConfigureAllowed = await TestDataGenerator.generateProtocolsConfigure({
|
|
579
580
|
author: bob,
|
|
580
|
-
protocolDefinition:
|
|
581
|
+
protocolDefinition: {
|
|
582
|
+
...minimalProtocolDefinition,
|
|
583
|
+
protocol: 'https://example.com/protocol/allowed'
|
|
584
|
+
},
|
|
581
585
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
582
586
|
});
|
|
583
|
-
const protocolConfigureAllowedReply =
|
|
587
|
+
const protocolConfigureAllowedReply = await dwn.processMessage(alice.did, protocolConfigureAllowed.message);
|
|
584
588
|
expect(protocolConfigureAllowedReply.status.code).toBe(202);
|
|
585
589
|
// Bob tries to ProtocolsConfigure to Alice's DWN for a different protocol
|
|
586
|
-
const protocolConfigureNotAllowed =
|
|
590
|
+
const protocolConfigureNotAllowed = await TestDataGenerator.generateProtocolsConfigure({
|
|
587
591
|
author: bob,
|
|
588
|
-
protocolDefinition:
|
|
592
|
+
protocolDefinition: {
|
|
593
|
+
...minimalProtocolDefinition,
|
|
594
|
+
protocol: 'https://example.com/protocol/not-allowed'
|
|
595
|
+
},
|
|
589
596
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
590
597
|
});
|
|
591
|
-
const protocolConfigureNotAllowedReply =
|
|
598
|
+
const protocolConfigureNotAllowedReply = await dwn.processMessage(alice.did, protocolConfigureNotAllowed.message);
|
|
592
599
|
expect(protocolConfigureNotAllowedReply.status.code).toBe(401);
|
|
593
|
-
})
|
|
600
|
+
});
|
|
594
601
|
});
|
|
595
602
|
describe('state index', () => {
|
|
596
|
-
it('should add event for ProtocolsConfigure', () =>
|
|
597
|
-
const alice =
|
|
598
|
-
const { message } =
|
|
599
|
-
const reply =
|
|
603
|
+
it('should add event for ProtocolsConfigure', async () => {
|
|
604
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
605
|
+
const { message } = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
606
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
600
607
|
expect(reply.status.code).toBe(202);
|
|
601
|
-
const events =
|
|
608
|
+
const events = await stateIndex.getLeaves(alice.did, []);
|
|
602
609
|
expect(events.length).toBe(1);
|
|
603
|
-
const messageCid =
|
|
610
|
+
const messageCid = await Message.getCid(message);
|
|
604
611
|
expect(events[0]).toBe(messageCid);
|
|
605
|
-
})
|
|
606
|
-
it('should retain all ProtocolsConfigure events for protocol versioning', () =>
|
|
607
|
-
const alice =
|
|
608
|
-
const oldestWrite =
|
|
609
|
-
|
|
610
|
-
const newestWrite =
|
|
611
|
-
let reply =
|
|
612
|
+
});
|
|
613
|
+
it('should retain all ProtocolsConfigure events for protocol versioning', async () => {
|
|
614
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
615
|
+
const oldestWrite = await TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
|
|
616
|
+
await Time.minimalSleep();
|
|
617
|
+
const newestWrite = await TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
|
|
618
|
+
let reply = await dwn.processMessage(alice.did, oldestWrite.message);
|
|
612
619
|
expect(reply.status.code).toBe(202);
|
|
613
|
-
reply =
|
|
620
|
+
reply = await dwn.processMessage(alice.did, newestWrite.message);
|
|
614
621
|
expect(reply.status.code).toBe(202);
|
|
615
|
-
const events =
|
|
622
|
+
const events = await stateIndex.getLeaves(alice.did, []);
|
|
616
623
|
expect(events.length).toBe(2);
|
|
617
|
-
const oldestMessageCid =
|
|
618
|
-
const newestMessageCid =
|
|
624
|
+
const oldestMessageCid = await Message.getCid(oldestWrite.message);
|
|
625
|
+
const newestMessageCid = await Message.getCid(newestWrite.message);
|
|
619
626
|
expect(events).toContain(oldestMessageCid);
|
|
620
627
|
expect(events).toContain(newestMessageCid);
|
|
621
|
-
})
|
|
628
|
+
});
|
|
622
629
|
});
|
|
623
630
|
describe('temporal protocol versioning', () => {
|
|
624
|
-
it('should authorize records created under v1 even after re-configuring to v2 that removes the type', () =>
|
|
631
|
+
it('should authorize records created under v1 even after re-configuring to v2 that removes the type', async () => {
|
|
625
632
|
// scenario:
|
|
626
633
|
// 1. Alice installs protocol v1 with types `post` and `comment`
|
|
627
634
|
// 2. Alice writes a `post` record under v1
|
|
628
635
|
// 3. Alice re-configures the protocol to v2 which removes the `comment` type
|
|
629
636
|
// 4. Alice should still be able to read the v1 `post` record
|
|
630
637
|
// 5. Alice should still be able to update the v1 `post` record (governed by v1 definition)
|
|
631
|
-
const alice =
|
|
638
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
632
639
|
// v1: has `post` and `comment` types
|
|
633
640
|
const protocolUri = 'https://example.com/versioned-protocol';
|
|
634
641
|
const protocolDefinitionV1 = {
|
|
@@ -647,24 +654,24 @@ export function testProtocolsConfigureHandler() {
|
|
|
647
654
|
}
|
|
648
655
|
}
|
|
649
656
|
};
|
|
650
|
-
const configureV1 =
|
|
657
|
+
const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
651
658
|
author: alice,
|
|
652
659
|
protocolDefinition: protocolDefinitionV1,
|
|
653
660
|
});
|
|
654
|
-
const configureV1Reply =
|
|
661
|
+
const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
|
|
655
662
|
expect(configureV1Reply.status.code).toBe(202);
|
|
656
663
|
// write a `post` record under v1
|
|
657
|
-
const postRecord =
|
|
664
|
+
const postRecord = await TestDataGenerator.generateRecordsWrite({
|
|
658
665
|
author: alice,
|
|
659
666
|
protocol: protocolUri,
|
|
660
667
|
protocolPath: 'post',
|
|
661
668
|
schema: 'https://example.com/post',
|
|
662
669
|
dataFormat: 'application/json',
|
|
663
670
|
});
|
|
664
|
-
const postReply =
|
|
671
|
+
const postReply = await dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
665
672
|
expect(postReply.status.code).toBe(202);
|
|
666
673
|
// write a `comment` record under v1
|
|
667
|
-
const commentRecord =
|
|
674
|
+
const commentRecord = await TestDataGenerator.generateRecordsWrite({
|
|
668
675
|
author: alice,
|
|
669
676
|
protocol: protocolUri,
|
|
670
677
|
protocolPath: 'post/comment',
|
|
@@ -672,9 +679,9 @@ export function testProtocolsConfigureHandler() {
|
|
|
672
679
|
dataFormat: 'application/json',
|
|
673
680
|
parentContextId: postRecord.message.contextId,
|
|
674
681
|
});
|
|
675
|
-
const commentReply =
|
|
682
|
+
const commentReply = await dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
|
|
676
683
|
expect(commentReply.status.code).toBe(202);
|
|
677
|
-
|
|
684
|
+
await Time.minimalSleep();
|
|
678
685
|
// v2: removes the `comment` type entirely, changes `post` schema
|
|
679
686
|
const protocolDefinitionV2 = {
|
|
680
687
|
protocol: protocolUri,
|
|
@@ -688,43 +695,43 @@ export function testProtocolsConfigureHandler() {
|
|
|
688
695
|
}
|
|
689
696
|
}
|
|
690
697
|
};
|
|
691
|
-
const configureV2 =
|
|
698
|
+
const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
692
699
|
author: alice,
|
|
693
700
|
protocolDefinition: protocolDefinitionV2,
|
|
694
701
|
});
|
|
695
|
-
const configureV2Reply =
|
|
702
|
+
const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
|
|
696
703
|
expect(configureV2Reply.status.code).toBe(202);
|
|
697
704
|
// read the v1 `post` record — should succeed because read authorization uses v1 definition
|
|
698
|
-
const readPost =
|
|
705
|
+
const readPost = await RecordsRead.create({
|
|
699
706
|
filter: { recordId: postRecord.message.recordId },
|
|
700
707
|
signer: Jws.createSigner(alice),
|
|
701
708
|
});
|
|
702
|
-
const readPostReply =
|
|
709
|
+
const readPostReply = await dwn.processMessage(alice.did, readPost.message);
|
|
703
710
|
expect(readPostReply.status.code).toBe(200);
|
|
704
711
|
// read the v1 `comment` record — should succeed (governed by v1 definition where `comment` exists)
|
|
705
|
-
const readComment =
|
|
712
|
+
const readComment = await RecordsRead.create({
|
|
706
713
|
filter: { recordId: commentRecord.message.recordId },
|
|
707
714
|
signer: Jws.createSigner(alice),
|
|
708
715
|
});
|
|
709
|
-
const readCommentReply =
|
|
716
|
+
const readCommentReply = await dwn.processMessage(alice.did, readComment.message);
|
|
710
717
|
expect(readCommentReply.status.code).toBe(200);
|
|
711
718
|
// update the v1 `post` record — should succeed (governed by v1 definition)
|
|
712
719
|
const updatedData = new TextEncoder().encode('{"title":"updated post"}');
|
|
713
|
-
const updatePost =
|
|
720
|
+
const updatePost = await RecordsWrite.createFrom({
|
|
714
721
|
recordsWriteMessage: postRecord.message,
|
|
715
722
|
data: updatedData,
|
|
716
723
|
signer: Jws.createSigner(alice),
|
|
717
724
|
});
|
|
718
|
-
const updatePostReply =
|
|
725
|
+
const updatePostReply = await dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
|
|
719
726
|
expect(updatePostReply.status.code).toBe(202);
|
|
720
|
-
})
|
|
721
|
-
it('should authorize new records against the latest protocol definition, not an older one', () =>
|
|
727
|
+
});
|
|
728
|
+
it('should authorize new records against the latest protocol definition, not an older one', async () => {
|
|
722
729
|
// scenario:
|
|
723
730
|
// 1. Alice installs protocol v1 with type `post`
|
|
724
731
|
// 2. Alice re-configures to v2 that changes `post` schema to 'https://example.com/post-v2'
|
|
725
732
|
// 3. A new record with v1 schema should be rejected (not matching the latest definition)
|
|
726
733
|
// 4. A new record with v2 schema should be accepted
|
|
727
|
-
const alice =
|
|
734
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
728
735
|
const protocolUri = 'https://example.com/versioned-protocol-2';
|
|
729
736
|
const protocolDefinitionV1 = {
|
|
730
737
|
protocol: protocolUri,
|
|
@@ -738,13 +745,13 @@ export function testProtocolsConfigureHandler() {
|
|
|
738
745
|
}
|
|
739
746
|
}
|
|
740
747
|
};
|
|
741
|
-
const configureV1 =
|
|
748
|
+
const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
742
749
|
author: alice,
|
|
743
750
|
protocolDefinition: protocolDefinitionV1,
|
|
744
751
|
});
|
|
745
|
-
const configureV1Reply =
|
|
752
|
+
const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
|
|
746
753
|
expect(configureV1Reply.status.code).toBe(202);
|
|
747
|
-
|
|
754
|
+
await Time.minimalSleep();
|
|
748
755
|
// v2: changes `post` schema
|
|
749
756
|
const protocolDefinitionV2 = {
|
|
750
757
|
protocol: protocolUri,
|
|
@@ -758,41 +765,41 @@ export function testProtocolsConfigureHandler() {
|
|
|
758
765
|
}
|
|
759
766
|
}
|
|
760
767
|
};
|
|
761
|
-
const configureV2 =
|
|
768
|
+
const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
762
769
|
author: alice,
|
|
763
770
|
protocolDefinition: protocolDefinitionV2,
|
|
764
771
|
});
|
|
765
|
-
const configureV2Reply =
|
|
772
|
+
const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
|
|
766
773
|
expect(configureV2Reply.status.code).toBe(202);
|
|
767
774
|
// write a new record with v1 schema — should fail (latest definition requires v2 schema)
|
|
768
|
-
const postV1 =
|
|
775
|
+
const postV1 = await TestDataGenerator.generateRecordsWrite({
|
|
769
776
|
author: alice,
|
|
770
777
|
protocol: protocolUri,
|
|
771
778
|
protocolPath: 'post',
|
|
772
779
|
schema: 'https://example.com/post-v1',
|
|
773
780
|
dataFormat: 'application/json',
|
|
774
781
|
});
|
|
775
|
-
const postV1Reply =
|
|
782
|
+
const postV1Reply = await dwn.processMessage(alice.did, postV1.message, { dataStream: postV1.dataStream });
|
|
776
783
|
expect(postV1Reply.status.code).toBe(400);
|
|
777
784
|
expect(postV1Reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationInvalidSchema);
|
|
778
785
|
// write a new record with v2 schema — should succeed
|
|
779
|
-
const postV2 =
|
|
786
|
+
const postV2 = await TestDataGenerator.generateRecordsWrite({
|
|
780
787
|
author: alice,
|
|
781
788
|
protocol: protocolUri,
|
|
782
789
|
protocolPath: 'post',
|
|
783
790
|
schema: 'https://example.com/post-v2',
|
|
784
791
|
dataFormat: 'application/json',
|
|
785
792
|
});
|
|
786
|
-
const postV2Reply =
|
|
793
|
+
const postV2Reply = await dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
|
|
787
794
|
expect(postV2Reply.status.code).toBe(202);
|
|
788
|
-
})
|
|
789
|
-
it('should authorize deletes of v1 records after re-configuring to v2 that removes the type', () =>
|
|
795
|
+
});
|
|
796
|
+
it('should authorize deletes of v1 records after re-configuring to v2 that removes the type', async () => {
|
|
790
797
|
// scenario:
|
|
791
798
|
// 1. Alice installs protocol v1 with types `post` (with delete action) and `comment`
|
|
792
799
|
// 2. Alice writes a `post/comment` record
|
|
793
800
|
// 3. Alice re-configures to v2 which removes the `comment` type
|
|
794
801
|
// 4. Alice should still be able to delete the v1 `comment` record (governed by v1 definition)
|
|
795
|
-
const alice =
|
|
802
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
796
803
|
const protocolUri = 'https://example.com/versioned-protocol-3';
|
|
797
804
|
const protocolDefinitionV1 = {
|
|
798
805
|
protocol: protocolUri,
|
|
@@ -810,30 +817,30 @@ export function testProtocolsConfigureHandler() {
|
|
|
810
817
|
}
|
|
811
818
|
}
|
|
812
819
|
};
|
|
813
|
-
const configureV1 =
|
|
820
|
+
const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
814
821
|
author: alice,
|
|
815
822
|
protocolDefinition: protocolDefinitionV1,
|
|
816
823
|
});
|
|
817
|
-
const configureV1Reply =
|
|
824
|
+
const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
|
|
818
825
|
expect(configureV1Reply.status.code).toBe(202);
|
|
819
826
|
// write a `post` record
|
|
820
|
-
const postRecord =
|
|
827
|
+
const postRecord = await TestDataGenerator.generateRecordsWrite({
|
|
821
828
|
author: alice,
|
|
822
829
|
protocol: protocolUri,
|
|
823
830
|
protocolPath: 'post',
|
|
824
831
|
});
|
|
825
|
-
const postReply =
|
|
832
|
+
const postReply = await dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
826
833
|
expect(postReply.status.code).toBe(202);
|
|
827
834
|
// write a `comment` record under the post
|
|
828
|
-
const commentRecord =
|
|
835
|
+
const commentRecord = await TestDataGenerator.generateRecordsWrite({
|
|
829
836
|
author: alice,
|
|
830
837
|
protocol: protocolUri,
|
|
831
838
|
protocolPath: 'post/comment',
|
|
832
839
|
parentContextId: postRecord.message.contextId,
|
|
833
840
|
});
|
|
834
|
-
const commentReply =
|
|
841
|
+
const commentReply = await dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
|
|
835
842
|
expect(commentReply.status.code).toBe(202);
|
|
836
|
-
|
|
843
|
+
await Time.minimalSleep();
|
|
837
844
|
// v2: removes the `comment` type
|
|
838
845
|
const protocolDefinitionV2 = {
|
|
839
846
|
protocol: protocolUri,
|
|
@@ -847,28 +854,28 @@ export function testProtocolsConfigureHandler() {
|
|
|
847
854
|
}
|
|
848
855
|
}
|
|
849
856
|
};
|
|
850
|
-
const configureV2 =
|
|
857
|
+
const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
851
858
|
author: alice,
|
|
852
859
|
protocolDefinition: protocolDefinitionV2,
|
|
853
860
|
});
|
|
854
|
-
const configureV2Reply =
|
|
861
|
+
const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
|
|
855
862
|
expect(configureV2Reply.status.code).toBe(202);
|
|
856
863
|
// delete the v1 `comment` record — should succeed (governed by v1 definition)
|
|
857
|
-
const deleteComment =
|
|
864
|
+
const deleteComment = await RecordsDelete.create({
|
|
858
865
|
signer: Jws.createSigner(alice),
|
|
859
866
|
recordId: commentRecord.message.recordId,
|
|
860
867
|
});
|
|
861
|
-
const deleteReply =
|
|
868
|
+
const deleteReply = await dwn.processMessage(alice.did, deleteComment.message);
|
|
862
869
|
expect(deleteReply.status.code).toBe(202);
|
|
863
|
-
})
|
|
864
|
-
it('should not retroactively apply v2 action rules to records created under v1', () =>
|
|
870
|
+
});
|
|
871
|
+
it('should not retroactively apply v2 action rules to records created under v1', async () => {
|
|
865
872
|
// scenario:
|
|
866
873
|
// 1. Alice installs protocol v1 where anyone can create and update `post` records
|
|
867
874
|
// 2. Bob writes a `post` to Alice's DWN
|
|
868
875
|
// 3. Alice re-configures to v2 that restricts `post` updates to author-only (removes co-update)
|
|
869
876
|
// 4. Bob should still be able to update his own record (governed by v1 definition which had update)
|
|
870
|
-
const alice =
|
|
871
|
-
const bob =
|
|
877
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
878
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
872
879
|
const protocolUri = 'https://example.com/versioned-protocol-4';
|
|
873
880
|
const protocolDefinitionV1 = {
|
|
874
881
|
protocol: protocolUri,
|
|
@@ -882,21 +889,21 @@ export function testProtocolsConfigureHandler() {
|
|
|
882
889
|
}
|
|
883
890
|
}
|
|
884
891
|
};
|
|
885
|
-
const configureV1 =
|
|
892
|
+
const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
886
893
|
author: alice,
|
|
887
894
|
protocolDefinition: protocolDefinitionV1,
|
|
888
895
|
});
|
|
889
|
-
const configureV1Reply =
|
|
896
|
+
const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
|
|
890
897
|
expect(configureV1Reply.status.code).toBe(202);
|
|
891
898
|
// Bob writes a `post` record to Alice's DWN under v1
|
|
892
|
-
const postRecord =
|
|
899
|
+
const postRecord = await TestDataGenerator.generateRecordsWrite({
|
|
893
900
|
author: bob,
|
|
894
901
|
protocol: protocolUri,
|
|
895
902
|
protocolPath: 'post',
|
|
896
903
|
});
|
|
897
|
-
const postReply =
|
|
904
|
+
const postReply = await dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
898
905
|
expect(postReply.status.code).toBe(202);
|
|
899
|
-
|
|
906
|
+
await Time.minimalSleep();
|
|
900
907
|
// v2: restricts actions (only create, no update for anyone)
|
|
901
908
|
const protocolDefinitionV2 = {
|
|
902
909
|
protocol: protocolUri,
|
|
@@ -910,30 +917,29 @@ export function testProtocolsConfigureHandler() {
|
|
|
910
917
|
}
|
|
911
918
|
}
|
|
912
919
|
};
|
|
913
|
-
const configureV2 =
|
|
920
|
+
const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
914
921
|
author: alice,
|
|
915
922
|
protocolDefinition: protocolDefinitionV2,
|
|
916
923
|
});
|
|
917
|
-
const configureV2Reply =
|
|
924
|
+
const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
|
|
918
925
|
expect(configureV2Reply.status.code).toBe(202);
|
|
919
926
|
// Bob updates his v1 record — should succeed because v1 definition (which governs this record) allowed update
|
|
920
927
|
const updatedData = new TextEncoder().encode('updated-post-data');
|
|
921
|
-
const updatePost =
|
|
928
|
+
const updatePost = await RecordsWrite.createFrom({
|
|
922
929
|
recordsWriteMessage: postRecord.message,
|
|
923
930
|
data: updatedData,
|
|
924
931
|
signer: Jws.createSigner(bob),
|
|
925
932
|
});
|
|
926
|
-
const updateReply =
|
|
933
|
+
const updateReply = await dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
|
|
927
934
|
expect(updateReply.status.code).toBe(202);
|
|
928
|
-
})
|
|
929
|
-
it('should handle out-of-order protocol configure processing correctly', () =>
|
|
930
|
-
var _a;
|
|
935
|
+
});
|
|
936
|
+
it('should handle out-of-order protocol configure processing correctly', async () => {
|
|
931
937
|
// scenario:
|
|
932
938
|
// 1. Create v1 and v2 ProtocolsConfigure messages (v2 has a newer timestamp)
|
|
933
939
|
// 2. Process v2 first, then v1
|
|
934
940
|
// 3. Both should be stored; query should return only v2 (the latest)
|
|
935
941
|
// 4. A record written under v2 schema should succeed
|
|
936
|
-
const alice =
|
|
942
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
937
943
|
const protocolUri = 'https://example.com/versioned-protocol-5';
|
|
938
944
|
const protocolDefinitionV1 = {
|
|
939
945
|
protocol: protocolUri,
|
|
@@ -947,11 +953,11 @@ export function testProtocolsConfigureHandler() {
|
|
|
947
953
|
}
|
|
948
954
|
}
|
|
949
955
|
};
|
|
950
|
-
const configureV1 =
|
|
956
|
+
const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
|
|
951
957
|
author: alice,
|
|
952
958
|
protocolDefinition: protocolDefinitionV1,
|
|
953
959
|
});
|
|
954
|
-
|
|
960
|
+
await Time.minimalSleep();
|
|
955
961
|
const protocolDefinitionV2 = {
|
|
956
962
|
protocol: protocolUri,
|
|
957
963
|
published: true,
|
|
@@ -964,36 +970,36 @@ export function testProtocolsConfigureHandler() {
|
|
|
964
970
|
}
|
|
965
971
|
}
|
|
966
972
|
};
|
|
967
|
-
const configureV2 =
|
|
973
|
+
const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
|
|
968
974
|
author: alice,
|
|
969
975
|
protocolDefinition: protocolDefinitionV2,
|
|
970
976
|
});
|
|
971
977
|
// process v2 first (out of order)
|
|
972
|
-
const configureV2Reply =
|
|
978
|
+
const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
|
|
973
979
|
expect(configureV2Reply.status.code).toBe(202);
|
|
974
980
|
// process v1 second (older, arrives later)
|
|
975
|
-
const configureV1Reply =
|
|
981
|
+
const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
|
|
976
982
|
expect(configureV1Reply.status.code).toBe(202);
|
|
977
983
|
// query should return only v2 (the latest)
|
|
978
|
-
const queryMessageData =
|
|
984
|
+
const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
|
|
979
985
|
author: alice,
|
|
980
986
|
filter: { protocol: protocolUri }
|
|
981
987
|
});
|
|
982
|
-
const queryReply =
|
|
988
|
+
const queryReply = await dwn.processMessage(alice.did, queryMessageData.message);
|
|
983
989
|
expect(queryReply.status.code).toBe(200);
|
|
984
|
-
expect(
|
|
990
|
+
expect(queryReply.entries?.length).toBe(1);
|
|
985
991
|
expect(queryReply.entries[0].descriptor.definition.types.post.schema).toBe('https://example.com/post-v2');
|
|
986
992
|
// writing a new record with v2 schema should succeed (latest definition)
|
|
987
|
-
const postV2 =
|
|
993
|
+
const postV2 = await TestDataGenerator.generateRecordsWrite({
|
|
988
994
|
author: alice,
|
|
989
995
|
protocol: protocolUri,
|
|
990
996
|
protocolPath: 'post',
|
|
991
997
|
schema: 'https://example.com/post-v2',
|
|
992
998
|
dataFormat: 'application/json',
|
|
993
999
|
});
|
|
994
|
-
const postV2Reply =
|
|
1000
|
+
const postV2Reply = await dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
|
|
995
1001
|
expect(postV2Reply.status.code).toBe(202);
|
|
996
|
-
})
|
|
1002
|
+
});
|
|
997
1003
|
});
|
|
998
1004
|
});
|
|
999
1005
|
});
|