@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 emailProtocolDefinition from '../vectors/protocol-definitions/email.json' with { type: 'json' };
|
|
11
2
|
import messageProtocolDefinition from '../vectors/protocol-definitions/message.json' with { type: 'json' };
|
|
12
3
|
import sinon from 'sinon';
|
|
@@ -20,7 +11,7 @@ import { PermissionGrant } from '../../src/protocols/permission-grant.js';
|
|
|
20
11
|
import { Poller } from '../utils/poller.js';
|
|
21
12
|
import { RecordsWrite } from '../../src/interfaces/records-write.js';
|
|
22
13
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
23
|
-
import {
|
|
14
|
+
import { TestEventLog } from '../test-event-stream.js';
|
|
24
15
|
import { TestStores } from '../test-stores.js';
|
|
25
16
|
import { Time } from '../../src/utils/time.js';
|
|
26
17
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
@@ -33,41 +24,41 @@ export function testAuthorDelegatedGrant() {
|
|
|
33
24
|
let dataStore;
|
|
34
25
|
let resumableTaskStore;
|
|
35
26
|
let stateIndex;
|
|
36
|
-
let
|
|
27
|
+
let eventLog;
|
|
37
28
|
let dwn;
|
|
38
29
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
39
30
|
// so that different test suites can reuse the same backend store for testing
|
|
40
|
-
beforeAll(() =>
|
|
31
|
+
beforeAll(async () => {
|
|
41
32
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
42
33
|
const stores = TestStores.get();
|
|
43
34
|
messageStore = stores.messageStore;
|
|
44
35
|
dataStore = stores.dataStore;
|
|
45
36
|
resumableTaskStore = stores.resumableTaskStore;
|
|
46
37
|
stateIndex = stores.stateIndex;
|
|
47
|
-
|
|
48
|
-
dwn =
|
|
49
|
-
})
|
|
50
|
-
beforeEach(() =>
|
|
38
|
+
eventLog = TestEventLog.get();
|
|
39
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, resumableTaskStore });
|
|
40
|
+
});
|
|
41
|
+
beforeEach(async () => {
|
|
51
42
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
52
43
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
58
|
-
afterAll(() =>
|
|
59
|
-
|
|
60
|
-
})
|
|
44
|
+
await messageStore.clear();
|
|
45
|
+
await dataStore.clear();
|
|
46
|
+
await resumableTaskStore.clear();
|
|
47
|
+
await stateIndex.clear();
|
|
48
|
+
});
|
|
49
|
+
afterAll(async () => {
|
|
50
|
+
await dwn.close();
|
|
51
|
+
});
|
|
61
52
|
describe('ProtocolsConfigure', () => {
|
|
62
|
-
it('should allow author-delegated grant to configure protocols', () =>
|
|
63
|
-
const alice =
|
|
64
|
-
const bob =
|
|
53
|
+
it('should allow author-delegated grant to configure protocols', async () => {
|
|
54
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
55
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
65
56
|
// Alice grants Bob ability to configure any protocol, bob will use it to configure the email protocol
|
|
66
57
|
const scope = {
|
|
67
58
|
interface: DwnInterfaceName.Protocols,
|
|
68
59
|
method: DwnMethodName.Configure,
|
|
69
60
|
};
|
|
70
|
-
const grantToBob =
|
|
61
|
+
const grantToBob = await PermissionsProtocol.createGrant({
|
|
71
62
|
delegated: true, // this is a delegated grant
|
|
72
63
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
73
64
|
description: 'Allow Bob to configure the email protocol',
|
|
@@ -76,22 +67,22 @@ export function testAuthorDelegatedGrant() {
|
|
|
76
67
|
signer: Jws.createSigner(alice)
|
|
77
68
|
});
|
|
78
69
|
// Bob attempts to configure a protocol
|
|
79
|
-
const protocolConfigure =
|
|
70
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
80
71
|
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
81
72
|
author: bob,
|
|
82
73
|
protocolDefinition: emailProtocolDefinition,
|
|
83
74
|
});
|
|
84
75
|
// Bob should be able to configure a protocol on behalf of alice
|
|
85
|
-
const protocolConfigureReply =
|
|
76
|
+
const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
86
77
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
87
78
|
// verify the protocol configure message was processed
|
|
88
|
-
const protocolsQuery =
|
|
79
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
89
80
|
author: alice,
|
|
90
81
|
filter: { protocol: emailProtocolDefinition.protocol }
|
|
91
82
|
});
|
|
92
|
-
const { status, entries } =
|
|
83
|
+
const { status, entries } = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
93
84
|
expect(status.code).toBe(200);
|
|
94
|
-
expect(entries
|
|
85
|
+
expect(entries?.length).toBe(1);
|
|
95
86
|
const fetchedProtocolConfigure = entries[0];
|
|
96
87
|
expect(fetchedProtocolConfigure.descriptor.definition).toEqual(emailProtocolDefinition);
|
|
97
88
|
// author should be alice
|
|
@@ -99,17 +90,17 @@ export function testAuthorDelegatedGrant() {
|
|
|
99
90
|
expect(author).toBe(alice.did);
|
|
100
91
|
const signer = Message.getSigner(fetchedProtocolConfigure);
|
|
101
92
|
expect(signer).toBe(bob.did);
|
|
102
|
-
})
|
|
103
|
-
it('should allow author-delegated grant to configure a specific protocol', () =>
|
|
104
|
-
const alice =
|
|
105
|
-
const bob =
|
|
93
|
+
});
|
|
94
|
+
it('should allow author-delegated grant to configure a specific protocol', async () => {
|
|
95
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
96
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
106
97
|
// Alice grants Bob to configure the email protocol
|
|
107
98
|
const scope = {
|
|
108
99
|
interface: DwnInterfaceName.Protocols,
|
|
109
100
|
method: DwnMethodName.Configure,
|
|
110
101
|
protocol: emailProtocolDefinition.protocol,
|
|
111
102
|
};
|
|
112
|
-
const grantToBob =
|
|
103
|
+
const grantToBob = await PermissionsProtocol.createGrant({
|
|
113
104
|
delegated: true, // this is a delegated grant
|
|
114
105
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
115
106
|
description: 'Allow Bob to configure the email protocol',
|
|
@@ -118,22 +109,22 @@ export function testAuthorDelegatedGrant() {
|
|
|
118
109
|
signer: Jws.createSigner(alice)
|
|
119
110
|
});
|
|
120
111
|
// Bob attempts to configure a protocol
|
|
121
|
-
const protocolConfigure =
|
|
112
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
122
113
|
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
123
114
|
author: bob,
|
|
124
115
|
protocolDefinition: emailProtocolDefinition,
|
|
125
116
|
});
|
|
126
117
|
// Bob should be able to configure a protocol on behalf of alice
|
|
127
|
-
const protocolConfigureReply =
|
|
118
|
+
const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
128
119
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
129
120
|
// verify the protocol configure message was processed
|
|
130
|
-
const protocolsQuery =
|
|
121
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
131
122
|
author: alice,
|
|
132
123
|
filter: { protocol: emailProtocolDefinition.protocol }
|
|
133
124
|
});
|
|
134
|
-
const { status, entries } =
|
|
125
|
+
const { status, entries } = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
135
126
|
expect(status.code).toBe(200);
|
|
136
|
-
expect(entries
|
|
127
|
+
expect(entries?.length).toBe(1);
|
|
137
128
|
const fetchedProtocolConfigure = entries[0];
|
|
138
129
|
expect(fetchedProtocolConfigure.descriptor.definition).toEqual(emailProtocolDefinition);
|
|
139
130
|
// author should be alice
|
|
@@ -142,28 +133,31 @@ export function testAuthorDelegatedGrant() {
|
|
|
142
133
|
const signer = Message.getSigner(fetchedProtocolConfigure);
|
|
143
134
|
expect(signer).toBe(bob.did);
|
|
144
135
|
// verify that bob cannot configure a different protocol
|
|
145
|
-
const otherProtocolDefinition =
|
|
146
|
-
|
|
136
|
+
const otherProtocolDefinition = {
|
|
137
|
+
...emailProtocolDefinition,
|
|
138
|
+
protocol: 'https://example.com/protocol/otherProtocol'
|
|
139
|
+
};
|
|
140
|
+
const otherProtocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
147
141
|
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
148
142
|
author: bob,
|
|
149
143
|
protocolDefinition: otherProtocolDefinition,
|
|
150
144
|
});
|
|
151
|
-
const otherProtocolConfigureReply =
|
|
145
|
+
const otherProtocolConfigureReply = await dwn.processMessage(alice.did, otherProtocolConfigure.message);
|
|
152
146
|
expect(otherProtocolConfigureReply.status.code).toBe(401);
|
|
153
147
|
expect(otherProtocolConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsGrantAuthorizationScopeProtocolMismatch);
|
|
154
|
-
})
|
|
148
|
+
});
|
|
155
149
|
});
|
|
156
150
|
describe('RecordsWrite.parse()', () => {
|
|
157
|
-
it('should throw if a message invokes a author-delegated grant (ID) but the author-delegated grant is not given', () =>
|
|
158
|
-
const alice =
|
|
159
|
-
const bob =
|
|
151
|
+
it('should throw if a message invokes a author-delegated grant (ID) but the author-delegated grant is not given', async () => {
|
|
152
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
153
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
160
154
|
// Alice grants Bob to write as her for the chat protocol
|
|
161
155
|
const scope = {
|
|
162
156
|
interface: DwnInterfaceName.Records,
|
|
163
157
|
method: DwnMethodName.Write,
|
|
164
158
|
protocol: 'chat'
|
|
165
159
|
};
|
|
166
|
-
const grantToBob =
|
|
160
|
+
const grantToBob = await PermissionsProtocol.createGrant({
|
|
167
161
|
delegated: true, // this is a delegated grant
|
|
168
162
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
169
163
|
description: 'Allow Bob to write as me in chat protocol',
|
|
@@ -172,26 +166,28 @@ export function testAuthorDelegatedGrant() {
|
|
|
172
166
|
signer: Jws.createSigner(alice)
|
|
173
167
|
});
|
|
174
168
|
// Bob creates a chat message invoking the delegated grant (ID) but does not include the author-delegated grant (we remove it below)
|
|
175
|
-
const recordsWrite =
|
|
169
|
+
const recordsWrite = await RecordsWrite.create({
|
|
176
170
|
signer: Jws.createSigner(bob),
|
|
177
171
|
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
172
|
+
protocol: 'http://test-protocol.xyz',
|
|
173
|
+
protocolPath: 'testRecord',
|
|
178
174
|
dataFormat: 'application/octet-stream',
|
|
179
175
|
data: TestDataGenerator.randomBytes(10),
|
|
180
176
|
});
|
|
181
177
|
delete recordsWrite.message.authorization.authorDelegatedGrant; // intentionally remove `authorDelegatedGrant`
|
|
182
178
|
const parsePromise = RecordsWrite.parse(recordsWrite.message);
|
|
183
|
-
|
|
184
|
-
})
|
|
185
|
-
it('should throw if a message includes an author-delegated grant but does not reference it in author signature', () =>
|
|
186
|
-
const alice =
|
|
187
|
-
const bob =
|
|
179
|
+
await expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
|
|
180
|
+
});
|
|
181
|
+
it('should throw if a message includes an author-delegated grant but does not reference it in author signature', async () => {
|
|
182
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
183
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
188
184
|
// Alice grants Bob to write as her for the chat protocol
|
|
189
185
|
const scope = {
|
|
190
186
|
interface: DwnInterfaceName.Records,
|
|
191
187
|
method: DwnMethodName.Write,
|
|
192
188
|
protocol: 'chat'
|
|
193
189
|
};
|
|
194
|
-
const grantToBob =
|
|
190
|
+
const grantToBob = await PermissionsProtocol.createGrant({
|
|
195
191
|
delegated: true, // this is a delegated grant
|
|
196
192
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
197
193
|
description: 'Allow Bob to write as me in chat protocol',
|
|
@@ -201,39 +197,40 @@ export function testAuthorDelegatedGrant() {
|
|
|
201
197
|
});
|
|
202
198
|
// Bob attempts to sign as Alice by including an author-delegated grant
|
|
203
199
|
// but does not reference the grant ID in author signature (we remove it below)
|
|
204
|
-
const recordsWrite =
|
|
200
|
+
const recordsWrite = await RecordsWrite.create({
|
|
205
201
|
signer: Jws.createSigner(bob),
|
|
206
202
|
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
203
|
+
protocol: 'http://test-protocol.xyz',
|
|
204
|
+
protocolPath: 'testRecord',
|
|
207
205
|
dataFormat: 'application/octet-stream',
|
|
208
206
|
data: TestDataGenerator.randomBytes(10),
|
|
209
207
|
});
|
|
210
|
-
const authorSignaturePayloadCopy =
|
|
208
|
+
const authorSignaturePayloadCopy = { ...recordsWrite.signaturePayload };
|
|
211
209
|
delete authorSignaturePayloadCopy.delegatedGrantId; // intentionally remove `delegatedGrantId` in author signature
|
|
212
210
|
recordsWrite.message.authorization.signature.payload = Encoder.stringToBase64Url(JSON.stringify(authorSignaturePayloadCopy));
|
|
213
211
|
const parsePromise = RecordsWrite.parse(recordsWrite.message);
|
|
214
|
-
|
|
215
|
-
})
|
|
212
|
+
await expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
|
|
213
|
+
});
|
|
216
214
|
});
|
|
217
|
-
it('should only allow correct entity invoking an author-delegated grant to write', () =>
|
|
218
|
-
var _a, _b;
|
|
215
|
+
it('should only allow correct entity invoking an author-delegated grant to write', async () => {
|
|
219
216
|
// scenario:
|
|
220
217
|
// 1. Alice creates a delegated grant for Device X and Device Y,
|
|
221
218
|
// 2. Device X and Y can both use their grants to write a message to Bob's DWN as Alice
|
|
222
219
|
// 3. Messages written by device X and Y should be considered to have been authored by Alice
|
|
223
220
|
// 4. Carol should not be able to write a message as Alice using Device X's delegated grant
|
|
224
|
-
const alice =
|
|
225
|
-
const deviceX =
|
|
226
|
-
const deviceY =
|
|
227
|
-
const bob =
|
|
228
|
-
const carol =
|
|
221
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
222
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
223
|
+
const deviceY = await TestDataGenerator.generateDidKeyPersona();
|
|
224
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
225
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
229
226
|
// Bob has the message protocol installed
|
|
230
227
|
const protocolDefinition = messageProtocolDefinition;
|
|
231
228
|
const protocol = protocolDefinition.protocol;
|
|
232
|
-
const protocolsConfig =
|
|
229
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
233
230
|
author: bob,
|
|
234
231
|
protocolDefinition
|
|
235
232
|
});
|
|
236
|
-
const protocolConfigureReply =
|
|
233
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
237
234
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
238
235
|
// Alice creates a delegated grant for device X and device Y
|
|
239
236
|
const scope = {
|
|
@@ -241,14 +238,14 @@ export function testAuthorDelegatedGrant() {
|
|
|
241
238
|
method: DwnMethodName.Write,
|
|
242
239
|
protocol
|
|
243
240
|
};
|
|
244
|
-
const deviceXGrant =
|
|
241
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
245
242
|
delegated: true, // this is a delegated grant
|
|
246
243
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
247
244
|
grantedTo: deviceX.did,
|
|
248
245
|
scope: scope,
|
|
249
246
|
signer: Jws.createSigner(alice)
|
|
250
247
|
});
|
|
251
|
-
const deviceYGrant =
|
|
248
|
+
const deviceYGrant = await PermissionsProtocol.createGrant({
|
|
252
249
|
delegated: true, // this is a delegated grant
|
|
253
250
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
254
251
|
grantedTo: deviceY.did,
|
|
@@ -258,7 +255,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
258
255
|
// generate a `RecordsWrite` message from device X and write to Bob's DWN
|
|
259
256
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
260
257
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
261
|
-
const messageByDeviceX =
|
|
258
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
262
259
|
signer: Jws.createSigner(deviceX),
|
|
263
260
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
264
261
|
protocol,
|
|
@@ -267,42 +264,42 @@ export function testAuthorDelegatedGrant() {
|
|
|
267
264
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
268
265
|
data: deviceXData
|
|
269
266
|
});
|
|
270
|
-
const deviceXWriteReply =
|
|
267
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
271
268
|
expect(deviceXWriteReply.status.code).toBe(202);
|
|
272
269
|
// verify the message by device X got written to Bob's DWN, AND Alice is the logical author
|
|
273
|
-
const recordsQueryByBob =
|
|
270
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
274
271
|
author: bob,
|
|
275
272
|
filter: { protocol }
|
|
276
273
|
});
|
|
277
|
-
const bobRecordsQueryReply =
|
|
274
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
278
275
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
279
|
-
expect(
|
|
276
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(1);
|
|
280
277
|
const fetchedDeviceXWriteEntry = bobRecordsQueryReply.entries[0];
|
|
281
278
|
expect(fetchedDeviceXWriteEntry.encodedData).toBe(base64url.baseEncode(deviceXData));
|
|
282
|
-
const fetchedDeviceXWrite =
|
|
279
|
+
const fetchedDeviceXWrite = await RecordsWrite.parse(fetchedDeviceXWriteEntry);
|
|
283
280
|
expect(fetchedDeviceXWrite.author).toBe(alice.did);
|
|
284
281
|
// generate a new message by device Y updating the existing record device X created, and write to Bob's DWN
|
|
285
282
|
const deviceYData = new TextEncoder().encode('message from device Y');
|
|
286
283
|
const deviceYDataStream = DataStream.fromBytes(deviceYData);
|
|
287
|
-
const messageByDeviceY =
|
|
284
|
+
const messageByDeviceY = await RecordsWrite.createFrom({
|
|
288
285
|
recordsWriteMessage: fetchedDeviceXWrite.message,
|
|
289
286
|
data: deviceYData,
|
|
290
287
|
signer: Jws.createSigner(deviceY),
|
|
291
288
|
delegatedGrant: deviceYGrant.dataEncodedMessage,
|
|
292
289
|
});
|
|
293
|
-
const deviceYWriteReply =
|
|
290
|
+
const deviceYWriteReply = await dwn.processMessage(bob.did, messageByDeviceY.message, { dataStream: deviceYDataStream });
|
|
294
291
|
expect(deviceYWriteReply.status.code).toBe(202);
|
|
295
292
|
// verify the message by device Y got written to Bob's DWN, AND Alice is the logical author
|
|
296
|
-
const bobRecordsQueryReply2 =
|
|
293
|
+
const bobRecordsQueryReply2 = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
297
294
|
expect(bobRecordsQueryReply2.status.code).toBe(200);
|
|
298
|
-
expect(
|
|
295
|
+
expect(bobRecordsQueryReply2.entries?.length).toBe(1);
|
|
299
296
|
const fetchedDeviceYWriteEntry = bobRecordsQueryReply2.entries[0];
|
|
300
297
|
expect(fetchedDeviceYWriteEntry.encodedData).toBe(base64url.baseEncode(deviceYData));
|
|
301
|
-
const fetchedDeviceYWrite =
|
|
298
|
+
const fetchedDeviceYWrite = await RecordsWrite.parse(fetchedDeviceYWriteEntry);
|
|
302
299
|
expect(fetchedDeviceYWrite.author).toBe(alice.did);
|
|
303
300
|
// Verify that Carol cannot write a chat message as Alice by invoking the Device X's grant
|
|
304
301
|
const messageByCarolAsAlice = new TextEncoder().encode('Message from Carol pretending to be Alice');
|
|
305
|
-
const writeByCarolAsAlice =
|
|
302
|
+
const writeByCarolAsAlice = await RecordsWrite.create({
|
|
306
303
|
signer: Jws.createSigner(carol),
|
|
307
304
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
308
305
|
protocol,
|
|
@@ -311,40 +308,39 @@ export function testAuthorDelegatedGrant() {
|
|
|
311
308
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
312
309
|
data: messageByCarolAsAlice
|
|
313
310
|
});
|
|
314
|
-
const carolWriteReply =
|
|
311
|
+
const carolWriteReply = await dwn.processMessage(carol.did, writeByCarolAsAlice.message, { dataStream: DataStream.fromBytes(messageByCarolAsAlice) });
|
|
315
312
|
expect(carolWriteReply.status.code).toBe(400);
|
|
316
313
|
expect(carolWriteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
317
|
-
})
|
|
318
|
-
it('should only allow correct entity invoking an author-delegated grant to read and query ', () =>
|
|
319
|
-
var _a, _b, _c, _d;
|
|
314
|
+
});
|
|
315
|
+
it('should only allow correct entity invoking an author-delegated grant to read and query ', async () => {
|
|
320
316
|
// scenario:
|
|
321
317
|
// 1. Alice creates read and query delegated grants for device X,
|
|
322
318
|
// 2. Bob starts a chat thread with Alice on his DWN
|
|
323
319
|
// 3. device X should be able to read the chat thread
|
|
324
320
|
// 4. Carol should not be able to read the chat thread using device X's delegated grant
|
|
325
|
-
const alice =
|
|
326
|
-
const deviceX =
|
|
327
|
-
const bob =
|
|
328
|
-
const carol =
|
|
321
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
322
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
323
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
324
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
329
325
|
// Bob has the chat protocol installed
|
|
330
326
|
const protocolDefinition = threadRoleProtocolDefinition;
|
|
331
327
|
const protocol = threadRoleProtocolDefinition.protocol;
|
|
332
|
-
const protocolsConfig =
|
|
328
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
333
329
|
author: bob,
|
|
334
330
|
protocolDefinition
|
|
335
331
|
});
|
|
336
|
-
const protocolsConfigureReply =
|
|
332
|
+
const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
337
333
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
338
334
|
// Bob starts a chat thread
|
|
339
|
-
const threadRecord =
|
|
335
|
+
const threadRecord = await TestDataGenerator.generateRecordsWrite({
|
|
340
336
|
author: bob,
|
|
341
337
|
protocol: protocolDefinition.protocol,
|
|
342
338
|
protocolPath: 'thread',
|
|
343
339
|
});
|
|
344
|
-
const threadRoleReply =
|
|
340
|
+
const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
345
341
|
expect(threadRoleReply.status.code).toBe(202);
|
|
346
342
|
// Bob adds Alice as a participant in the thread
|
|
347
|
-
const participantRoleRecord =
|
|
343
|
+
const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
|
|
348
344
|
author: bob,
|
|
349
345
|
recipient: alice.did,
|
|
350
346
|
protocol: protocolDefinition.protocol,
|
|
@@ -352,19 +348,19 @@ export function testAuthorDelegatedGrant() {
|
|
|
352
348
|
parentContextId: threadRecord.message.contextId,
|
|
353
349
|
data: new TextEncoder().encode('Alice is my friend'),
|
|
354
350
|
});
|
|
355
|
-
const participantRoleReply =
|
|
351
|
+
const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
356
352
|
expect(participantRoleReply.status.code).toBe(202);
|
|
357
353
|
// Bob writes a chat message in the thread
|
|
358
|
-
const chatRecord =
|
|
354
|
+
const chatRecord = await TestDataGenerator.generateRecordsWrite({
|
|
359
355
|
author: bob,
|
|
360
356
|
protocol: protocolDefinition.protocol,
|
|
361
357
|
protocolPath: 'thread/chat',
|
|
362
358
|
parentContextId: threadRecord.message.contextId,
|
|
363
359
|
});
|
|
364
|
-
const chatRecordReply =
|
|
360
|
+
const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
365
361
|
expect(chatRecordReply.status.code).toBe(202);
|
|
366
362
|
// Alice creates a delegated query grant for device X to act as Alice.
|
|
367
|
-
const queryGrantForDeviceX =
|
|
363
|
+
const queryGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
368
364
|
delegated: true, // this is a delegated grant
|
|
369
365
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
370
366
|
grantedTo: deviceX.did,
|
|
@@ -376,7 +372,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
376
372
|
signer: Jws.createSigner(alice)
|
|
377
373
|
});
|
|
378
374
|
// Alice creates a delegated read grant for device X to act as Alice.
|
|
379
|
-
const readGrantForDeviceX =
|
|
375
|
+
const readGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
380
376
|
delegated: true, // this is a delegated grant
|
|
381
377
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
382
378
|
grantedTo: deviceX.did,
|
|
@@ -388,15 +384,15 @@ export function testAuthorDelegatedGrant() {
|
|
|
388
384
|
signer: Jws.createSigner(alice)
|
|
389
385
|
});
|
|
390
386
|
// sanity verify Bob himself is able to query for the chat thread from Bob's DWN
|
|
391
|
-
const recordsQueryByBob =
|
|
387
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
392
388
|
author: bob,
|
|
393
389
|
filter: { protocol }
|
|
394
390
|
});
|
|
395
|
-
const bobRecordsQueryReply =
|
|
391
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
396
392
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
397
|
-
expect(
|
|
393
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(3);
|
|
398
394
|
// sanity verify Alice herself is able to query for the chat message from Bob's DWN
|
|
399
|
-
const recordsQueryByAlice =
|
|
395
|
+
const recordsQueryByAlice = await RecordsQuery.create({
|
|
400
396
|
signer: Jws.createSigner(alice),
|
|
401
397
|
protocolRole: 'thread/participant',
|
|
402
398
|
filter: {
|
|
@@ -405,11 +401,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
405
401
|
protocolPath: 'thread/chat'
|
|
406
402
|
}
|
|
407
403
|
});
|
|
408
|
-
const aliceRecordsQueryReply =
|
|
404
|
+
const aliceRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByAlice.message);
|
|
409
405
|
expect(aliceRecordsQueryReply.status.code).toBe(200);
|
|
410
|
-
expect(
|
|
406
|
+
expect(aliceRecordsQueryReply.entries?.length).toBe(1);
|
|
411
407
|
// verify device X is able to query for the chat message from Bob's DWN
|
|
412
|
-
const recordsQueryByDeviceX =
|
|
408
|
+
const recordsQueryByDeviceX = await RecordsQuery.create({
|
|
413
409
|
signer: Jws.createSigner(deviceX),
|
|
414
410
|
delegatedGrant: queryGrantForDeviceX.dataEncodedMessage,
|
|
415
411
|
protocolRole: 'thread/participant',
|
|
@@ -419,11 +415,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
419
415
|
protocolPath: 'thread/chat'
|
|
420
416
|
}
|
|
421
417
|
});
|
|
422
|
-
const deviceXRecordsQueryReply =
|
|
418
|
+
const deviceXRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
|
|
423
419
|
expect(deviceXRecordsQueryReply.status.code).toBe(200);
|
|
424
|
-
expect(
|
|
420
|
+
expect(deviceXRecordsQueryReply.entries?.length).toBe(1);
|
|
425
421
|
// verify device X is able to read the chat message from Bob's DWN
|
|
426
|
-
const recordsReadByDeviceX =
|
|
422
|
+
const recordsReadByDeviceX = await RecordsRead.create({
|
|
427
423
|
signer: Jws.createSigner(deviceX),
|
|
428
424
|
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
429
425
|
protocolRole: 'thread/participant',
|
|
@@ -431,11 +427,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
431
427
|
recordId: chatRecord.message.recordId
|
|
432
428
|
}
|
|
433
429
|
});
|
|
434
|
-
const deviceXRecordsReadReply =
|
|
430
|
+
const deviceXRecordsReadReply = await dwn.processMessage(bob.did, recordsReadByDeviceX.message);
|
|
435
431
|
expect(deviceXRecordsReadReply.status.code).toBe(200);
|
|
436
|
-
expect(
|
|
432
|
+
expect(deviceXRecordsReadReply.entry.recordsWrite?.recordId).toBe(chatRecord.message.recordId);
|
|
437
433
|
// Verify that Carol cannot query as Alice by invoking the delegated grant granted to Device X
|
|
438
|
-
const recordsQueryByCarol =
|
|
434
|
+
const recordsQueryByCarol = await RecordsQuery.create({
|
|
439
435
|
signer: Jws.createSigner(carol),
|
|
440
436
|
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
441
437
|
protocolRole: 'thread/participant',
|
|
@@ -445,11 +441,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
445
441
|
protocolPath: 'thread/chat'
|
|
446
442
|
}
|
|
447
443
|
});
|
|
448
|
-
const recordsQueryByCarolReply =
|
|
444
|
+
const recordsQueryByCarolReply = await dwn.processMessage(bob.did, recordsQueryByCarol.message);
|
|
449
445
|
expect(recordsQueryByCarolReply.status.code).toBe(400);
|
|
450
446
|
expect(recordsQueryByCarolReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
451
447
|
// Verify that Carol cannot read as Alice by invoking the delegated grant granted to Device X
|
|
452
|
-
const recordsReadByCarol =
|
|
448
|
+
const recordsReadByCarol = await RecordsRead.create({
|
|
453
449
|
signer: Jws.createSigner(carol),
|
|
454
450
|
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
455
451
|
protocolRole: 'thread/participant',
|
|
@@ -457,11 +453,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
457
453
|
recordId: chatRecord.message.recordId
|
|
458
454
|
}
|
|
459
455
|
});
|
|
460
|
-
const recordsReadByCarolReply =
|
|
456
|
+
const recordsReadByCarolReply = await dwn.processMessage(bob.did, recordsReadByCarol.message);
|
|
461
457
|
expect(recordsReadByCarolReply.status.code).toBe(400);
|
|
462
458
|
expect(recordsQueryByCarolReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
463
|
-
})
|
|
464
|
-
it('should only allow correct entity invoking an author-delegated grant to subscribe', () =>
|
|
459
|
+
});
|
|
460
|
+
it('should only allow correct entity invoking an author-delegated grant to subscribe', async () => {
|
|
465
461
|
// scenario:
|
|
466
462
|
// 1. Bob installs a chat protocol and creates a thread, adding Alice as a participant.
|
|
467
463
|
// 2. Alice a creates subscribe delegated grant for device X,
|
|
@@ -471,30 +467,29 @@ export function testAuthorDelegatedGrant() {
|
|
|
471
467
|
// 6. The subscription should have received the chat messages.
|
|
472
468
|
// 7. Bob deletes one of the chat messages.
|
|
473
469
|
// 8. The subscription should have received the delete event.
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
const
|
|
477
|
-
const
|
|
478
|
-
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
470
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
471
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
472
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
473
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
479
474
|
// Bob has the chat protocol installed
|
|
480
475
|
const protocolDefinition = threadRoleProtocolDefinition;
|
|
481
476
|
const protocol = threadRoleProtocolDefinition.protocol;
|
|
482
|
-
const protocolsConfig =
|
|
477
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
483
478
|
author: bob,
|
|
484
479
|
protocolDefinition
|
|
485
480
|
});
|
|
486
|
-
const protocolsConfigureReply =
|
|
481
|
+
const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
487
482
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
488
483
|
// Bob starts a chat thread
|
|
489
|
-
const threadRecord =
|
|
484
|
+
const threadRecord = await TestDataGenerator.generateRecordsWrite({
|
|
490
485
|
author: bob,
|
|
491
486
|
protocol: protocolDefinition.protocol,
|
|
492
487
|
protocolPath: 'thread',
|
|
493
488
|
});
|
|
494
|
-
const threadRoleReply =
|
|
489
|
+
const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
495
490
|
expect(threadRoleReply.status.code).toBe(202);
|
|
496
491
|
// Bob adds Alice as a participant in the thread
|
|
497
|
-
const participantRoleRecord =
|
|
492
|
+
const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
|
|
498
493
|
author: bob,
|
|
499
494
|
recipient: alice.did,
|
|
500
495
|
protocol: protocolDefinition.protocol,
|
|
@@ -502,10 +497,10 @@ export function testAuthorDelegatedGrant() {
|
|
|
502
497
|
parentContextId: threadRecord.message.contextId,
|
|
503
498
|
data: new TextEncoder().encode('Alice is my friend'),
|
|
504
499
|
});
|
|
505
|
-
const participantRoleReply =
|
|
500
|
+
const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
506
501
|
expect(participantRoleReply.status.code).toBe(202);
|
|
507
502
|
// Alice creates a delegated subscribe grant for device X to act as Alice.
|
|
508
|
-
const subscribeGrantForDeviceX =
|
|
503
|
+
const subscribeGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
509
504
|
delegated: true, // this is a delegated grant
|
|
510
505
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
511
506
|
grantedTo: deviceX.did,
|
|
@@ -518,8 +513,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
518
513
|
});
|
|
519
514
|
// Create a handler to set or delete the chat record ID in the subscription set depending on the interface method
|
|
520
515
|
const subscriptionChatRecords = new Set();
|
|
521
|
-
const captureChatRecords = (
|
|
522
|
-
|
|
516
|
+
const captureChatRecords = async (msg) => {
|
|
517
|
+
if (msg.type !== 'event') {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const { message } = msg.event;
|
|
523
521
|
if (message.descriptor.method === DwnMethodName.Delete) {
|
|
524
522
|
const recordId = message.descriptor.recordId;
|
|
525
523
|
subscriptionChatRecords.delete(recordId);
|
|
@@ -528,9 +526,9 @@ export function testAuthorDelegatedGrant() {
|
|
|
528
526
|
const recordId = message.recordId;
|
|
529
527
|
subscriptionChatRecords.add(recordId);
|
|
530
528
|
}
|
|
531
|
-
}
|
|
529
|
+
};
|
|
532
530
|
// control: verify that device X cannot subscribe to the chat thread without the delegated grant
|
|
533
|
-
const recordsSubscribeByDeviceXWithoutGrant =
|
|
531
|
+
const recordsSubscribeByDeviceXWithoutGrant = await RecordsSubscribe.create({
|
|
534
532
|
signer: Jws.createSigner(deviceX),
|
|
535
533
|
protocolRole: 'thread/participant',
|
|
536
534
|
filter: {
|
|
@@ -539,10 +537,10 @@ export function testAuthorDelegatedGrant() {
|
|
|
539
537
|
protocolPath: 'thread/chat'
|
|
540
538
|
}
|
|
541
539
|
});
|
|
542
|
-
const recordsSubscribeByDeviceXWithoutGrantReply =
|
|
540
|
+
const recordsSubscribeByDeviceXWithoutGrantReply = await dwn.processMessage(bob.did, recordsSubscribeByDeviceXWithoutGrant.message);
|
|
543
541
|
expect(recordsSubscribeByDeviceXWithoutGrantReply.status.code).toBe(401, 'device X without grant subscribe');
|
|
544
542
|
// control: verify that Carol cannot subscribe as Alice by invoking the delegated grant granted to Device X
|
|
545
|
-
const recordsSubscribeByCarol =
|
|
543
|
+
const recordsSubscribeByCarol = await RecordsSubscribe.create({
|
|
546
544
|
signer: Jws.createSigner(carol),
|
|
547
545
|
delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
|
|
548
546
|
protocolRole: 'thread/participant',
|
|
@@ -552,11 +550,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
552
550
|
protocolPath: 'thread/chat'
|
|
553
551
|
}
|
|
554
552
|
});
|
|
555
|
-
const recordsSubscribeByCarolReply =
|
|
553
|
+
const recordsSubscribeByCarolReply = await dwn.processMessage(bob.did, recordsSubscribeByCarol.message);
|
|
556
554
|
expect(recordsSubscribeByCarolReply.status.code).toBe(400, 'carol subscribe');
|
|
557
555
|
expect(recordsSubscribeByCarolReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
558
556
|
// verify device X is able to subscribe the chat message from Bob's DWN using the delegated grant
|
|
559
|
-
const recordsSubscribeByDeviceX =
|
|
557
|
+
const recordsSubscribeByDeviceX = await RecordsSubscribe.create({
|
|
560
558
|
signer: Jws.createSigner(deviceX),
|
|
561
559
|
delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
|
|
562
560
|
protocolRole: 'thread/participant',
|
|
@@ -566,84 +564,83 @@ export function testAuthorDelegatedGrant() {
|
|
|
566
564
|
protocolPath: 'thread/chat'
|
|
567
565
|
}
|
|
568
566
|
});
|
|
569
|
-
const recordsSubscribeByDeviceXReply =
|
|
567
|
+
const recordsSubscribeByDeviceXReply = await dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message, {
|
|
570
568
|
subscriptionHandler: captureChatRecords
|
|
571
569
|
});
|
|
572
570
|
expect(recordsSubscribeByDeviceXReply.status.code).toBe(200, 'subscribe');
|
|
573
571
|
// Bob writes chat messages in the thread
|
|
574
|
-
const chatRecord1 =
|
|
572
|
+
const chatRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
575
573
|
author: bob,
|
|
576
574
|
protocol: protocolDefinition.protocol,
|
|
577
575
|
protocolPath: 'thread/chat',
|
|
578
576
|
parentContextId: threadRecord.message.contextId,
|
|
579
577
|
});
|
|
580
|
-
const chatRecord1Reply =
|
|
578
|
+
const chatRecord1Reply = await dwn.processMessage(bob.did, chatRecord1.message, { dataStream: chatRecord1.dataStream });
|
|
581
579
|
expect(chatRecord1Reply.status.code).toBe(202);
|
|
582
|
-
const chatRecord2 =
|
|
580
|
+
const chatRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
583
581
|
author: bob,
|
|
584
582
|
protocol: protocolDefinition.protocol,
|
|
585
583
|
protocolPath: 'thread/chat',
|
|
586
584
|
parentContextId: threadRecord.message.contextId,
|
|
587
585
|
});
|
|
588
|
-
const chatRecord2Reply =
|
|
586
|
+
const chatRecord2Reply = await dwn.processMessage(bob.did, chatRecord2.message, { dataStream: chatRecord2.dataStream });
|
|
589
587
|
expect(chatRecord2Reply.status.code).toBe(202);
|
|
590
|
-
|
|
588
|
+
await Poller.pollUntilSuccessOrTimeout(async () => {
|
|
591
589
|
expect(subscriptionChatRecords.size).toBe(2);
|
|
592
590
|
expect([...subscriptionChatRecords]).toEqual(expect.arrayContaining([chatRecord1.message.recordId, chatRecord2.message.recordId]));
|
|
593
|
-
})
|
|
594
|
-
|
|
595
|
-
})
|
|
596
|
-
it('should only allow correct entity invoking an author-delegated grant to delete', () =>
|
|
597
|
-
var _a, _b;
|
|
591
|
+
});
|
|
592
|
+
await recordsSubscribeByDeviceXReply.subscription?.close();
|
|
593
|
+
});
|
|
594
|
+
it('should only allow correct entity invoking an author-delegated grant to delete', async () => {
|
|
598
595
|
// scenario:
|
|
599
596
|
// 1. Bob installs the chat protocol on his DWN and makes Alice an admin
|
|
600
597
|
// 2. Bob starts a chat thread with Carol on his DWN
|
|
601
598
|
// 3. Alice creates a delegated grant for Device X to act as her
|
|
602
599
|
// 4. Carol should not be able to delete a chat message as Alice using Device X's delegated grant
|
|
603
600
|
// 5. Device X should be able to delete a chat message as Alice
|
|
604
|
-
const alice =
|
|
605
|
-
const deviceX =
|
|
606
|
-
const bob =
|
|
607
|
-
const carol =
|
|
601
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
602
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
603
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
604
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
608
605
|
// Bob has the chat protocol installed
|
|
609
606
|
const protocolDefinition = threadRoleProtocolDefinition;
|
|
610
607
|
const protocol = threadRoleProtocolDefinition.protocol;
|
|
611
|
-
const protocolsConfig =
|
|
608
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
612
609
|
author: bob,
|
|
613
610
|
protocolDefinition
|
|
614
611
|
});
|
|
615
|
-
const protocolsConfigureReply =
|
|
612
|
+
const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
616
613
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
617
614
|
// Bob adds Alice as an admin
|
|
618
|
-
const globalAdminRecord =
|
|
615
|
+
const globalAdminRecord = await TestDataGenerator.generateRecordsWrite({
|
|
619
616
|
author: bob,
|
|
620
617
|
recipient: alice.did,
|
|
621
618
|
protocol: protocolDefinition.protocol,
|
|
622
619
|
protocolPath: 'globalAdmin',
|
|
623
620
|
data: new TextEncoder().encode('I trust Alice to manage my chat thread'),
|
|
624
621
|
});
|
|
625
|
-
const globalAdminRecordReply =
|
|
622
|
+
const globalAdminRecordReply = await dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
|
|
626
623
|
expect(globalAdminRecordReply.status.code).toBe(202);
|
|
627
624
|
// Bob starts a chat thread
|
|
628
|
-
const threadRecord =
|
|
625
|
+
const threadRecord = await TestDataGenerator.generateRecordsWrite({
|
|
629
626
|
author: bob,
|
|
630
627
|
protocol: protocolDefinition.protocol,
|
|
631
628
|
protocolPath: 'thread',
|
|
632
629
|
});
|
|
633
|
-
const threadRoleReply =
|
|
630
|
+
const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
634
631
|
expect(threadRoleReply.status.code).toBe(202);
|
|
635
632
|
// Bob adds Carol as a participant in the thread
|
|
636
|
-
const participantRoleRecord =
|
|
633
|
+
const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
|
|
637
634
|
author: bob,
|
|
638
635
|
recipient: carol.did,
|
|
639
636
|
protocol: protocolDefinition.protocol,
|
|
640
637
|
protocolPath: 'thread/participant',
|
|
641
638
|
parentContextId: threadRecord.message.contextId
|
|
642
639
|
});
|
|
643
|
-
const participantRoleReply =
|
|
640
|
+
const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
644
641
|
expect(participantRoleReply.status.code).toBe(202);
|
|
645
642
|
// Carol writes a chat message in the thread
|
|
646
|
-
const chatRecord =
|
|
643
|
+
const chatRecord = await TestDataGenerator.generateRecordsWrite({
|
|
647
644
|
author: carol,
|
|
648
645
|
protocolRole: 'thread/participant',
|
|
649
646
|
protocol: protocolDefinition.protocol,
|
|
@@ -651,10 +648,10 @@ export function testAuthorDelegatedGrant() {
|
|
|
651
648
|
parentContextId: threadRecord.message.contextId,
|
|
652
649
|
data: new TextEncoder().encode('A rude message'),
|
|
653
650
|
});
|
|
654
|
-
const chatRecordReply =
|
|
651
|
+
const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
655
652
|
expect(chatRecordReply.status.code).toBe(202);
|
|
656
653
|
// Alice creates a delegated delete grant for device X to act as Alice.
|
|
657
|
-
const deleteGrantForDeviceX =
|
|
654
|
+
const deleteGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
658
655
|
delegated: true, // this is a delegated grant
|
|
659
656
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
660
657
|
grantedTo: deviceX.did,
|
|
@@ -666,54 +663,53 @@ export function testAuthorDelegatedGrant() {
|
|
|
666
663
|
signer: Jws.createSigner(alice)
|
|
667
664
|
});
|
|
668
665
|
// verify Carol is not able to delete Carol's chat message from Bob's DWN
|
|
669
|
-
const recordsDeleteByCarol =
|
|
666
|
+
const recordsDeleteByCarol = await RecordsDelete.create({
|
|
670
667
|
signer: Jws.createSigner(carol),
|
|
671
668
|
delegatedGrant: deleteGrantForDeviceX.dataEncodedMessage,
|
|
672
669
|
protocolRole: 'thread/participant',
|
|
673
670
|
recordId: chatRecord.message.recordId
|
|
674
671
|
});
|
|
675
|
-
const carolRecordsDeleteReply =
|
|
672
|
+
const carolRecordsDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByCarol.message);
|
|
676
673
|
expect(carolRecordsDeleteReply.status.code).toBe(400);
|
|
677
674
|
// sanity verify the chat message is still in Bob's DWN
|
|
678
|
-
const recordsQueryByBob =
|
|
675
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
679
676
|
author: bob,
|
|
680
677
|
filter: { protocolPath: 'thread/chat' }
|
|
681
678
|
});
|
|
682
|
-
const bobRecordsQueryReply =
|
|
679
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
683
680
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
684
|
-
expect(
|
|
681
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(1);
|
|
685
682
|
// verify device X is able to delete Carol's chat message from Bob's DWN
|
|
686
|
-
const recordsDeleteByDeviceX =
|
|
683
|
+
const recordsDeleteByDeviceX = await RecordsDelete.create({
|
|
687
684
|
signer: Jws.createSigner(deviceX),
|
|
688
685
|
delegatedGrant: deleteGrantForDeviceX.dataEncodedMessage,
|
|
689
686
|
protocolRole: 'globalAdmin',
|
|
690
687
|
recordId: chatRecord.message.recordId
|
|
691
688
|
});
|
|
692
|
-
const deviceXRecordsDeleteReply =
|
|
689
|
+
const deviceXRecordsDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
|
|
693
690
|
expect(deviceXRecordsDeleteReply.status.code).toBe(202);
|
|
694
691
|
// sanity verify the chat message is no longer queryable from Bob's DWN
|
|
695
|
-
const bobRecordsQueryReply2 =
|
|
692
|
+
const bobRecordsQueryReply2 = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
696
693
|
expect(bobRecordsQueryReply2.status.code).toBe(200);
|
|
697
|
-
expect(
|
|
698
|
-
})
|
|
699
|
-
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke write', () =>
|
|
700
|
-
var _a;
|
|
694
|
+
expect(bobRecordsQueryReply2.entries?.length).toBe(0);
|
|
695
|
+
});
|
|
696
|
+
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke write', async () => {
|
|
701
697
|
// scenario:
|
|
702
698
|
// 1. Bob has the message protocol installed
|
|
703
699
|
// 2. Alice creates a non-delegated grant for device X
|
|
704
700
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the non-delegated grant
|
|
705
701
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
706
|
-
const alice =
|
|
707
|
-
const bob =
|
|
708
|
-
const deviceX =
|
|
702
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
703
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
704
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
709
705
|
// 1. Bob has the message protocol installed
|
|
710
706
|
const protocolDefinition = messageProtocolDefinition;
|
|
711
707
|
const protocol = protocolDefinition.protocol;
|
|
712
|
-
const protocolsConfig =
|
|
708
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
713
709
|
author: bob,
|
|
714
710
|
protocolDefinition
|
|
715
711
|
});
|
|
716
|
-
const protocolConfigureReply =
|
|
712
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
717
713
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
718
714
|
// 2. Alice creates a non-delegated grant for device X
|
|
719
715
|
const scope = {
|
|
@@ -721,7 +717,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
721
717
|
method: DwnMethodName.Write,
|
|
722
718
|
protocol
|
|
723
719
|
};
|
|
724
|
-
const deviceXGrant =
|
|
720
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
725
721
|
// delegated : true, // intentionally commented out to show that this is not a delegated grant
|
|
726
722
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
727
723
|
grantedTo: deviceX.did,
|
|
@@ -731,7 +727,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
731
727
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the non-delegated grant
|
|
732
728
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
733
729
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
734
|
-
const messageByDeviceX =
|
|
730
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
735
731
|
signer: Jws.createSigner(deviceX),
|
|
736
732
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
737
733
|
protocol,
|
|
@@ -740,48 +736,48 @@ export function testAuthorDelegatedGrant() {
|
|
|
740
736
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
741
737
|
data: deviceXData
|
|
742
738
|
});
|
|
743
|
-
const deviceXWriteReply =
|
|
739
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
744
740
|
expect(deviceXWriteReply.status.code).toBe(400);
|
|
745
741
|
expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
|
|
746
742
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
747
|
-
const recordsQueryByBob =
|
|
743
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
748
744
|
author: bob,
|
|
749
745
|
filter: { protocol }
|
|
750
746
|
});
|
|
751
|
-
const bobRecordsQueryReply =
|
|
747
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
752
748
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
753
|
-
expect(
|
|
754
|
-
})
|
|
755
|
-
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke read', () =>
|
|
749
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(0);
|
|
750
|
+
});
|
|
751
|
+
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke read', async () => {
|
|
756
752
|
// scenario:
|
|
757
753
|
// 1. Bob has the message protocol installed
|
|
758
754
|
// 2. Alice writes a message to Bob's DWN
|
|
759
755
|
// 3. Alice creates a non-delegated read grant for device X
|
|
760
756
|
// 4. Verify that device X cannot read the message from Bob's DWN as Alice using the non-delegated grant
|
|
761
|
-
const alice =
|
|
762
|
-
const bob =
|
|
763
|
-
const deviceX =
|
|
757
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
758
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
759
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
764
760
|
// 1. Bob has the message protocol installed
|
|
765
761
|
const protocolDefinition = messageProtocolDefinition;
|
|
766
762
|
const protocol = protocolDefinition.protocol;
|
|
767
|
-
const protocolsConfig =
|
|
763
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
768
764
|
author: bob,
|
|
769
765
|
protocolDefinition
|
|
770
766
|
});
|
|
771
|
-
const protocolConfigureReply =
|
|
767
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
772
768
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
773
769
|
// 2. Alice writes a message to Bob's DWN
|
|
774
|
-
const messageByAlice =
|
|
770
|
+
const messageByAlice = await TestDataGenerator.generateRecordsWrite({
|
|
775
771
|
author: alice,
|
|
776
772
|
protocol,
|
|
777
773
|
protocolPath: 'message',
|
|
778
774
|
schema: protocolDefinition.types.message.schema,
|
|
779
775
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
780
776
|
});
|
|
781
|
-
const aliceWriteReply =
|
|
777
|
+
const aliceWriteReply = await dwn.processMessage(bob.did, messageByAlice.message, { dataStream: messageByAlice.dataStream });
|
|
782
778
|
expect(aliceWriteReply.status.code).toBe(202);
|
|
783
779
|
// 3. Alice creates a non-delegated read grant for device X
|
|
784
|
-
const deviceXGrant =
|
|
780
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
785
781
|
// delegated : true, // intentionally commented out to show that this is not a delegated grant
|
|
786
782
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
787
783
|
grantedTo: deviceX.did,
|
|
@@ -793,36 +789,36 @@ export function testAuthorDelegatedGrant() {
|
|
|
793
789
|
signer: Jws.createSigner(alice)
|
|
794
790
|
});
|
|
795
791
|
// 4. Verify that device X cannot read the message from Bob's DWN as Alice using the non-delegated grant
|
|
796
|
-
const recordsReadByDeviceX =
|
|
792
|
+
const recordsReadByDeviceX = await RecordsRead.create({
|
|
797
793
|
signer: Jws.createSigner(deviceX),
|
|
798
794
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
799
795
|
filter: {
|
|
800
796
|
recordId: messageByAlice.message.recordId
|
|
801
797
|
}
|
|
802
798
|
});
|
|
803
|
-
const deviceXReadReply =
|
|
799
|
+
const deviceXReadReply = await dwn.processMessage(bob.did, recordsReadByDeviceX.message);
|
|
804
800
|
expect(deviceXReadReply.status.code).toBe(400);
|
|
805
801
|
expect(deviceXReadReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
|
|
806
|
-
})
|
|
807
|
-
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke query', () =>
|
|
802
|
+
});
|
|
803
|
+
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke query', async () => {
|
|
808
804
|
// scenario:
|
|
809
805
|
// 1. Bob has the message protocol installed
|
|
810
806
|
// 2. Alice creates a non-delegated query grant for device X
|
|
811
807
|
// 3. Verify that device X cannot query Bob's DWN as Alice using the non-delegated grant
|
|
812
|
-
const alice =
|
|
813
|
-
const bob =
|
|
814
|
-
const deviceX =
|
|
808
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
809
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
810
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
815
811
|
// 1. Bob has the message protocol installed
|
|
816
812
|
const protocolDefinition = messageProtocolDefinition;
|
|
817
813
|
const protocol = protocolDefinition.protocol;
|
|
818
|
-
const protocolsConfig =
|
|
814
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
819
815
|
author: bob,
|
|
820
816
|
protocolDefinition
|
|
821
817
|
});
|
|
822
|
-
const protocolConfigureReply =
|
|
818
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
823
819
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
824
820
|
// 2. Alice creates a non-delegated query grant for device X
|
|
825
|
-
const deviceXGrant =
|
|
821
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
826
822
|
// delegated : true, // intentionally commented out to show that this is not a delegated grant
|
|
827
823
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
828
824
|
grantedTo: deviceX.did,
|
|
@@ -834,7 +830,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
834
830
|
signer: Jws.createSigner(alice)
|
|
835
831
|
});
|
|
836
832
|
// 3. Verify that device X cannot query Bob's DWN as Alice using the non-delegated grant
|
|
837
|
-
const recordsQueryByDeviceX =
|
|
833
|
+
const recordsQueryByDeviceX = await RecordsQuery.create({
|
|
838
834
|
signer: Jws.createSigner(deviceX),
|
|
839
835
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
840
836
|
filter: {
|
|
@@ -842,42 +838,41 @@ export function testAuthorDelegatedGrant() {
|
|
|
842
838
|
protocolPath: 'message'
|
|
843
839
|
}
|
|
844
840
|
});
|
|
845
|
-
const deviceXQueryReply =
|
|
841
|
+
const deviceXQueryReply = await dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
|
|
846
842
|
expect(deviceXQueryReply.status.code).toBe(400);
|
|
847
843
|
expect(deviceXQueryReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
|
|
848
|
-
})
|
|
849
|
-
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke delete', () =>
|
|
850
|
-
var _a;
|
|
844
|
+
});
|
|
845
|
+
it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke delete', async () => {
|
|
851
846
|
// scenario:
|
|
852
847
|
// 1. Bob has the message protocol installed
|
|
853
848
|
// 2. Alice writes a message to Bob's DWN
|
|
854
849
|
// 3. Alice creates a non-delegated delete grant for device X
|
|
855
850
|
// 4. Verify that device X cannot delete the message from Bob's DWN as Alice using the non-delegated grant
|
|
856
851
|
// 5. Sanity verify the message still exists in Bob's DWN
|
|
857
|
-
const alice =
|
|
858
|
-
const bob =
|
|
859
|
-
const deviceX =
|
|
852
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
853
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
854
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
860
855
|
// 1. Bob has the message protocol installed
|
|
861
856
|
const protocolDefinition = messageProtocolDefinition;
|
|
862
857
|
const protocol = protocolDefinition.protocol;
|
|
863
|
-
const protocolsConfig =
|
|
858
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
864
859
|
author: bob,
|
|
865
860
|
protocolDefinition
|
|
866
861
|
});
|
|
867
|
-
const protocolConfigureReply =
|
|
862
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
868
863
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
869
864
|
// 2. Alice writes a message to Bob's DWN
|
|
870
|
-
const messageByAlice =
|
|
865
|
+
const messageByAlice = await TestDataGenerator.generateRecordsWrite({
|
|
871
866
|
author: alice,
|
|
872
867
|
protocol,
|
|
873
868
|
protocolPath: 'message',
|
|
874
869
|
schema: protocolDefinition.types.message.schema,
|
|
875
870
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
876
871
|
});
|
|
877
|
-
const aliceWriteReply =
|
|
872
|
+
const aliceWriteReply = await dwn.processMessage(bob.did, messageByAlice.message, { dataStream: messageByAlice.dataStream });
|
|
878
873
|
expect(aliceWriteReply.status.code).toBe(202);
|
|
879
874
|
// 3. Alice creates a non-delegated delete grant for device X
|
|
880
|
-
const deviceXGrant =
|
|
875
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
881
876
|
// delegated : true, // intentionally commented out to show that this is not a delegated grant
|
|
882
877
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
883
878
|
grantedTo: deviceX.did,
|
|
@@ -889,39 +884,39 @@ export function testAuthorDelegatedGrant() {
|
|
|
889
884
|
signer: Jws.createSigner(alice)
|
|
890
885
|
});
|
|
891
886
|
// 4. Verify that device X cannot delete the message from Bob's DWN as Alice using the non-delegated grant
|
|
892
|
-
const recordsDeleteByDeviceX =
|
|
887
|
+
const recordsDeleteByDeviceX = await RecordsDelete.create({
|
|
893
888
|
signer: Jws.createSigner(deviceX),
|
|
894
889
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
895
890
|
recordId: messageByAlice.message.recordId
|
|
896
891
|
});
|
|
897
|
-
const deviceXDeleteReply =
|
|
892
|
+
const deviceXDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
|
|
898
893
|
expect(deviceXDeleteReply.status.code).toBe(400);
|
|
899
894
|
expect(deviceXDeleteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
|
|
900
895
|
// 5. Sanity verify the message still exists in Bob's DWN
|
|
901
|
-
const recordsQueryByBob =
|
|
896
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
902
897
|
author: bob,
|
|
903
898
|
filter: { protocol }
|
|
904
899
|
});
|
|
905
|
-
const bobRecordsQueryReply =
|
|
900
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
906
901
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
907
|
-
expect(
|
|
908
|
-
})
|
|
909
|
-
it('should fail if author-delegated grant has a mismatching protocol scope - write', () =>
|
|
902
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(1);
|
|
903
|
+
});
|
|
904
|
+
it('should fail if author-delegated grant has a mismatching protocol scope - write', async () => {
|
|
910
905
|
// scenario:
|
|
911
906
|
// 1. Alice creates a delegated grant for device X to act as her for a protocol that is NOT email protocol
|
|
912
907
|
// 2. Bob has email protocol configured for his DWN that allows anyone to write an email to him
|
|
913
908
|
// 3. Device X attempts to use the delegated grant to write an email to Bob as Alice
|
|
914
909
|
// 4. Bob's DWN should reject Device X's message
|
|
915
|
-
const alice =
|
|
916
|
-
const deviceX =
|
|
917
|
-
const bob =
|
|
910
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
911
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
912
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
918
913
|
// 1. Alice creates a delegated grant for device X to act as her for a protocol that is NOT email protocol
|
|
919
914
|
const scope = {
|
|
920
915
|
interface: DwnInterfaceName.Records,
|
|
921
916
|
method: DwnMethodName.Write,
|
|
922
917
|
protocol: 'random-protocol'
|
|
923
918
|
};
|
|
924
|
-
const deviceXGrant =
|
|
919
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
925
920
|
delegated: true, // this is a delegated grant
|
|
926
921
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
927
922
|
grantedTo: deviceX.did,
|
|
@@ -931,16 +926,16 @@ export function testAuthorDelegatedGrant() {
|
|
|
931
926
|
// 2. Bob has email protocol configured for his DWN that allows anyone to write an email to him
|
|
932
927
|
const protocolDefinition = emailProtocolDefinition;
|
|
933
928
|
const protocol = protocolDefinition.protocol;
|
|
934
|
-
const protocolsConfig =
|
|
929
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
935
930
|
author: bob,
|
|
936
931
|
protocolDefinition
|
|
937
932
|
});
|
|
938
|
-
const protocolConfigureReply =
|
|
933
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
939
934
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
940
935
|
// 3. Device X attempts to use the delegated grant to write an email to Bob as Alice
|
|
941
936
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
942
937
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
943
|
-
const messageByDeviceX =
|
|
938
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
944
939
|
signer: Jws.createSigner(deviceX),
|
|
945
940
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
946
941
|
protocol,
|
|
@@ -949,38 +944,38 @@ export function testAuthorDelegatedGrant() {
|
|
|
949
944
|
dataFormat: protocolDefinition.types.email.dataFormats[0],
|
|
950
945
|
data: deviceXData
|
|
951
946
|
});
|
|
952
|
-
const deviceXWriteReply =
|
|
947
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
953
948
|
expect(deviceXWriteReply.status.code).toBe(401);
|
|
954
949
|
expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
955
|
-
})
|
|
956
|
-
it('should fail if author-delegated grant has a mismatching protocol scope - query, subscribe & read', () =>
|
|
950
|
+
});
|
|
951
|
+
it('should fail if author-delegated grant has a mismatching protocol scope - query, subscribe & read', async () => {
|
|
957
952
|
// scenario:
|
|
958
953
|
// 1. Bob starts a chat thread with Alice on his DWN
|
|
959
954
|
// 2. Alice creates a delegated grant for device X to act as her for a protocol that is NOT chat protocol
|
|
960
955
|
// 3. Device X attempts to use the delegated grant to read, query and subscribe to the chat thread and gets rejected by Bob's DWN
|
|
961
|
-
const alice =
|
|
962
|
-
const deviceX =
|
|
963
|
-
const bob =
|
|
956
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
957
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
958
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
964
959
|
// 1. Bob starts a chat thread with Alice on his DWN
|
|
965
960
|
// Bob has the chat protocol installed
|
|
966
961
|
const protocolDefinition = threadRoleProtocolDefinition;
|
|
967
962
|
const protocol = threadRoleProtocolDefinition.protocol;
|
|
968
|
-
const protocolsConfig =
|
|
963
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
969
964
|
author: bob,
|
|
970
965
|
protocolDefinition
|
|
971
966
|
});
|
|
972
|
-
const protocolsConfigureReply =
|
|
967
|
+
const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
973
968
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
974
969
|
// Bob starts a chat thread
|
|
975
|
-
const threadRecord =
|
|
970
|
+
const threadRecord = await TestDataGenerator.generateRecordsWrite({
|
|
976
971
|
author: bob,
|
|
977
972
|
protocol: protocolDefinition.protocol,
|
|
978
973
|
protocolPath: 'thread',
|
|
979
974
|
});
|
|
980
|
-
const threadRoleReply =
|
|
975
|
+
const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
981
976
|
expect(threadRoleReply.status.code).toBe(202);
|
|
982
977
|
// Bob adds Alice as a participant in the thread
|
|
983
|
-
const participantRoleRecord =
|
|
978
|
+
const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
|
|
984
979
|
author: bob,
|
|
985
980
|
recipient: alice.did,
|
|
986
981
|
protocol: protocolDefinition.protocol,
|
|
@@ -988,20 +983,20 @@ export function testAuthorDelegatedGrant() {
|
|
|
988
983
|
parentContextId: threadRecord.message.contextId,
|
|
989
984
|
data: new TextEncoder().encode('Alice is my friend'),
|
|
990
985
|
});
|
|
991
|
-
const participantRoleReply =
|
|
986
|
+
const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
992
987
|
expect(participantRoleReply.status.code).toBe(202);
|
|
993
988
|
// Bob writes a chat message in the thread
|
|
994
|
-
const chatRecord =
|
|
989
|
+
const chatRecord = await TestDataGenerator.generateRecordsWrite({
|
|
995
990
|
author: bob,
|
|
996
991
|
protocol: protocolDefinition.protocol,
|
|
997
992
|
protocolPath: 'thread/chat',
|
|
998
993
|
parentContextId: threadRecord.message.contextId,
|
|
999
994
|
});
|
|
1000
|
-
const chatRecordReply =
|
|
995
|
+
const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1001
996
|
expect(chatRecordReply.status.code).toBe(202);
|
|
1002
997
|
// 2. Alice creates a delegated grant for device X to act as her for a protocol that is NOT chat protocol
|
|
1003
998
|
// Alice creates a delegated query grant for device X to act as Alice but not for chat protocol
|
|
1004
|
-
const queryGrantForDeviceX =
|
|
999
|
+
const queryGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
1005
1000
|
delegated: true, // this is a delegated grant
|
|
1006
1001
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1007
1002
|
grantedTo: deviceX.did,
|
|
@@ -1013,7 +1008,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1013
1008
|
signer: Jws.createSigner(alice)
|
|
1014
1009
|
});
|
|
1015
1010
|
// Alice creates a delegated read grant for device X to act as Alice but not for chat protocol
|
|
1016
|
-
const readGrantForDeviceX =
|
|
1011
|
+
const readGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
1017
1012
|
delegated: true, // this is a delegated grant
|
|
1018
1013
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1019
1014
|
grantedTo: deviceX.did,
|
|
@@ -1025,7 +1020,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1025
1020
|
signer: Jws.createSigner(alice)
|
|
1026
1021
|
});
|
|
1027
1022
|
// Alice creates a delegated subscribe grant for device X to act as Alice but not for chat protocol
|
|
1028
|
-
const subscribeGrantForDeviceX =
|
|
1023
|
+
const subscribeGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
1029
1024
|
delegated: true, // this is a delegated grant
|
|
1030
1025
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1031
1026
|
grantedTo: deviceX.did,
|
|
@@ -1038,7 +1033,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1038
1033
|
});
|
|
1039
1034
|
// 3. Device X attempts to use the delegated grant to read, query and subscribe to the chat thread and gets rejected by Bob's DWN
|
|
1040
1035
|
// verify device X querying for the chat message from Bob's DWN fails
|
|
1041
|
-
const recordsQueryByDeviceX =
|
|
1036
|
+
const recordsQueryByDeviceX = await RecordsQuery.create({
|
|
1042
1037
|
signer: Jws.createSigner(deviceX),
|
|
1043
1038
|
delegatedGrant: queryGrantForDeviceX.dataEncodedMessage,
|
|
1044
1039
|
protocolRole: 'thread/participant',
|
|
@@ -1048,11 +1043,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
1048
1043
|
protocolPath: 'thread/chat'
|
|
1049
1044
|
}
|
|
1050
1045
|
});
|
|
1051
|
-
const deviceXRecordsQueryReply =
|
|
1046
|
+
const deviceXRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
|
|
1052
1047
|
expect(deviceXRecordsQueryReply.status.code).toBe(401);
|
|
1053
1048
|
expect(deviceXRecordsQueryReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch);
|
|
1054
1049
|
// verify device X reading for the chat message from Bob's DWN fails
|
|
1055
|
-
const recordsReadByDeviceX =
|
|
1050
|
+
const recordsReadByDeviceX = await RecordsRead.create({
|
|
1056
1051
|
signer: Jws.createSigner(deviceX),
|
|
1057
1052
|
delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
|
|
1058
1053
|
protocolRole: 'thread/participant',
|
|
@@ -1060,11 +1055,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
1060
1055
|
recordId: chatRecord.message.recordId
|
|
1061
1056
|
}
|
|
1062
1057
|
});
|
|
1063
|
-
const deviceXReadReply =
|
|
1058
|
+
const deviceXReadReply = await dwn.processMessage(bob.did, recordsReadByDeviceX.message);
|
|
1064
1059
|
expect(deviceXReadReply.status.code).toBe(401);
|
|
1065
1060
|
expect(deviceXReadReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
1066
1061
|
// verify device X subscribing to the chat message from Bob's DWN fails
|
|
1067
|
-
const recordsSubscribeByDeviceX =
|
|
1062
|
+
const recordsSubscribeByDeviceX = await RecordsSubscribe.create({
|
|
1068
1063
|
signer: Jws.createSigner(deviceX),
|
|
1069
1064
|
delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
|
|
1070
1065
|
protocolRole: 'thread/participant',
|
|
@@ -1074,59 +1069,58 @@ export function testAuthorDelegatedGrant() {
|
|
|
1074
1069
|
protocolPath: 'thread/chat'
|
|
1075
1070
|
}
|
|
1076
1071
|
});
|
|
1077
|
-
const deviceXRecordsSubscribeReply =
|
|
1072
|
+
const deviceXRecordsSubscribeReply = await dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message);
|
|
1078
1073
|
expect(deviceXRecordsSubscribeReply.status.code).toBe(401);
|
|
1079
1074
|
expect(deviceXRecordsSubscribeReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch);
|
|
1080
|
-
})
|
|
1081
|
-
it('should fail if author-delegated grant has a mismatching protocol scope - delete', () =>
|
|
1082
|
-
var _a;
|
|
1075
|
+
});
|
|
1076
|
+
it('should fail if author-delegated grant has a mismatching protocol scope - delete', async () => {
|
|
1083
1077
|
// scenario:
|
|
1084
1078
|
// 1. Bob installs the chat protocol on his DWN and makes Alice an admin
|
|
1085
1079
|
// 2. Bob starts a chat thread with Carol on his DWN
|
|
1086
1080
|
// 3. Alice creates a delegated delete grant for Device X to act as her for a protocol that is NOT chat protocol
|
|
1087
1081
|
// 4. Device X should NOT be able to delete a chat message as Alice
|
|
1088
|
-
const alice =
|
|
1089
|
-
const deviceX =
|
|
1090
|
-
const bob =
|
|
1091
|
-
const carol =
|
|
1082
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1083
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
1084
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
1085
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
1092
1086
|
// Bob has the chat protocol installed
|
|
1093
1087
|
const protocolDefinition = threadRoleProtocolDefinition;
|
|
1094
|
-
const protocolsConfig =
|
|
1088
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
1095
1089
|
author: bob,
|
|
1096
1090
|
protocolDefinition
|
|
1097
1091
|
});
|
|
1098
|
-
const protocolsConfigureReply =
|
|
1092
|
+
const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1099
1093
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1100
1094
|
// Bob adds Alice as an admin
|
|
1101
|
-
const globalAdminRecord =
|
|
1095
|
+
const globalAdminRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1102
1096
|
author: bob,
|
|
1103
1097
|
recipient: alice.did,
|
|
1104
1098
|
protocol: protocolDefinition.protocol,
|
|
1105
1099
|
protocolPath: 'globalAdmin',
|
|
1106
1100
|
data: new TextEncoder().encode('I trust Alice to manage my chat thread'),
|
|
1107
1101
|
});
|
|
1108
|
-
const globalAdminRecordReply =
|
|
1102
|
+
const globalAdminRecordReply = await dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
|
|
1109
1103
|
expect(globalAdminRecordReply.status.code).toBe(202);
|
|
1110
1104
|
// Bob starts a chat thread
|
|
1111
|
-
const threadRecord =
|
|
1105
|
+
const threadRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1112
1106
|
author: bob,
|
|
1113
1107
|
protocol: protocolDefinition.protocol,
|
|
1114
1108
|
protocolPath: 'thread',
|
|
1115
1109
|
});
|
|
1116
|
-
const threadRoleReply =
|
|
1110
|
+
const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
1117
1111
|
expect(threadRoleReply.status.code).toBe(202);
|
|
1118
1112
|
// Bob adds Carol as a participant in the thread
|
|
1119
|
-
const participantRoleRecord =
|
|
1113
|
+
const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1120
1114
|
author: bob,
|
|
1121
1115
|
recipient: carol.did,
|
|
1122
1116
|
protocol: protocolDefinition.protocol,
|
|
1123
1117
|
protocolPath: 'thread/participant',
|
|
1124
1118
|
parentContextId: threadRecord.message.contextId
|
|
1125
1119
|
});
|
|
1126
|
-
const participantRoleReply =
|
|
1120
|
+
const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
1127
1121
|
expect(participantRoleReply.status.code).toBe(202);
|
|
1128
1122
|
// Carol writes a chat message in the thread
|
|
1129
|
-
const chatRecord =
|
|
1123
|
+
const chatRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1130
1124
|
author: carol,
|
|
1131
1125
|
protocolRole: 'thread/participant',
|
|
1132
1126
|
protocol: protocolDefinition.protocol,
|
|
@@ -1134,10 +1128,10 @@ export function testAuthorDelegatedGrant() {
|
|
|
1134
1128
|
parentContextId: threadRecord.message.contextId,
|
|
1135
1129
|
data: new TextEncoder().encode('A rude message'),
|
|
1136
1130
|
});
|
|
1137
|
-
const chatRecordReply =
|
|
1131
|
+
const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
1138
1132
|
expect(chatRecordReply.status.code).toBe(202);
|
|
1139
1133
|
// Alice creates a delegated delete grant for Device X to act as her for a protocol that is NOT chat protocol
|
|
1140
|
-
const delegatedGrantForDeviceX =
|
|
1134
|
+
const delegatedGrantForDeviceX = await PermissionsProtocol.createGrant({
|
|
1141
1135
|
delegated: true, // this is a delegated grant
|
|
1142
1136
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1143
1137
|
grantedTo: deviceX.did,
|
|
@@ -1149,42 +1143,41 @@ export function testAuthorDelegatedGrant() {
|
|
|
1149
1143
|
signer: Jws.createSigner(alice)
|
|
1150
1144
|
});
|
|
1151
1145
|
// verify device X is NOT able to delete Carol's chat message from Bob's DWN
|
|
1152
|
-
const recordsDeleteByDeviceX =
|
|
1146
|
+
const recordsDeleteByDeviceX = await RecordsDelete.create({
|
|
1153
1147
|
signer: Jws.createSigner(deviceX),
|
|
1154
1148
|
delegatedGrant: delegatedGrantForDeviceX.dataEncodedMessage,
|
|
1155
1149
|
protocolRole: 'globalAdmin',
|
|
1156
1150
|
recordId: chatRecord.message.recordId
|
|
1157
1151
|
});
|
|
1158
|
-
const deviceXRecordsDeleteReply =
|
|
1152
|
+
const deviceXRecordsDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
|
|
1159
1153
|
expect(deviceXRecordsDeleteReply.status.code).toBe(401);
|
|
1160
1154
|
expect(deviceXRecordsDeleteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationDeleteProtocolScopeMismatch);
|
|
1161
1155
|
// sanity verify the chat message is still in Bob's DWN
|
|
1162
|
-
const recordsQueryByBob =
|
|
1156
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
1163
1157
|
author: bob,
|
|
1164
1158
|
filter: { protocolPath: 'thread/chat' }
|
|
1165
1159
|
});
|
|
1166
|
-
const bobRecordsQueryReply =
|
|
1160
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1167
1161
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1168
|
-
expect(
|
|
1169
|
-
})
|
|
1170
|
-
it('should fail if presented with an author-delegated grant with invalid grantor signature - write', () =>
|
|
1171
|
-
var _a;
|
|
1162
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(1);
|
|
1163
|
+
});
|
|
1164
|
+
it('should fail if presented with an author-delegated grant with invalid grantor signature - write', async () => {
|
|
1172
1165
|
// scenario:
|
|
1173
1166
|
// 1. Bob has the message protocol installed
|
|
1174
1167
|
// 2. Alice creates a delegated grant for device X to write as Alice, but with invalid signature
|
|
1175
1168
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the delegated grant with invalid grantor signature
|
|
1176
1169
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1177
|
-
const alice =
|
|
1178
|
-
const bob =
|
|
1179
|
-
const deviceX =
|
|
1170
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1171
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
1172
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
1180
1173
|
// 1. Bob has the message protocol installed
|
|
1181
1174
|
const protocolDefinition = messageProtocolDefinition;
|
|
1182
1175
|
const protocol = protocolDefinition.protocol;
|
|
1183
|
-
const protocolsConfig =
|
|
1176
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
1184
1177
|
author: bob,
|
|
1185
1178
|
protocolDefinition
|
|
1186
1179
|
});
|
|
1187
|
-
const protocolConfigureReply =
|
|
1180
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1188
1181
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
1189
1182
|
// 2. Alice creates a delegated grant for device X to write as Alice, but with invalid signature
|
|
1190
1183
|
const scope = {
|
|
@@ -1192,7 +1185,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1192
1185
|
method: DwnMethodName.Write,
|
|
1193
1186
|
protocol
|
|
1194
1187
|
};
|
|
1195
|
-
const deviceXGrant =
|
|
1188
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
1196
1189
|
delegated: true,
|
|
1197
1190
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1198
1191
|
grantedTo: deviceX.did,
|
|
@@ -1200,11 +1193,11 @@ export function testAuthorDelegatedGrant() {
|
|
|
1200
1193
|
signer: Jws.createSigner(alice)
|
|
1201
1194
|
});
|
|
1202
1195
|
const deviceXGrantMessage = deviceXGrant.dataEncodedMessage;
|
|
1203
|
-
deviceXGrantMessage.authorization.signature.signatures[0].signature =
|
|
1196
|
+
deviceXGrantMessage.authorization.signature.signatures[0].signature = await TestDataGenerator.randomSignatureString();
|
|
1204
1197
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the delegated grant with invalid grantor signature
|
|
1205
1198
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1206
1199
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1207
|
-
const messageByDeviceX =
|
|
1200
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
1208
1201
|
signer: Jws.createSigner(deviceX),
|
|
1209
1202
|
delegatedGrant: deviceXGrantMessage,
|
|
1210
1203
|
protocol,
|
|
@@ -1213,36 +1206,35 @@ export function testAuthorDelegatedGrant() {
|
|
|
1213
1206
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1214
1207
|
data: deviceXData
|
|
1215
1208
|
});
|
|
1216
|
-
const deviceXWriteReply =
|
|
1209
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1217
1210
|
expect(deviceXWriteReply.status.code).toBe(401);
|
|
1218
1211
|
expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
|
|
1219
1212
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1220
|
-
const recordsQueryByBob =
|
|
1213
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
1221
1214
|
author: bob,
|
|
1222
1215
|
filter: { protocol }
|
|
1223
1216
|
});
|
|
1224
|
-
const bobRecordsQueryReply =
|
|
1217
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1225
1218
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1226
|
-
expect(
|
|
1227
|
-
})
|
|
1228
|
-
it('should fail if the CID of the author-delegated grant and the grant ID in the payload of the message signature is mismatching - write', () =>
|
|
1229
|
-
var _a;
|
|
1219
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(0);
|
|
1220
|
+
});
|
|
1221
|
+
it('should fail if the CID of the author-delegated grant and the grant ID in the payload of the message signature is mismatching - write', async () => {
|
|
1230
1222
|
// scenario:
|
|
1231
1223
|
// 1. Bob has the message protocol installed
|
|
1232
1224
|
// 2. Alice creates two delegated grants for device X to write as Alice
|
|
1233
1225
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
|
|
1234
1226
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1235
|
-
const alice =
|
|
1236
|
-
const bob =
|
|
1237
|
-
const deviceX =
|
|
1227
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1228
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
1229
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
1238
1230
|
// 1. Bob has the message protocol installed
|
|
1239
1231
|
const protocolDefinition = messageProtocolDefinition;
|
|
1240
1232
|
const protocol = protocolDefinition.protocol;
|
|
1241
|
-
const protocolsConfig =
|
|
1233
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
1242
1234
|
author: bob,
|
|
1243
1235
|
protocolDefinition
|
|
1244
1236
|
});
|
|
1245
|
-
const protocolConfigureReply =
|
|
1237
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1246
1238
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
1247
1239
|
// 2. Alice creates two delegated grants for device X to write as Alice
|
|
1248
1240
|
const scope = {
|
|
@@ -1250,15 +1242,15 @@ export function testAuthorDelegatedGrant() {
|
|
|
1250
1242
|
method: DwnMethodName.Write,
|
|
1251
1243
|
protocol
|
|
1252
1244
|
};
|
|
1253
|
-
const deviceXGrant =
|
|
1245
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
1254
1246
|
delegated: true,
|
|
1255
1247
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1256
1248
|
grantedTo: deviceX.did,
|
|
1257
1249
|
scope: scope,
|
|
1258
1250
|
signer: Jws.createSigner(alice)
|
|
1259
1251
|
});
|
|
1260
|
-
|
|
1261
|
-
const deviceXGrant2 =
|
|
1252
|
+
await Time.minimalSleep();
|
|
1253
|
+
const deviceXGrant2 = await PermissionsProtocol.createGrant({
|
|
1262
1254
|
delegated: true,
|
|
1263
1255
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1264
1256
|
grantedTo: deviceX.did,
|
|
@@ -1268,7 +1260,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1268
1260
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
|
|
1269
1261
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1270
1262
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1271
|
-
const messageByDeviceX =
|
|
1263
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
1272
1264
|
signer: Jws.createSigner(deviceX),
|
|
1273
1265
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
1274
1266
|
protocol,
|
|
@@ -1278,37 +1270,36 @@ export function testAuthorDelegatedGrant() {
|
|
|
1278
1270
|
data: deviceXData
|
|
1279
1271
|
});
|
|
1280
1272
|
messageByDeviceX.message.authorization.authorDelegatedGrant = deviceXGrant2.dataEncodedMessage; // intentionally have a mismatching grant
|
|
1281
|
-
const deviceXWriteReply =
|
|
1273
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1282
1274
|
expect(deviceXWriteReply.status.code).toBe(400);
|
|
1283
1275
|
expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantCidMismatch);
|
|
1284
1276
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1285
|
-
const recordsQueryByBob =
|
|
1277
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
1286
1278
|
author: bob,
|
|
1287
1279
|
filter: { protocol }
|
|
1288
1280
|
});
|
|
1289
|
-
const bobRecordsQueryReply =
|
|
1281
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1290
1282
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1291
|
-
expect(
|
|
1292
|
-
})
|
|
1293
|
-
it('should fail if author-delegated grant is revoked - write', () =>
|
|
1294
|
-
var _a;
|
|
1283
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(0);
|
|
1284
|
+
});
|
|
1285
|
+
it('should fail if author-delegated grant is revoked - write', async () => {
|
|
1295
1286
|
// scenario:
|
|
1296
1287
|
// 1. Bob has the message protocol installed
|
|
1297
1288
|
// 2. Alice creates a delegated grant for device X to write as Alice
|
|
1298
1289
|
// 3. Alice revokes the grant
|
|
1299
1290
|
// 4. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a revoked delegated grant
|
|
1300
1291
|
// 5. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1301
|
-
const alice =
|
|
1302
|
-
const bob =
|
|
1303
|
-
const deviceX =
|
|
1292
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1293
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
1294
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
1304
1295
|
// 1. Bob has the message protocol installed
|
|
1305
1296
|
const protocolDefinition = messageProtocolDefinition;
|
|
1306
1297
|
const protocol = protocolDefinition.protocol;
|
|
1307
|
-
const protocolsConfig =
|
|
1298
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
1308
1299
|
author: bob,
|
|
1309
1300
|
protocolDefinition
|
|
1310
1301
|
});
|
|
1311
|
-
const protocolConfigureReply =
|
|
1302
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1312
1303
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
1313
1304
|
// 2. Alice creates a delegated grant for device X to write as Alice
|
|
1314
1305
|
const scope = {
|
|
@@ -1316,7 +1307,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1316
1307
|
method: DwnMethodName.Write,
|
|
1317
1308
|
protocol
|
|
1318
1309
|
};
|
|
1319
|
-
const deviceXGrant =
|
|
1310
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
1320
1311
|
delegated: true,
|
|
1321
1312
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
1322
1313
|
grantedTo: deviceX.did,
|
|
@@ -1324,20 +1315,20 @@ export function testAuthorDelegatedGrant() {
|
|
|
1324
1315
|
signer: Jws.createSigner(alice)
|
|
1325
1316
|
});
|
|
1326
1317
|
const deviceXGrantDataStream = DataStream.fromBytes(deviceXGrant.permissionGrantBytes);
|
|
1327
|
-
const permissionGrantWriteReply =
|
|
1318
|
+
const permissionGrantWriteReply = await dwn.processMessage(alice.did, deviceXGrant.recordsWrite.message, { dataStream: deviceXGrantDataStream });
|
|
1328
1319
|
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
1329
1320
|
// 3. Alice revokes the grant
|
|
1330
|
-
const permissionRevoke =
|
|
1321
|
+
const permissionRevoke = await PermissionsProtocol.createRevocation({
|
|
1331
1322
|
signer: Jws.createSigner(alice),
|
|
1332
|
-
grant:
|
|
1323
|
+
grant: PermissionGrant.parse(deviceXGrant.dataEncodedMessage),
|
|
1333
1324
|
});
|
|
1334
1325
|
const revocationDataStream = DataStream.fromBytes(permissionRevoke.permissionRevocationBytes);
|
|
1335
|
-
const permissionRevokeReply =
|
|
1326
|
+
const permissionRevokeReply = await dwn.processMessage(alice.did, permissionRevoke.recordsWrite.message, { dataStream: revocationDataStream });
|
|
1336
1327
|
expect(permissionRevokeReply.status.code).toBe(202);
|
|
1337
1328
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
|
|
1338
1329
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1339
1330
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1340
|
-
const messageByDeviceX =
|
|
1331
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
1341
1332
|
signer: Jws.createSigner(deviceX),
|
|
1342
1333
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
1343
1334
|
protocol,
|
|
@@ -1346,36 +1337,35 @@ export function testAuthorDelegatedGrant() {
|
|
|
1346
1337
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1347
1338
|
data: deviceXData
|
|
1348
1339
|
});
|
|
1349
|
-
const deviceXWriteReply =
|
|
1340
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1350
1341
|
expect(deviceXWriteReply.status.code).toBe(401);
|
|
1351
1342
|
expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
1352
1343
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1353
|
-
const recordsQueryByBob =
|
|
1344
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
1354
1345
|
author: bob,
|
|
1355
1346
|
filter: { protocol }
|
|
1356
1347
|
});
|
|
1357
|
-
const bobRecordsQueryReply =
|
|
1348
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1358
1349
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1359
|
-
expect(
|
|
1360
|
-
})
|
|
1361
|
-
it('should fail if author-delegated grant is expired - write', () =>
|
|
1362
|
-
var _a;
|
|
1350
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(0);
|
|
1351
|
+
});
|
|
1352
|
+
it('should fail if author-delegated grant is expired - write', async () => {
|
|
1363
1353
|
// scenario:
|
|
1364
1354
|
// 1. Bob has the message protocol installed
|
|
1365
1355
|
// 2. Alice creates a delegated grant for device X to write as Alice, but make it expired
|
|
1366
1356
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using an expired delegated grant
|
|
1367
1357
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1368
|
-
const alice =
|
|
1369
|
-
const bob =
|
|
1370
|
-
const deviceX =
|
|
1358
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1359
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
1360
|
+
const deviceX = await TestDataGenerator.generateDidKeyPersona();
|
|
1371
1361
|
// 1. Bob has the message protocol installed
|
|
1372
1362
|
const protocolDefinition = messageProtocolDefinition;
|
|
1373
1363
|
const protocol = protocolDefinition.protocol;
|
|
1374
|
-
const protocolsConfig =
|
|
1364
|
+
const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
|
|
1375
1365
|
author: bob,
|
|
1376
1366
|
protocolDefinition
|
|
1377
1367
|
});
|
|
1378
|
-
const protocolConfigureReply =
|
|
1368
|
+
const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
|
|
1379
1369
|
expect(protocolConfigureReply.status.code).toBe(202);
|
|
1380
1370
|
// 2. Alice creates a delegated grant for device X to write as Alice, but make it expired
|
|
1381
1371
|
const scope = {
|
|
@@ -1383,7 +1373,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1383
1373
|
method: DwnMethodName.Write,
|
|
1384
1374
|
protocol
|
|
1385
1375
|
};
|
|
1386
|
-
const deviceXGrant =
|
|
1376
|
+
const deviceXGrant = await PermissionsProtocol.createGrant({
|
|
1387
1377
|
delegated: true,
|
|
1388
1378
|
dateExpires: Time.getCurrentTimestamp(), // intentionally set to current time to make it expired immediately
|
|
1389
1379
|
grantedTo: deviceX.did,
|
|
@@ -1393,7 +1383,7 @@ export function testAuthorDelegatedGrant() {
|
|
|
1393
1383
|
// 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using an expired delegated grant
|
|
1394
1384
|
const deviceXData = new TextEncoder().encode('message from device X');
|
|
1395
1385
|
const deviceXDataStream = DataStream.fromBytes(deviceXData);
|
|
1396
|
-
const messageByDeviceX =
|
|
1386
|
+
const messageByDeviceX = await RecordsWrite.create({
|
|
1397
1387
|
signer: Jws.createSigner(deviceX),
|
|
1398
1388
|
delegatedGrant: deviceXGrant.dataEncodedMessage,
|
|
1399
1389
|
protocol,
|
|
@@ -1402,18 +1392,18 @@ export function testAuthorDelegatedGrant() {
|
|
|
1402
1392
|
dataFormat: protocolDefinition.types.message.dataFormats[0],
|
|
1403
1393
|
data: deviceXData
|
|
1404
1394
|
});
|
|
1405
|
-
const deviceXWriteReply =
|
|
1395
|
+
const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
|
|
1406
1396
|
expect(deviceXWriteReply.status.code).toBe(401);
|
|
1407
1397
|
expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantExpired);
|
|
1408
1398
|
// 4. Sanity verify the message by device X did not get written to Bob's DWN
|
|
1409
|
-
const recordsQueryByBob =
|
|
1399
|
+
const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
|
|
1410
1400
|
author: bob,
|
|
1411
1401
|
filter: { protocol }
|
|
1412
1402
|
});
|
|
1413
|
-
const bobRecordsQueryReply =
|
|
1403
|
+
const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
|
|
1414
1404
|
expect(bobRecordsQueryReply.status.code).toBe(200);
|
|
1415
|
-
expect(
|
|
1416
|
-
})
|
|
1405
|
+
expect(bobRecordsQueryReply.entries?.length).toBe(0);
|
|
1406
|
+
});
|
|
1417
1407
|
});
|
|
1418
1408
|
}
|
|
1419
1409
|
//# sourceMappingURL=author-delegated-grant.spec.js.map
|