@enbox/dwn-sdk-js 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +1 -2
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/abstract-message.js +4 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -1
- package/dist/esm/src/core/auth.js +22 -33
- package/dist/esm/src/core/auth.js.map +1 -1
- package/dist/esm/src/core/dwn-constant.js +7 -7
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +1 -0
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +37 -52
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message.js +85 -116
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +63 -78
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +266 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization-validation.js +254 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +122 -740
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/record-chain.js +64 -0
- package/dist/esm/src/core/record-chain.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +55 -72
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +50 -65
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/tenant-gate.js +2 -13
- package/dist/esm/src/core/tenant-gate.js.map +1 -1
- package/dist/esm/src/dwn.js +69 -86
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-stream.js +17 -31
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +1 -1
- package/dist/esm/src/handlers/messages-read.js +67 -77
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +51 -61
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +75 -85
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +135 -155
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +52 -51
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +96 -82
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +78 -88
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +116 -101
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +124 -131
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +150 -103
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +250 -259
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +24 -32
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +27 -41
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/messages-sync.js +26 -40
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +63 -63
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +55 -68
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +50 -66
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +45 -55
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +60 -76
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +51 -67
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +52 -68
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-query.js +102 -0
- package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-write-signing.js +92 -0
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +407 -602
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js +23 -35
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +56 -69
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +44 -15
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +29 -15
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +216 -226
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +42 -64
- package/dist/esm/src/smt/smt-store-level.js.map +1 -1
- package/dist/esm/src/smt/smt-store-memory.js +19 -45
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
- package/dist/esm/src/smt/smt-utils.js +28 -45
- package/dist/esm/src/smt/smt-utils.js.map +1 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +115 -150
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +54 -156
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +48 -153
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +59 -99
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level-compound.js +246 -0
- package/dist/esm/src/store/index-level-compound.js.map +1 -0
- package/dist/esm/src/store/index-level.js +295 -713
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +143 -244
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +71 -94
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/resumable-task-store-level.js +62 -101
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +129 -144
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/utils/abort.js +8 -19
- package/dist/esm/src/utils/abort.js.map +1 -1
- package/dist/esm/src/utils/array.js +15 -49
- package/dist/esm/src/utils/array.js.map +1 -1
- package/dist/esm/src/utils/cid.js +29 -77
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +37 -65
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +136 -162
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/filter.js +1 -12
- package/dist/esm/src/utils/filter.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +45 -63
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +9 -20
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +12 -23
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/messages.js +9 -3
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +9 -17
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +62 -70
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +108 -140
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +60 -96
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +54 -71
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +5 -18
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/src/utils/url.js +3 -3
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +3 -12
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +50 -59
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +9 -18
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +45 -58
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +24 -33
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +1 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +46 -55
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +1 -1
- package/dist/esm/tests/features/author-delegated-grant.spec.js +326 -343
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +153 -169
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +67 -78
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +446 -181
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +346 -356
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +42 -51
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +94 -103
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +105 -114
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +175 -191
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +441 -460
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +82 -91
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +206 -207
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +145 -154
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +174 -183
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +244 -238
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +156 -169
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +93 -102
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +252 -264
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +917 -988
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +553 -568
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +269 -278
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1057 -1082
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +152 -165
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +36 -45
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +49 -55
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +124 -135
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +23 -32
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +52 -61
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +63 -73
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +377 -333
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +86 -95
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +404 -414
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +13 -22
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +229 -238
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +3 -3
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +16 -13
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +2 -11
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +24 -33
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +48 -57
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +291 -44
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +46 -55
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +10 -19
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +3 -12
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +6 -15
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +22 -33
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +10 -19
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +414 -468
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +7 -16
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts +60 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +10 -100
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/record-chain.d.ts +24 -0
- package/dist/types/src/core/record-chain.d.ts.map +1 -0
- package/dist/types/src/handlers/records-write.d.ts +2 -1
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
- package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts +35 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +10 -44
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/store/index-level-compound.d.ts +70 -0
- package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +0 -58
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +5 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +3 -1
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/protocol-authorization-action.ts +377 -0
- package/src/core/protocol-authorization-validation.ts +391 -0
- package/src/core/protocol-authorization.ts +60 -849
- package/src/core/record-chain.ts +99 -0
- package/src/handlers/records-read.ts +1 -1
- package/src/handlers/records-write.ts +37 -21
- package/src/interfaces/protocols-configure.ts +33 -5
- package/src/interfaces/records-write-query.ts +139 -0
- package/src/interfaces/records-write-signing.ts +143 -0
- package/src/interfaces/records-write.ts +49 -221
- package/src/store/index-level-compound.ts +324 -0
- package/src/store/index-level.ts +24 -306
- package/src/utils/protocols.ts +8 -0
- package/src/utils/records.ts +9 -15
|
@@ -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 minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' with { type: 'json' };
|
|
11
2
|
import sinon from 'sinon';
|
|
12
3
|
import { DataStream } from '../../src/utils/data-stream.js';
|
|
@@ -33,7 +24,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
33
24
|
let dwn;
|
|
34
25
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
35
26
|
// so that different test suites can reuse the same backend store for testing
|
|
36
|
-
beforeAll(() =>
|
|
27
|
+
beforeAll(async () => {
|
|
37
28
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
38
29
|
const stores = TestStores.get();
|
|
39
30
|
messageStore = stores.messageStore;
|
|
@@ -41,31 +32,31 @@ export function testOwnerDelegatedGrant() {
|
|
|
41
32
|
resumableTaskStore = stores.resumableTaskStore;
|
|
42
33
|
stateIndex = stores.stateIndex;
|
|
43
34
|
eventStream = TestEventStream.get();
|
|
44
|
-
dwn =
|
|
45
|
-
})
|
|
46
|
-
beforeEach(() =>
|
|
35
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
36
|
+
});
|
|
37
|
+
beforeEach(async () => {
|
|
47
38
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
48
39
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
afterAll(() =>
|
|
55
|
-
|
|
56
|
-
})
|
|
40
|
+
await messageStore.clear();
|
|
41
|
+
await dataStore.clear();
|
|
42
|
+
await resumableTaskStore.clear();
|
|
43
|
+
await stateIndex.clear();
|
|
44
|
+
});
|
|
45
|
+
afterAll(async () => {
|
|
46
|
+
await dwn.close();
|
|
47
|
+
});
|
|
57
48
|
describe('RecordsWrite.parse()', () => {
|
|
58
|
-
it('should throw if a message invokes an owner-delegated grant (ID) but the owner-delegated grant is not given', () =>
|
|
59
|
-
const alice =
|
|
60
|
-
const bob =
|
|
61
|
-
const appX =
|
|
49
|
+
it('should throw if a message invokes an owner-delegated grant (ID) but the owner-delegated grant is not given', async () => {
|
|
50
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
51
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
52
|
+
const appX = await TestDataGenerator.generatePersona();
|
|
62
53
|
// Alice grants App X to write as her for the chat protocol
|
|
63
54
|
const scope = {
|
|
64
55
|
interface: DwnInterfaceName.Records,
|
|
65
56
|
method: DwnMethodName.Write,
|
|
66
57
|
protocol: 'chat'
|
|
67
58
|
};
|
|
68
|
-
const grantToAppX =
|
|
59
|
+
const grantToAppX = await PermissionsProtocol.createGrant({
|
|
69
60
|
delegated: true, // this is a delegated grant
|
|
70
61
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
71
62
|
description: 'Allow App X to write as me in chat protocol',
|
|
@@ -74,28 +65,28 @@ export function testOwnerDelegatedGrant() {
|
|
|
74
65
|
signer: Jws.createSigner(alice)
|
|
75
66
|
});
|
|
76
67
|
// Bob creates a RecordsWrite message
|
|
77
|
-
const recordsWrite =
|
|
68
|
+
const recordsWrite = await RecordsWrite.create({
|
|
78
69
|
signer: Jws.createSigner(bob),
|
|
79
70
|
dataFormat: 'application/octet-stream',
|
|
80
71
|
data: TestDataGenerator.randomBytes(10),
|
|
81
72
|
});
|
|
82
73
|
// App X signs over Bob's RecordsWrite as DWN owner but does not include the delegated grant (we remove it below)
|
|
83
|
-
|
|
74
|
+
await recordsWrite.signAsOwnerDelegate(Jws.createSigner(appX), grantToAppX.dataEncodedMessage);
|
|
84
75
|
delete recordsWrite.message.authorization.ownerDelegatedGrant; // intentionally remove `ownerDelegatedGrant`
|
|
85
76
|
const parsePromise = RecordsWrite.parse(recordsWrite.message);
|
|
86
|
-
|
|
87
|
-
})
|
|
88
|
-
it('should throw if a message includes an owner-delegated grant but does not reference it in owner signature', () =>
|
|
89
|
-
const alice =
|
|
90
|
-
const bob =
|
|
91
|
-
const appX =
|
|
77
|
+
await expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsOwnerDelegatedGrantAndIdExistenceMismatch);
|
|
78
|
+
});
|
|
79
|
+
it('should throw if a message includes an owner-delegated grant but does not reference it in owner signature', async () => {
|
|
80
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
81
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
82
|
+
const appX = await TestDataGenerator.generatePersona();
|
|
92
83
|
// Alice grants App X to write as her for the chat protocol
|
|
93
84
|
const scope = {
|
|
94
85
|
interface: DwnInterfaceName.Records,
|
|
95
86
|
method: DwnMethodName.Write,
|
|
96
87
|
protocol: 'chat'
|
|
97
88
|
};
|
|
98
|
-
const grantToAppX =
|
|
89
|
+
const grantToAppX = await PermissionsProtocol.createGrant({
|
|
99
90
|
delegated: true, // this is a delegated grant
|
|
100
91
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
101
92
|
description: 'Allow App X to write as me in chat protocol',
|
|
@@ -104,23 +95,22 @@ export function testOwnerDelegatedGrant() {
|
|
|
104
95
|
signer: Jws.createSigner(alice)
|
|
105
96
|
});
|
|
106
97
|
// Bob creates a RecordsWrite message
|
|
107
|
-
const recordsWrite =
|
|
98
|
+
const recordsWrite = await RecordsWrite.create({
|
|
108
99
|
signer: Jws.createSigner(bob),
|
|
109
100
|
dataFormat: 'application/octet-stream',
|
|
110
101
|
data: TestDataGenerator.randomBytes(10),
|
|
111
102
|
});
|
|
112
103
|
// App X attempts to sign over Bob's RecordsWrite as the DWN owner by including an owner-delegated grant
|
|
113
104
|
// but does not reference the grant ID in owner signature (we remove it below)
|
|
114
|
-
|
|
115
|
-
const ownerSignaturePayloadCopy =
|
|
105
|
+
await recordsWrite.signAsOwnerDelegate(Jws.createSigner(appX), grantToAppX.dataEncodedMessage);
|
|
106
|
+
const ownerSignaturePayloadCopy = { ...recordsWrite.ownerSignaturePayload };
|
|
116
107
|
delete ownerSignaturePayloadCopy.delegatedGrantId; // intentionally remove `delegatedGrantId` in ownerSignature
|
|
117
108
|
recordsWrite.message.authorization.ownerSignature.payload = Encoder.stringToBase64Url(JSON.stringify(ownerSignaturePayloadCopy));
|
|
118
109
|
const parsePromise = RecordsWrite.parse(recordsWrite.message);
|
|
119
|
-
|
|
120
|
-
})
|
|
110
|
+
await expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsOwnerDelegatedGrantAndIdExistenceMismatch);
|
|
111
|
+
});
|
|
121
112
|
});
|
|
122
|
-
it('should only allow correct entity invoking an owner-delegated grant to write', () =>
|
|
123
|
-
var _a;
|
|
113
|
+
it('should only allow correct entity invoking an owner-delegated grant to write', async () => {
|
|
124
114
|
// scenario:
|
|
125
115
|
// 1. Alice installs a protocol
|
|
126
116
|
// 2. Alice creates a delegated grant for app X to write in the protocol
|
|
@@ -129,18 +119,18 @@ export function testOwnerDelegatedGrant() {
|
|
|
129
119
|
// 5. Verify that App Y cannot write Bob's message in Alice's DWN by invoking the delegated grant for App X.
|
|
130
120
|
// 6. Verify that App X can successfully write Bob's message in Alice's DWN by invoking an owner-delegated grant
|
|
131
121
|
// 7. Sanity verify the RecordsWrite written by App X
|
|
132
|
-
const alice =
|
|
133
|
-
const bob =
|
|
134
|
-
const appX =
|
|
135
|
-
const appY =
|
|
122
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
123
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
124
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
125
|
+
const appY = await TestDataGenerator.generateDidKeyPersona();
|
|
136
126
|
// 1. Alice installs a protocol
|
|
137
127
|
const protocolDefinition = minimalProtocolDefinition;
|
|
138
128
|
const protocol = minimalProtocolDefinition.protocol;
|
|
139
|
-
const protocolsConfig =
|
|
129
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
140
130
|
signer: Jws.createSigner(alice),
|
|
141
131
|
definition: protocolDefinition
|
|
142
132
|
});
|
|
143
|
-
const protocolsConfigureReply =
|
|
133
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
144
134
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
145
135
|
// 2. Alice creates a delegated grant for app X to write in the protocol
|
|
146
136
|
const scope = {
|
|
@@ -148,7 +138,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
148
138
|
method: DwnMethodName.Write,
|
|
149
139
|
protocol
|
|
150
140
|
};
|
|
151
|
-
const appXGrant =
|
|
141
|
+
const appXGrant = await PermissionsProtocol.createGrant({
|
|
152
142
|
delegated: true, // this is a delegated grant
|
|
153
143
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
154
144
|
grantedTo: appX.did,
|
|
@@ -157,7 +147,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
157
147
|
});
|
|
158
148
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
159
149
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
160
|
-
const bobRecordsWrite =
|
|
150
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
161
151
|
signer: Jws.createSigner(bob),
|
|
162
152
|
protocol,
|
|
163
153
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -165,51 +155,50 @@ export function testOwnerDelegatedGrant() {
|
|
|
165
155
|
data: bobRecordsWriteBytes
|
|
166
156
|
});
|
|
167
157
|
// 4. Sanity test that Bob's RecordsWrite cannot be written to Alice's DWN by itself
|
|
168
|
-
const unauthorizedRecordsWriteReply =
|
|
158
|
+
const unauthorizedRecordsWriteReply = await dwn.processMessage(alice.did, bobRecordsWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
169
159
|
expect(unauthorizedRecordsWriteReply.status.code).toBe(401);
|
|
170
160
|
// 5. Verify that App Y cannot write Bob's message in Alice's DWN by invoking the delegated grant for App X.
|
|
171
|
-
const appYAugmentedWrite =
|
|
172
|
-
|
|
173
|
-
const appYWriteReply =
|
|
161
|
+
const appYAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
162
|
+
await appYAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appY), appXGrant.dataEncodedMessage);
|
|
163
|
+
const appYWriteReply = await dwn.processMessage(alice.did, appYAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
174
164
|
expect(appYWriteReply.status.code).toBe(400);
|
|
175
165
|
expect(appYWriteReply.status.detail).toContain(DwnErrorCode.RecordsOwnerDelegatedGrantGrantedToAndOwnerSignatureMismatch);
|
|
176
166
|
// 6. Verify that App X can successfully write Bob's message in Alice's DWN by invoking an owner-delegated grant
|
|
177
|
-
const appXAugmentedWrite =
|
|
178
|
-
|
|
179
|
-
const appXWriteReply =
|
|
167
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
168
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrant.dataEncodedMessage);
|
|
169
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
180
170
|
expect(appXWriteReply.status.code).toBe(202);
|
|
181
171
|
// 7. Sanity verify the RecordsWrite written by App X
|
|
182
|
-
const recordsQuery =
|
|
172
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
183
173
|
author: alice,
|
|
184
174
|
filter: { protocol }
|
|
185
175
|
});
|
|
186
|
-
const recordsQueryReply =
|
|
176
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
187
177
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
188
|
-
expect(
|
|
178
|
+
expect(recordsQueryReply.entries?.length).toBe(1);
|
|
189
179
|
const fetchedEntry = recordsQueryReply.entries[0];
|
|
190
180
|
expect(fetchedEntry.encodedData).toBe(Encoder.bytesToBase64Url(bobRecordsWriteBytes));
|
|
191
|
-
const fetchedRecordsWrite =
|
|
181
|
+
const fetchedRecordsWrite = await RecordsWrite.parse(fetchedEntry);
|
|
192
182
|
expect(fetchedRecordsWrite.author).toBe(bob.did);
|
|
193
|
-
})
|
|
194
|
-
it('should not allow entity using a non-delegated grant as an owner-delegated grant to invoke write', () =>
|
|
195
|
-
var _a;
|
|
183
|
+
});
|
|
184
|
+
it('should not allow entity using a non-delegated grant as an owner-delegated grant to invoke write', async () => {
|
|
196
185
|
// scenario:
|
|
197
186
|
// 1. Alice installs a protocol
|
|
198
187
|
// 2. Alice creates a non-delegated grant for app X to write in the protocol
|
|
199
188
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
200
189
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an non-delegated grant
|
|
201
190
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
202
|
-
const alice =
|
|
203
|
-
const bob =
|
|
204
|
-
const appX =
|
|
191
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
192
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
193
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
205
194
|
// 1. Alice installs a protocol
|
|
206
195
|
const protocolDefinition = minimalProtocolDefinition;
|
|
207
196
|
const protocol = minimalProtocolDefinition.protocol;
|
|
208
|
-
const protocolsConfig =
|
|
197
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
209
198
|
signer: Jws.createSigner(alice),
|
|
210
199
|
definition: protocolDefinition
|
|
211
200
|
});
|
|
212
|
-
const protocolsConfigureReply =
|
|
201
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
213
202
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
214
203
|
// 2. Alice creates a non-delegated grant for app X to write in the protocol
|
|
215
204
|
const scope = {
|
|
@@ -217,7 +206,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
217
206
|
method: DwnMethodName.Write,
|
|
218
207
|
protocol
|
|
219
208
|
};
|
|
220
|
-
const appXGrant =
|
|
209
|
+
const appXGrant = await PermissionsProtocol.createGrant({
|
|
221
210
|
// delegated : true, // intentionally commented out to show that this is not a delegated grant
|
|
222
211
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
223
212
|
grantedTo: appX.did,
|
|
@@ -226,7 +215,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
226
215
|
});
|
|
227
216
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
228
217
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
229
|
-
const bobRecordsWrite =
|
|
218
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
230
219
|
signer: Jws.createSigner(bob),
|
|
231
220
|
protocol,
|
|
232
221
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -234,22 +223,21 @@ export function testOwnerDelegatedGrant() {
|
|
|
234
223
|
data: bobRecordsWriteBytes
|
|
235
224
|
});
|
|
236
225
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an non-delegated grant
|
|
237
|
-
const appXAugmentedWrite =
|
|
238
|
-
|
|
239
|
-
const appXWriteReply =
|
|
226
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
227
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrant.dataEncodedMessage);
|
|
228
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
240
229
|
expect(appXWriteReply.status.code).toBe(400);
|
|
241
230
|
expect(appXWriteReply.status.detail).toContain(DwnErrorCode.RecordsOwnerDelegatedGrantNotADelegatedGrant);
|
|
242
231
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
243
|
-
const recordsQuery =
|
|
232
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
244
233
|
author: alice,
|
|
245
234
|
filter: { protocol }
|
|
246
235
|
});
|
|
247
|
-
const recordsQueryReply =
|
|
236
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
248
237
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
249
|
-
expect(
|
|
250
|
-
})
|
|
251
|
-
it('should fail if owner-delegated grant invoked for write has a mismatching interface method or protocol scope', () =>
|
|
252
|
-
var _a;
|
|
238
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
239
|
+
});
|
|
240
|
+
it('should fail if owner-delegated grant invoked for write has a mismatching interface method or protocol scope', async () => {
|
|
253
241
|
// scenario:
|
|
254
242
|
// 1. Alice installs a protocol
|
|
255
243
|
// 2. Alice creates a delegated grant for app X to read in the protocol
|
|
@@ -258,17 +246,17 @@ export function testOwnerDelegatedGrant() {
|
|
|
258
246
|
// 5. Verify that App X cannot write Bob's message in Alice's DWN by invoking a delegated grant for RecordsRead
|
|
259
247
|
// 6. Verify that App X cannot write Bob's message in Alice's DWN by invoking a delegated grant for writing in another random protocol
|
|
260
248
|
// 7. Sanity verify the RecordsWrite is not written by App X
|
|
261
|
-
const alice =
|
|
262
|
-
const bob =
|
|
263
|
-
const appX =
|
|
249
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
250
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
251
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
264
252
|
// 1. Alice installs a protocol
|
|
265
253
|
const protocolDefinition = minimalProtocolDefinition;
|
|
266
254
|
const protocol = minimalProtocolDefinition.protocol;
|
|
267
|
-
const protocolsConfig =
|
|
255
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
268
256
|
signer: Jws.createSigner(alice),
|
|
269
257
|
definition: protocolDefinition
|
|
270
258
|
});
|
|
271
|
-
const protocolsConfigureReply =
|
|
259
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
272
260
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
273
261
|
// 2. Alice creates a delegated grant for app X to read in the protocol
|
|
274
262
|
const readScope = {
|
|
@@ -276,7 +264,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
276
264
|
method: DwnMethodName.Read,
|
|
277
265
|
protocol
|
|
278
266
|
};
|
|
279
|
-
const appXGrantToRead =
|
|
267
|
+
const appXGrantToRead = await PermissionsProtocol.createGrant({
|
|
280
268
|
delegated: true,
|
|
281
269
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
282
270
|
grantedTo: appX.did,
|
|
@@ -289,7 +277,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
289
277
|
method: DwnMethodName.Write,
|
|
290
278
|
protocol: `random-protocol`
|
|
291
279
|
};
|
|
292
|
-
const appXGrantToWriteInRandomProtocol =
|
|
280
|
+
const appXGrantToWriteInRandomProtocol = await PermissionsProtocol.createGrant({
|
|
293
281
|
delegated: true,
|
|
294
282
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
295
283
|
grantedTo: appX.did,
|
|
@@ -298,7 +286,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
298
286
|
});
|
|
299
287
|
// 4. A third party (Bob) authors a RecordsWrite
|
|
300
288
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
301
|
-
const bobRecordsWrite =
|
|
289
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
302
290
|
signer: Jws.createSigner(bob),
|
|
303
291
|
protocol,
|
|
304
292
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -306,45 +294,44 @@ export function testOwnerDelegatedGrant() {
|
|
|
306
294
|
data: bobRecordsWriteBytes
|
|
307
295
|
});
|
|
308
296
|
// 5. Verify that App X cannot write Bob's message in Alice's DWN by invoking a delegated grant for RecordsRead
|
|
309
|
-
const appXAugmentedWrite =
|
|
310
|
-
|
|
311
|
-
const appXWriteReply =
|
|
297
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
298
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrantToRead.dataEncodedMessage);
|
|
299
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
312
300
|
expect(appXWriteReply.status.code).toBe(401);
|
|
313
301
|
expect(appXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationMethodMismatch);
|
|
314
302
|
// 6. Verify that App X cannot write Bob's message in Alice's DWN by invoking a delegated grant for writing in another random protocol
|
|
315
|
-
const appXAugmentedWrite2 =
|
|
316
|
-
|
|
317
|
-
const appXWriteReply2 =
|
|
303
|
+
const appXAugmentedWrite2 = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
304
|
+
await appXAugmentedWrite2.signAsOwnerDelegate(Jws.createSigner(appX), appXGrantToWriteInRandomProtocol.dataEncodedMessage);
|
|
305
|
+
const appXWriteReply2 = await dwn.processMessage(alice.did, appXAugmentedWrite2.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
318
306
|
expect(appXWriteReply2.status.code).toBe(401);
|
|
319
307
|
expect(appXWriteReply2.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
320
308
|
// 7. Sanity verify the RecordsWrite is not written by App X
|
|
321
|
-
const recordsQuery =
|
|
309
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
322
310
|
author: alice,
|
|
323
311
|
filter: { protocol }
|
|
324
312
|
});
|
|
325
|
-
const recordsQueryReply =
|
|
313
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
326
314
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
327
|
-
expect(
|
|
328
|
-
})
|
|
329
|
-
it('should fail RecordsWrite if presented with an owner-delegated grant with invalid grantor signature', () =>
|
|
330
|
-
var _a;
|
|
315
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
316
|
+
});
|
|
317
|
+
it('should fail RecordsWrite if presented with an owner-delegated grant with invalid grantor signature', async () => {
|
|
331
318
|
// scenario:
|
|
332
319
|
// 1. Alice installs a protocol
|
|
333
320
|
// 2. Alice creates a delegated grant for App X to write as Alice, but with invalid signature
|
|
334
321
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
335
322
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an owner-delegated grant with invalid signature
|
|
336
323
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
337
|
-
const alice =
|
|
338
|
-
const bob =
|
|
339
|
-
const appX =
|
|
324
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
325
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
326
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
340
327
|
// 1. Alice installs a protocol
|
|
341
328
|
const protocolDefinition = minimalProtocolDefinition;
|
|
342
329
|
const protocol = minimalProtocolDefinition.protocol;
|
|
343
|
-
const protocolsConfig =
|
|
330
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
344
331
|
signer: Jws.createSigner(alice),
|
|
345
332
|
definition: protocolDefinition
|
|
346
333
|
});
|
|
347
|
-
const protocolsConfigureReply =
|
|
334
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
348
335
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
349
336
|
// 2. Alice creates a delegated grant for App X to write as Alice, but with invalid signature
|
|
350
337
|
const scope = {
|
|
@@ -352,7 +339,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
352
339
|
method: DwnMethodName.Write,
|
|
353
340
|
protocol
|
|
354
341
|
};
|
|
355
|
-
const appXGrant =
|
|
342
|
+
const appXGrant = await PermissionsProtocol.createGrant({
|
|
356
343
|
delegated: true,
|
|
357
344
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
358
345
|
grantedTo: appX.did,
|
|
@@ -360,10 +347,10 @@ export function testOwnerDelegatedGrant() {
|
|
|
360
347
|
signer: Jws.createSigner(alice)
|
|
361
348
|
});
|
|
362
349
|
const appXGrantMessage = appXGrant.dataEncodedMessage;
|
|
363
|
-
appXGrantMessage.authorization.signature.signatures[0].signature =
|
|
350
|
+
appXGrantMessage.authorization.signature.signatures[0].signature = await TestDataGenerator.randomSignatureString();
|
|
364
351
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
365
352
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
366
|
-
const bobRecordsWrite =
|
|
353
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
367
354
|
signer: Jws.createSigner(bob),
|
|
368
355
|
protocol,
|
|
369
356
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -371,39 +358,38 @@ export function testOwnerDelegatedGrant() {
|
|
|
371
358
|
data: bobRecordsWriteBytes
|
|
372
359
|
});
|
|
373
360
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an owner-delegated grant with invalid signature
|
|
374
|
-
const appXAugmentedWrite =
|
|
375
|
-
|
|
376
|
-
const appXWriteReply =
|
|
361
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
362
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrantMessage);
|
|
363
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
377
364
|
expect(appXWriteReply.status.code).toBe(401);
|
|
378
365
|
expect(appXWriteReply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
|
|
379
366
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
380
|
-
const recordsQuery =
|
|
367
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
381
368
|
author: alice,
|
|
382
369
|
filter: { protocol }
|
|
383
370
|
});
|
|
384
|
-
const recordsQueryReply =
|
|
371
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
385
372
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
386
|
-
expect(
|
|
387
|
-
})
|
|
388
|
-
it('should fail RecordsWrite if grant ID in owner signature payload and CID of owner-delegated grant are mismatching', () =>
|
|
389
|
-
var _a;
|
|
373
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
374
|
+
});
|
|
375
|
+
it('should fail RecordsWrite if grant ID in owner signature payload and CID of owner-delegated grant are mismatching', async () => {
|
|
390
376
|
// scenario:
|
|
391
377
|
// 1. Alice installs a protocol
|
|
392
378
|
// 2. Creates two delegated grant for App X to write as Alice
|
|
393
379
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
394
380
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an owner-delegated grant with the wrong ID
|
|
395
381
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
396
|
-
const alice =
|
|
397
|
-
const bob =
|
|
398
|
-
const appX =
|
|
382
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
383
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
384
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
399
385
|
// 1. Alice installs a protocol
|
|
400
386
|
const protocolDefinition = minimalProtocolDefinition;
|
|
401
387
|
const protocol = minimalProtocolDefinition.protocol;
|
|
402
|
-
const protocolsConfig =
|
|
388
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
403
389
|
signer: Jws.createSigner(alice),
|
|
404
390
|
definition: protocolDefinition
|
|
405
391
|
});
|
|
406
|
-
const protocolsConfigureReply =
|
|
392
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
407
393
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
408
394
|
// 2. Creates two delegated grant for App X to write as Alice
|
|
409
395
|
const scope = {
|
|
@@ -411,15 +397,15 @@ export function testOwnerDelegatedGrant() {
|
|
|
411
397
|
method: DwnMethodName.Write,
|
|
412
398
|
protocol
|
|
413
399
|
};
|
|
414
|
-
const appXGrant =
|
|
400
|
+
const appXGrant = await PermissionsProtocol.createGrant({
|
|
415
401
|
delegated: true,
|
|
416
402
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
417
403
|
grantedTo: appX.did,
|
|
418
404
|
scope: scope,
|
|
419
405
|
signer: Jws.createSigner(alice)
|
|
420
406
|
});
|
|
421
|
-
|
|
422
|
-
const appXGrant2 =
|
|
407
|
+
await Time.minimalSleep();
|
|
408
|
+
const appXGrant2 = await PermissionsProtocol.createGrant({
|
|
423
409
|
delegated: true,
|
|
424
410
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
425
411
|
grantedTo: appX.did,
|
|
@@ -428,7 +414,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
428
414
|
});
|
|
429
415
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
430
416
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
431
|
-
const bobRecordsWrite =
|
|
417
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
432
418
|
signer: Jws.createSigner(bob),
|
|
433
419
|
protocol,
|
|
434
420
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -436,23 +422,22 @@ export function testOwnerDelegatedGrant() {
|
|
|
436
422
|
data: bobRecordsWriteBytes
|
|
437
423
|
});
|
|
438
424
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an owner-delegated grant with the wrong ID
|
|
439
|
-
const appXAugmentedWrite =
|
|
440
|
-
|
|
425
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
426
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrant.dataEncodedMessage);
|
|
441
427
|
appXAugmentedWrite.message.authorization.ownerDelegatedGrant = appXGrant2.dataEncodedMessage; // intentionally have a mismatching grant
|
|
442
|
-
const appXWriteReply =
|
|
428
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
443
429
|
expect(appXWriteReply.status.code).toBe(400);
|
|
444
430
|
expect(appXWriteReply.status.detail).toContain(DwnErrorCode.RecordsOwnerDelegatedGrantCidMismatch);
|
|
445
431
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
446
|
-
const recordsQuery =
|
|
432
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
447
433
|
author: alice,
|
|
448
434
|
filter: { protocol }
|
|
449
435
|
});
|
|
450
|
-
const recordsQueryReply =
|
|
436
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
451
437
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
452
|
-
expect(
|
|
453
|
-
})
|
|
454
|
-
it('should fail RecordsWrite if owner-delegated grant is revoked', () =>
|
|
455
|
-
var _a;
|
|
438
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
439
|
+
});
|
|
440
|
+
it('should fail RecordsWrite if owner-delegated grant is revoked', async () => {
|
|
456
441
|
// scenario:
|
|
457
442
|
// 1. Alice installs a protocol
|
|
458
443
|
// 2. Alice creates a delegated grant for App X to write as Alice
|
|
@@ -460,17 +445,17 @@ export function testOwnerDelegatedGrant() {
|
|
|
460
445
|
// 4. A third party (Bob) authors a RecordsWrite
|
|
461
446
|
// 5. Verify that App X cannot write Bob's message in Alice's DWN by invoking a revoked owner-delegated grant
|
|
462
447
|
// 6. Sanity verify the RecordsWrite is not written by App X
|
|
463
|
-
const alice =
|
|
464
|
-
const bob =
|
|
465
|
-
const appX =
|
|
448
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
449
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
450
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
466
451
|
// 1. Alice installs a protocol
|
|
467
452
|
const protocolDefinition = minimalProtocolDefinition;
|
|
468
453
|
const protocol = minimalProtocolDefinition.protocol;
|
|
469
|
-
const protocolsConfig =
|
|
454
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
470
455
|
signer: Jws.createSigner(alice),
|
|
471
456
|
definition: protocolDefinition
|
|
472
457
|
});
|
|
473
|
-
const protocolsConfigureReply =
|
|
458
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
474
459
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
475
460
|
// 2. Alice creates a delegated grant for App X to write as Alice
|
|
476
461
|
const scope = {
|
|
@@ -478,7 +463,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
478
463
|
method: DwnMethodName.Write,
|
|
479
464
|
protocol
|
|
480
465
|
};
|
|
481
|
-
const appXGrant =
|
|
466
|
+
const appXGrant = await PermissionsProtocol.createGrant({
|
|
482
467
|
delegated: true,
|
|
483
468
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
484
469
|
grantedTo: appX.did,
|
|
@@ -486,19 +471,19 @@ export function testOwnerDelegatedGrant() {
|
|
|
486
471
|
signer: Jws.createSigner(alice)
|
|
487
472
|
});
|
|
488
473
|
const grantDataStream = DataStream.fromBytes(appXGrant.permissionGrantBytes);
|
|
489
|
-
const permissionGrantWriteReply =
|
|
474
|
+
const permissionGrantWriteReply = await dwn.processMessage(alice.did, appXGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
490
475
|
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
491
476
|
// 3. Alice revokes the grant
|
|
492
|
-
const permissionRevoke =
|
|
477
|
+
const permissionRevoke = await PermissionsProtocol.createRevocation({
|
|
493
478
|
signer: Jws.createSigner(alice),
|
|
494
|
-
grant:
|
|
479
|
+
grant: await PermissionGrant.parse(appXGrant.dataEncodedMessage),
|
|
495
480
|
});
|
|
496
481
|
const revocationDataStream = DataStream.fromBytes(permissionRevoke.permissionRevocationBytes);
|
|
497
|
-
const permissionRevokeReply =
|
|
482
|
+
const permissionRevokeReply = await dwn.processMessage(alice.did, permissionRevoke.recordsWrite.message, { dataStream: revocationDataStream });
|
|
498
483
|
expect(permissionRevokeReply.status.code).toBe(202);
|
|
499
484
|
// 4. A third party (Bob) authors a RecordsWrite
|
|
500
485
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
501
|
-
const bobRecordsWrite =
|
|
486
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
502
487
|
signer: Jws.createSigner(bob),
|
|
503
488
|
protocol,
|
|
504
489
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -506,39 +491,38 @@ export function testOwnerDelegatedGrant() {
|
|
|
506
491
|
data: bobRecordsWriteBytes
|
|
507
492
|
});
|
|
508
493
|
// 5. Verify that App X cannot write Bob's message in Alice's DWN by invoking a revoked owner-delegated grant
|
|
509
|
-
const appXAugmentedWrite =
|
|
510
|
-
|
|
511
|
-
const appXWriteReply =
|
|
494
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
495
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrant.dataEncodedMessage);
|
|
496
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
512
497
|
expect(appXWriteReply.status.code).toBe(401);
|
|
513
498
|
expect(appXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
514
499
|
// 6. Sanity verify the RecordsWrite is not written by App X
|
|
515
|
-
const recordsQuery =
|
|
500
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
516
501
|
author: alice,
|
|
517
502
|
filter: { protocol }
|
|
518
503
|
});
|
|
519
|
-
const recordsQueryReply =
|
|
504
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
520
505
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
521
|
-
expect(
|
|
522
|
-
})
|
|
523
|
-
it('should fail RecordsWrite if owner-delegated grant is expired', () =>
|
|
524
|
-
var _a;
|
|
506
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
507
|
+
});
|
|
508
|
+
it('should fail RecordsWrite if owner-delegated grant is expired', async () => {
|
|
525
509
|
// scenario:
|
|
526
510
|
// 1. Alice installs a protocol
|
|
527
511
|
// 2. Alice creates a delegated grant for App X to write as Alice, but make it expired
|
|
528
512
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
529
513
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an expired owner-delegated grant
|
|
530
514
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
531
|
-
const alice =
|
|
532
|
-
const bob =
|
|
533
|
-
const appX =
|
|
515
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
516
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
517
|
+
const appX = await TestDataGenerator.generateDidKeyPersona();
|
|
534
518
|
// 1. Alice installs a protocol
|
|
535
519
|
const protocolDefinition = minimalProtocolDefinition;
|
|
536
520
|
const protocol = minimalProtocolDefinition.protocol;
|
|
537
|
-
const protocolsConfig =
|
|
521
|
+
const protocolsConfig = await ProtocolsConfigure.create({
|
|
538
522
|
signer: Jws.createSigner(alice),
|
|
539
523
|
definition: protocolDefinition
|
|
540
524
|
});
|
|
541
|
-
const protocolsConfigureReply =
|
|
525
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
|
|
542
526
|
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
543
527
|
// 2. Alice creates a delegated grant for App X to write as Alice, but make it expired
|
|
544
528
|
const scope = {
|
|
@@ -546,7 +530,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
546
530
|
method: DwnMethodName.Write,
|
|
547
531
|
protocol
|
|
548
532
|
};
|
|
549
|
-
const appXGrant =
|
|
533
|
+
const appXGrant = await PermissionsProtocol.createGrant({
|
|
550
534
|
delegated: true,
|
|
551
535
|
dateExpires: Time.getCurrentTimestamp(), // intentionally set to current time to make it expired immediately
|
|
552
536
|
grantedTo: appX.did,
|
|
@@ -555,7 +539,7 @@ export function testOwnerDelegatedGrant() {
|
|
|
555
539
|
});
|
|
556
540
|
// 3. A third party (Bob) authors a RecordsWrite
|
|
557
541
|
const bobRecordsWriteBytes = new TextEncoder().encode('message from Bob');
|
|
558
|
-
const bobRecordsWrite =
|
|
542
|
+
const bobRecordsWrite = await RecordsWrite.create({
|
|
559
543
|
signer: Jws.createSigner(bob),
|
|
560
544
|
protocol,
|
|
561
545
|
protocolPath: 'foo', // this comes from `types` in protocol definition
|
|
@@ -563,20 +547,20 @@ export function testOwnerDelegatedGrant() {
|
|
|
563
547
|
data: bobRecordsWriteBytes
|
|
564
548
|
});
|
|
565
549
|
// 4. Verify that App X cannot write Bob's message in Alice's DWN by invoking an expired owner-delegated grant
|
|
566
|
-
const appXAugmentedWrite =
|
|
567
|
-
|
|
568
|
-
const appXWriteReply =
|
|
550
|
+
const appXAugmentedWrite = await RecordsWrite.parse(bobRecordsWrite.message);
|
|
551
|
+
await appXAugmentedWrite.signAsOwnerDelegate(Jws.createSigner(appX), appXGrant.dataEncodedMessage);
|
|
552
|
+
const appXWriteReply = await dwn.processMessage(alice.did, appXAugmentedWrite.message, { dataStream: DataStream.fromBytes(bobRecordsWriteBytes) });
|
|
569
553
|
expect(appXWriteReply.status.code).toBe(401);
|
|
570
554
|
expect(appXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantExpired);
|
|
571
555
|
// 5. Sanity verify the RecordsWrite is not written by App X
|
|
572
|
-
const recordsQuery =
|
|
556
|
+
const recordsQuery = await TestDataGenerator.generateRecordsQuery({
|
|
573
557
|
author: alice,
|
|
574
558
|
filter: { protocol }
|
|
575
559
|
});
|
|
576
|
-
const recordsQueryReply =
|
|
560
|
+
const recordsQueryReply = await dwn.processMessage(alice.did, recordsQuery.message);
|
|
577
561
|
expect(recordsQueryReply.status.code).toBe(200);
|
|
578
|
-
expect(
|
|
579
|
-
})
|
|
562
|
+
expect(recordsQueryReply.entries?.length).toBe(0);
|
|
563
|
+
});
|
|
580
564
|
});
|
|
581
565
|
}
|
|
582
566
|
//# sourceMappingURL=owner-delegated-grant.spec.js.map
|