@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 sinon from 'sinon';
|
|
11
2
|
import { GeneralJwsBuilder } from '../../src/jose/jws/general/builder.js';
|
|
12
3
|
import { Message } from '../../src/core/message.js';
|
|
@@ -31,7 +22,7 @@ export function testProtocolsQueryHandler() {
|
|
|
31
22
|
describe('functional tests', () => {
|
|
32
23
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
33
24
|
// so that different test suites can reuse the same backend store for testing
|
|
34
|
-
beforeAll(() =>
|
|
25
|
+
beforeAll(async () => {
|
|
35
26
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
36
27
|
const stores = TestStores.get();
|
|
37
28
|
messageStore = stores.messageStore;
|
|
@@ -39,299 +30,295 @@ export function testProtocolsQueryHandler() {
|
|
|
39
30
|
resumableTaskStore = stores.resumableTaskStore;
|
|
40
31
|
stateIndex = stores.stateIndex;
|
|
41
32
|
eventStream = TestEventStream.get();
|
|
42
|
-
dwn =
|
|
43
|
-
})
|
|
44
|
-
beforeEach(() =>
|
|
33
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
34
|
+
});
|
|
35
|
+
beforeEach(async () => {
|
|
45
36
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
46
37
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
afterAll(() =>
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
it('should return protocols matching the query', () =>
|
|
56
|
-
|
|
57
|
-
const alice = yield TestDataGenerator.generatePersona();
|
|
38
|
+
await messageStore.clear();
|
|
39
|
+
await dataStore.clear();
|
|
40
|
+
await resumableTaskStore.clear();
|
|
41
|
+
await stateIndex.clear();
|
|
42
|
+
});
|
|
43
|
+
afterAll(async () => {
|
|
44
|
+
await dwn.close();
|
|
45
|
+
});
|
|
46
|
+
it('should return protocols matching the query', async () => {
|
|
47
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
58
48
|
// setting up a stub method resolver
|
|
59
49
|
TestStubGenerator.stubDidResolver(didResolver, [alice]);
|
|
60
50
|
// insert three messages into DB, two with matching protocol
|
|
61
|
-
const protocol1 =
|
|
62
|
-
const protocol2 =
|
|
63
|
-
const protocol3 =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
const protocol1 = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
52
|
+
const protocol2 = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
53
|
+
const protocol3 = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
54
|
+
await dwn.processMessage(alice.did, protocol1.message);
|
|
55
|
+
await dwn.processMessage(alice.did, protocol2.message);
|
|
56
|
+
await dwn.processMessage(alice.did, protocol3.message);
|
|
67
57
|
// testing singular conditional query
|
|
68
|
-
const queryMessageData =
|
|
58
|
+
const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
|
|
69
59
|
author: alice,
|
|
70
60
|
filter: { protocol: protocol1.message.descriptor.definition.protocol }
|
|
71
61
|
});
|
|
72
|
-
const reply =
|
|
62
|
+
const reply = await dwn.processMessage(alice.did, queryMessageData.message);
|
|
73
63
|
expect(reply.status.code).toBe(200);
|
|
74
|
-
expect(
|
|
64
|
+
expect(reply.entries?.length).toBe(1); // only 1 entry should match the query on protocol
|
|
75
65
|
// testing fetch-all query without filter
|
|
76
|
-
const queryMessageData2 =
|
|
66
|
+
const queryMessageData2 = await TestDataGenerator.generateProtocolsQuery({
|
|
77
67
|
author: alice
|
|
78
68
|
});
|
|
79
|
-
const reply2 =
|
|
69
|
+
const reply2 = await dwn.processMessage(alice.did, queryMessageData2.message);
|
|
80
70
|
expect(reply2.status.code).toBe(200);
|
|
81
|
-
expect(
|
|
82
|
-
})
|
|
83
|
-
it('should return published protocols matching the query if query is unauthenticated or unauthorized', () =>
|
|
71
|
+
expect(reply2.entries?.length).toBe(3); // expecting all 3 entries written above match the query
|
|
72
|
+
});
|
|
73
|
+
it('should return published protocols matching the query if query is unauthenticated or unauthorized', async () => {
|
|
84
74
|
// scenario:
|
|
85
75
|
// 1. Alice has 3 protocols installed: 1 private + 2 published
|
|
86
76
|
// 2. Unauthenticated ProtocolsQuery should return published ProtocolsConfigure
|
|
87
77
|
// 3. Authenticated ProtocolsQuery by Bob but unauthorized to private ProtocolsConfigures should return published ProtocolsConfigure
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
const bob = yield TestDataGenerator.generatePersona();
|
|
78
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
79
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
91
80
|
TestStubGenerator.stubDidResolver(didResolver, [alice, bob]);
|
|
92
81
|
// insert three messages into DB, two with matching protocol
|
|
93
|
-
const protocol1 =
|
|
94
|
-
const protocol2 =
|
|
95
|
-
const protocol3 =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
82
|
+
const protocol1 = await TestDataGenerator.generateProtocolsConfigure({ author: alice, published: false });
|
|
83
|
+
const protocol2 = await TestDataGenerator.generateProtocolsConfigure({ author: alice, published: true });
|
|
84
|
+
const protocol3 = await TestDataGenerator.generateProtocolsConfigure({ author: alice, published: true });
|
|
85
|
+
await dwn.processMessage(alice.did, protocol1.message);
|
|
86
|
+
await dwn.processMessage(alice.did, protocol2.message);
|
|
87
|
+
await dwn.processMessage(alice.did, protocol3.message);
|
|
99
88
|
// testing unauthenticated conditional query
|
|
100
|
-
const conditionalQuery =
|
|
89
|
+
const conditionalQuery = await ProtocolsQuery.create({
|
|
101
90
|
filter: { protocol: protocol2.message.descriptor.definition.protocol }
|
|
102
91
|
});
|
|
103
|
-
const conditionalQueryReply =
|
|
92
|
+
const conditionalQueryReply = await dwn.processMessage(alice.did, conditionalQuery.message);
|
|
104
93
|
expect(conditionalQueryReply.status.code).toBe(200);
|
|
105
|
-
expect(
|
|
94
|
+
expect(conditionalQueryReply.entries?.length).toBe(1); // only 1 entry should match the query on protocol
|
|
106
95
|
const protocolConfigured = conditionalQueryReply.entries[0];
|
|
107
96
|
expect(protocolConfigured).toEqual(protocol2.message);
|
|
108
97
|
// testing authenticated but unauthorized conditional query, it should return only matching published ProtocolsConfigures
|
|
109
|
-
const signedConditionalQuery =
|
|
98
|
+
const signedConditionalQuery = await ProtocolsQuery.create({
|
|
110
99
|
filter: { protocol: protocol2.message.descriptor.definition.protocol },
|
|
111
100
|
signer: Jws.createSigner(bob)
|
|
112
101
|
});
|
|
113
|
-
const signedConditionalQueryReply =
|
|
102
|
+
const signedConditionalQueryReply = await dwn.processMessage(alice.did, signedConditionalQuery.message);
|
|
114
103
|
expect(signedConditionalQueryReply.status.code).toBe(200);
|
|
115
|
-
expect(
|
|
104
|
+
expect(signedConditionalQueryReply.entries?.length).toBe(1); // only 1 entry should match the query on protocol
|
|
116
105
|
const protocolConfigured2 = conditionalQueryReply.entries[0];
|
|
117
106
|
expect(protocolConfigured2).toEqual(protocol2.message);
|
|
118
107
|
// testing unauthenticated fetch-all query without filter
|
|
119
|
-
const fetchAllQuery =
|
|
120
|
-
const fetchAllQueryReply =
|
|
108
|
+
const fetchAllQuery = await ProtocolsQuery.create({});
|
|
109
|
+
const fetchAllQueryReply = await dwn.processMessage(alice.did, fetchAllQuery.message);
|
|
121
110
|
expect(fetchAllQueryReply.status.code).toBe(200);
|
|
122
|
-
expect(
|
|
111
|
+
expect(fetchAllQueryReply.entries?.length).toBe(2);
|
|
123
112
|
expect(fetchAllQueryReply.entries).toContainEqual(protocol2.message);
|
|
124
113
|
expect(fetchAllQueryReply.entries).toContainEqual(protocol3.message);
|
|
125
114
|
// testing authenticated but unauthorized fetch-all query without filter, it should return all matching published ProtocolsConfigures
|
|
126
|
-
const signedFetchAllQuery =
|
|
115
|
+
const signedFetchAllQuery = await ProtocolsQuery.create({
|
|
127
116
|
signer: Jws.createSigner(bob)
|
|
128
117
|
});
|
|
129
|
-
const signedFetchAllQueryReply =
|
|
118
|
+
const signedFetchAllQueryReply = await dwn.processMessage(alice.did, signedFetchAllQuery.message);
|
|
130
119
|
expect(signedFetchAllQueryReply.status.code).toBe(200);
|
|
131
|
-
expect(
|
|
120
|
+
expect(signedFetchAllQueryReply.entries?.length).toBe(2);
|
|
132
121
|
expect(signedFetchAllQueryReply.entries).toContainEqual(protocol2.message);
|
|
133
122
|
expect(signedFetchAllQueryReply.entries).toContainEqual(protocol3.message);
|
|
134
|
-
})
|
|
135
|
-
it('should return 400 if protocol is not normalized', () =>
|
|
136
|
-
const alice =
|
|
123
|
+
});
|
|
124
|
+
it('should return 400 if protocol is not normalized', async () => {
|
|
125
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
137
126
|
// query for non-normalized protocol
|
|
138
|
-
const protocolsQuery =
|
|
127
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
139
128
|
author: alice,
|
|
140
129
|
filter: { protocol: 'example.com/' },
|
|
141
130
|
});
|
|
142
131
|
// overwrite protocol because #create auto-normalizes protocol
|
|
143
132
|
protocolsQuery.message.descriptor.filter.protocol = 'example.com/';
|
|
144
133
|
// Re-create auth because we altered the descriptor after signing
|
|
145
|
-
protocolsQuery.message.authorization =
|
|
134
|
+
protocolsQuery.message.authorization = await Message.createAuthorization({
|
|
146
135
|
descriptor: protocolsQuery.message.descriptor,
|
|
147
136
|
signer: Jws.createSigner(alice)
|
|
148
137
|
});
|
|
149
138
|
// Send records write message
|
|
150
|
-
const reply =
|
|
139
|
+
const reply = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
151
140
|
expect(reply.status.code).toBe(400);
|
|
152
141
|
expect(reply.status.detail).toContain(DwnErrorCode.UrlProtocolNotNormalized);
|
|
153
|
-
})
|
|
154
|
-
it('should fail with 400 if signature payload is referencing a different message (`descriptorCid`)', () =>
|
|
155
|
-
const { author, message, protocolsQuery } =
|
|
142
|
+
});
|
|
143
|
+
it('should fail with 400 if signature payload is referencing a different message (`descriptorCid`)', async () => {
|
|
144
|
+
const { author, message, protocolsQuery } = await TestDataGenerator.generateProtocolsQuery();
|
|
156
145
|
const tenant = author.did;
|
|
157
146
|
// replace signature with incorrect `descriptorCid`, even though signature is still valid
|
|
158
|
-
const incorrectDescriptorCid =
|
|
159
|
-
const signaturePayload =
|
|
147
|
+
const incorrectDescriptorCid = await TestDataGenerator.randomCborSha256Cid();
|
|
148
|
+
const signaturePayload = { ...protocolsQuery.signaturePayload };
|
|
160
149
|
signaturePayload.descriptorCid = incorrectDescriptorCid;
|
|
161
150
|
const signaturePayloadBytes = Encoder.objectToBytes(signaturePayload);
|
|
162
151
|
const signer = Jws.createSigner(author);
|
|
163
|
-
const jwsBuilder =
|
|
152
|
+
const jwsBuilder = await GeneralJwsBuilder.create(signaturePayloadBytes, [signer]);
|
|
164
153
|
message.authorization = { signature: jwsBuilder.getJws() };
|
|
165
|
-
const reply =
|
|
154
|
+
const reply = await dwn.processMessage(tenant, message);
|
|
166
155
|
expect(reply.status.code).toBe(400);
|
|
167
156
|
expect(reply.status.detail).toContain(`${incorrectDescriptorCid} does not match expected CID`);
|
|
168
|
-
})
|
|
169
|
-
it('should return 401 if auth fails', () =>
|
|
170
|
-
const alice =
|
|
171
|
-
const { message } =
|
|
157
|
+
});
|
|
158
|
+
it('should return 401 if auth fails', async () => {
|
|
159
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
160
|
+
const { message } = await TestDataGenerator.generateProtocolsQuery({ author: alice });
|
|
172
161
|
// use a bad signature to fail authentication
|
|
173
|
-
const badSignature =
|
|
162
|
+
const badSignature = await TestDataGenerator.randomSignatureString();
|
|
174
163
|
message.authorization.signature.signatures[0].signature = badSignature;
|
|
175
|
-
const reply =
|
|
164
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
176
165
|
expect(reply.status.code).toBe(401);
|
|
177
166
|
expect(reply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
|
|
178
|
-
})
|
|
167
|
+
});
|
|
179
168
|
describe('Grant authorization', () => {
|
|
180
|
-
it('allows an external party to ProtocolsQuery only if they have a valid grant', () =>
|
|
181
|
-
var _a;
|
|
169
|
+
it('allows an external party to ProtocolsQuery only if they have a valid grant', async () => {
|
|
182
170
|
// scenario:
|
|
183
171
|
// 1. Alice grants Bob the access to ProtocolsQuery on her DWN
|
|
184
172
|
// 2. Verify Bob can perform a ProtocolsQuery
|
|
185
173
|
// 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
|
|
186
174
|
// 4. Alice revokes Bob's grant
|
|
187
175
|
// 5. Verify Bob cannot perform ProtocolsQuery with the revoked grant
|
|
188
|
-
const alice =
|
|
189
|
-
const bob =
|
|
190
|
-
const mallory =
|
|
176
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
177
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
178
|
+
const mallory = await TestDataGenerator.generateDidKeyPersona();
|
|
191
179
|
// Alice creates a public and private protocol to test query results
|
|
192
|
-
const { message: publicProtocolMessage } =
|
|
180
|
+
const { message: publicProtocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
193
181
|
author: alice,
|
|
194
182
|
published: true,
|
|
195
183
|
});
|
|
196
|
-
const { status: publicProtocolStatus } =
|
|
184
|
+
const { status: publicProtocolStatus } = await dwn.processMessage(alice.did, publicProtocolMessage);
|
|
197
185
|
expect(publicProtocolStatus.code).toBe(202);
|
|
198
|
-
const { message: privateProtocolMessage } =
|
|
186
|
+
const { message: privateProtocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
199
187
|
author: alice,
|
|
200
188
|
published: false,
|
|
201
189
|
});
|
|
202
|
-
const { status: privateProtocolStatus } =
|
|
190
|
+
const { status: privateProtocolStatus } = await dwn.processMessage(alice.did, privateProtocolMessage);
|
|
203
191
|
expect(privateProtocolStatus.code).toBe(202);
|
|
204
192
|
// 1. Alice grants Bob the access to ProtocolsQuery on her DWN
|
|
205
|
-
const permissionGrant =
|
|
193
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
206
194
|
signer: Jws.createSigner(alice),
|
|
207
195
|
grantedTo: bob.did,
|
|
208
196
|
dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
|
|
209
197
|
scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Query }
|
|
210
198
|
});
|
|
211
199
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
212
|
-
const grantRecordsWriteReply =
|
|
200
|
+
const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
213
201
|
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
214
202
|
// 2. Verify Bob can perform a ProtocolsQuery
|
|
215
203
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
216
|
-
const protocolsQuery =
|
|
204
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
217
205
|
author: bob,
|
|
218
206
|
permissionGrantId,
|
|
219
207
|
});
|
|
220
|
-
const protocolsQueryReply =
|
|
208
|
+
const protocolsQueryReply = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
221
209
|
expect(protocolsQueryReply.status.code).toBe(200);
|
|
222
|
-
expect(
|
|
210
|
+
expect(protocolsQueryReply.entries?.length).toBe(2);
|
|
223
211
|
// 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
|
|
224
|
-
const malloryProtocolsQuery =
|
|
212
|
+
const malloryProtocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
225
213
|
author: mallory,
|
|
226
214
|
permissionGrantId,
|
|
227
215
|
});
|
|
228
|
-
const malloryProtocolsQueryReply =
|
|
216
|
+
const malloryProtocolsQueryReply = await dwn.processMessage(alice.did, malloryProtocolsQuery.message);
|
|
229
217
|
expect(malloryProtocolsQueryReply.status.code).toBe(401);
|
|
230
218
|
expect(malloryProtocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationNotGrantedToAuthor);
|
|
231
219
|
// 4. Alice revokes Bob's grant
|
|
232
|
-
const revokeWrite =
|
|
220
|
+
const revokeWrite = await PermissionsProtocol.createRevocation({
|
|
233
221
|
signer: Jws.createSigner(alice),
|
|
234
|
-
grant:
|
|
222
|
+
grant: await PermissionGrant.parse(permissionGrant.dataEncodedMessage),
|
|
235
223
|
dateRevoked: Time.getCurrentTimestamp()
|
|
236
224
|
});
|
|
237
|
-
const revokeWriteReply =
|
|
225
|
+
const revokeWriteReply = await dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
|
|
238
226
|
expect(revokeWriteReply.status.code).toBe(202);
|
|
239
227
|
// 5. Verify Bob cannot perform ProtocolsQuery with the revoked grant
|
|
240
|
-
const unauthorizedProtocolsQuery =
|
|
228
|
+
const unauthorizedProtocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
241
229
|
author: bob,
|
|
242
230
|
permissionGrantId,
|
|
243
231
|
});
|
|
244
|
-
const unauthorizedProtocolsQueryReply =
|
|
232
|
+
const unauthorizedProtocolsQueryReply = await dwn.processMessage(alice.did, unauthorizedProtocolsQuery.message);
|
|
245
233
|
expect(unauthorizedProtocolsQueryReply.status.code).toBe(401);
|
|
246
234
|
expect(unauthorizedProtocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
247
|
-
})
|
|
248
|
-
it('should allow to scope a ProtocolsQuery to a specific protocol', () =>
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
235
|
+
});
|
|
236
|
+
it('should allow to scope a ProtocolsQuery to a specific protocol', async () => {
|
|
237
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
238
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
252
239
|
// create 2 unpublished protocols, and one published protocol
|
|
253
|
-
const { message: allowedProtocolMessage } =
|
|
240
|
+
const { message: allowedProtocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
254
241
|
author: alice,
|
|
255
242
|
published: false,
|
|
256
243
|
});
|
|
257
244
|
const allowedProtocol = allowedProtocolMessage.descriptor.definition.protocol;
|
|
258
|
-
const { status: allowedStatus } =
|
|
245
|
+
const { status: allowedStatus } = await dwn.processMessage(alice.did, allowedProtocolMessage);
|
|
259
246
|
expect(allowedStatus.code).toBe(202);
|
|
260
|
-
const { message: notAllowedProtocolMessage } =
|
|
247
|
+
const { message: notAllowedProtocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
261
248
|
author: alice,
|
|
262
249
|
published: false,
|
|
263
250
|
});
|
|
264
251
|
const notAllowedProtocol = notAllowedProtocolMessage.descriptor.definition.protocol;
|
|
265
|
-
const { status: notAllowedStatus } =
|
|
252
|
+
const { status: notAllowedStatus } = await dwn.processMessage(alice.did, notAllowedProtocolMessage);
|
|
266
253
|
expect(notAllowedStatus.code).toBe(202);
|
|
267
|
-
const { message: publishedProtocolMessage } =
|
|
254
|
+
const { message: publishedProtocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
268
255
|
author: alice,
|
|
269
256
|
published: true,
|
|
270
257
|
});
|
|
271
258
|
const publishedProtocol = publishedProtocolMessage.descriptor.definition.protocol;
|
|
272
|
-
const { status: publishedStatus } =
|
|
259
|
+
const { status: publishedStatus } = await dwn.processMessage(alice.did, publishedProtocolMessage);
|
|
273
260
|
expect(publishedStatus.code).toBe(202);
|
|
274
261
|
// Alice grants Bob the access to ProtocolsQuery on her DWN for a specific protocol
|
|
275
|
-
const permissionGrant =
|
|
262
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
276
263
|
signer: Jws.createSigner(alice),
|
|
277
264
|
grantedTo: bob.did,
|
|
278
265
|
dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
|
|
279
266
|
scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Query, protocol: allowedProtocol }
|
|
280
267
|
});
|
|
281
268
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
282
|
-
const grantRecordsWriteReply =
|
|
269
|
+
const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
283
270
|
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
284
271
|
// Bob tries to ProtocolsQuery to Alice's DWN for the allowed protocol
|
|
285
|
-
const protocolsQueryAllowed =
|
|
272
|
+
const protocolsQueryAllowed = await TestDataGenerator.generateProtocolsQuery({
|
|
286
273
|
author: bob,
|
|
287
274
|
filter: {
|
|
288
275
|
protocol: allowedProtocol
|
|
289
276
|
},
|
|
290
277
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
291
278
|
});
|
|
292
|
-
const protocolQueryAllowedReply =
|
|
279
|
+
const protocolQueryAllowedReply = await dwn.processMessage(alice.did, protocolsQueryAllowed.message);
|
|
293
280
|
expect(protocolQueryAllowedReply.status.code).toBe(200);
|
|
294
|
-
expect(
|
|
281
|
+
expect(protocolQueryAllowedReply.entries?.length).toBe(1);
|
|
295
282
|
expect(protocolQueryAllowedReply.entries[0].descriptor.definition.protocol).toEqual(allowedProtocol);
|
|
296
283
|
// Bob tries to ProtocolsQuery to Alice's DWN for a different protocol
|
|
297
|
-
const protocolQueryNotAllowed =
|
|
284
|
+
const protocolQueryNotAllowed = await TestDataGenerator.generateProtocolsQuery({
|
|
298
285
|
author: bob,
|
|
299
286
|
filter: {
|
|
300
287
|
protocol: notAllowedProtocol,
|
|
301
288
|
},
|
|
302
289
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
303
290
|
});
|
|
304
|
-
const protocolQueryNotAllowedReply =
|
|
291
|
+
const protocolQueryNotAllowedReply = await dwn.processMessage(alice.did, protocolQueryNotAllowed.message);
|
|
305
292
|
expect(protocolQueryNotAllowedReply.status.code).toBe(200);
|
|
306
|
-
expect(
|
|
293
|
+
expect(protocolQueryNotAllowedReply.entries?.length).toBe(0);
|
|
307
294
|
// Bob tries to ProtocolsQuery to Alice's DWN for a published protocol with the same grant
|
|
308
|
-
const protocolQueryPublished =
|
|
295
|
+
const protocolQueryPublished = await TestDataGenerator.generateProtocolsQuery({
|
|
309
296
|
author: bob,
|
|
310
297
|
filter: {
|
|
311
298
|
protocol: publishedProtocol,
|
|
312
299
|
},
|
|
313
300
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
314
301
|
});
|
|
315
|
-
const protocolQueryPublishedReply =
|
|
302
|
+
const protocolQueryPublishedReply = await dwn.processMessage(alice.did, protocolQueryPublished.message);
|
|
316
303
|
expect(protocolQueryPublishedReply.status.code).toBe(200);
|
|
317
|
-
expect(
|
|
304
|
+
expect(protocolQueryPublishedReply.entries?.length).toBe(1);
|
|
318
305
|
expect(protocolQueryPublishedReply.entries[0].descriptor.definition.protocol).toEqual(publishedProtocol);
|
|
319
306
|
// Bob tries to ProtocolsQuery to Alice's DWN with no filters, using the same grant
|
|
320
|
-
const protocolQueryNoFilters =
|
|
307
|
+
const protocolQueryNoFilters = await ProtocolsQuery.create({
|
|
321
308
|
signer: Jws.createSigner(bob),
|
|
322
309
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
323
310
|
});
|
|
324
|
-
const protocolQueryNoFiltersReply =
|
|
311
|
+
const protocolQueryNoFiltersReply = await dwn.processMessage(alice.did, protocolQueryNoFilters.message);
|
|
325
312
|
expect(protocolQueryNoFiltersReply.status.code).toBe(200);
|
|
326
|
-
expect(
|
|
313
|
+
expect(protocolQueryNoFiltersReply.entries?.length).toBe(1);
|
|
327
314
|
expect(protocolQueryNoFiltersReply.entries[0].descriptor.definition.protocol).toEqual(publishedProtocol);
|
|
328
|
-
})
|
|
329
|
-
it('rejects with 401 when an external party attempts to ProtocolsQuery if they present an expired grant', () =>
|
|
315
|
+
});
|
|
316
|
+
it('rejects with 401 when an external party attempts to ProtocolsQuery if they present an expired grant', async () => {
|
|
330
317
|
// scenario: Alice grants Bob access to ProtocolsQuery, but when Bob invokes the grant it has expired
|
|
331
|
-
const alice =
|
|
332
|
-
const bob =
|
|
318
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
319
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
333
320
|
// Alice gives Bob a permission grant with scope ProtocolsQuery and an expiry time
|
|
334
|
-
const permissionGrant =
|
|
321
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
335
322
|
signer: Jws.createSigner(alice),
|
|
336
323
|
grantedTo: bob.did,
|
|
337
324
|
dateGranted: Time.getCurrentTimestamp(),
|
|
@@ -339,26 +326,26 @@ export function testProtocolsQueryHandler() {
|
|
|
339
326
|
scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Query }
|
|
340
327
|
});
|
|
341
328
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
342
|
-
const permissionGrantWriteReply =
|
|
329
|
+
const permissionGrantWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
343
330
|
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
344
331
|
// Bob does ProtocolsQuery after the grant has expired
|
|
345
|
-
const protocolsQuery =
|
|
332
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
346
333
|
author: bob,
|
|
347
334
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
348
335
|
});
|
|
349
|
-
const protocolsQueryReply =
|
|
336
|
+
const protocolsQueryReply = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
350
337
|
expect(protocolsQueryReply.status.code).toBe(401);
|
|
351
338
|
expect(protocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantExpired);
|
|
352
|
-
})
|
|
353
|
-
it('rejects with 401 when an external party attempts to ProtocolsQuery if the grant is not yet active', () =>
|
|
339
|
+
});
|
|
340
|
+
it('rejects with 401 when an external party attempts to ProtocolsQuery if the grant is not yet active', async () => {
|
|
354
341
|
// scenario: Alice grants Bob access to ProtocolsQuery, but Bob's message has a timestamp just before the grant is active
|
|
355
|
-
const alice =
|
|
356
|
-
const bob =
|
|
342
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
343
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
357
344
|
// Set up timestamps
|
|
358
345
|
const protocolsQueryTimestamp = Time.getCurrentTimestamp();
|
|
359
|
-
|
|
346
|
+
await Time.minimalSleep(); // to ensure granted created will be after the query timestamp
|
|
360
347
|
// Alice gives Bob a permission grant with scope ProtocolsQuery
|
|
361
|
-
const permissionGrant =
|
|
348
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
362
349
|
signer: Jws.createSigner(alice),
|
|
363
350
|
grantedTo: bob.did,
|
|
364
351
|
dateGranted: Time.getCurrentTimestamp(),
|
|
@@ -366,64 +353,64 @@ export function testProtocolsQueryHandler() {
|
|
|
366
353
|
scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Query }
|
|
367
354
|
});
|
|
368
355
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
369
|
-
const permissionGrantWriteReply =
|
|
356
|
+
const permissionGrantWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
370
357
|
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
371
358
|
// Bob does ProtocolsQuery but his message has timestamp before the grant is active
|
|
372
|
-
const protocolsQuery =
|
|
359
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
373
360
|
author: bob,
|
|
374
361
|
messageTimestamp: protocolsQueryTimestamp,
|
|
375
362
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
376
363
|
});
|
|
377
|
-
const protocolsQueryReply =
|
|
364
|
+
const protocolsQueryReply = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
378
365
|
expect(protocolsQueryReply.status.code).toBe(401);
|
|
379
366
|
expect(protocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantNotYetActive);
|
|
380
|
-
})
|
|
381
|
-
it('rejects with 401 when an external party attempts to ProtocolsQuery using a grant that has a different scope', () =>
|
|
367
|
+
});
|
|
368
|
+
it('rejects with 401 when an external party attempts to ProtocolsQuery using a grant that has a different scope', async () => {
|
|
382
369
|
// scenario: Alice grants Bob access to RecordsRead, then Bob tries to invoke the grant with ProtocolsQuery
|
|
383
|
-
const alice =
|
|
384
|
-
const bob =
|
|
370
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
371
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
385
372
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
386
|
-
const permissionGrant =
|
|
373
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
387
374
|
signer: Jws.createSigner(alice),
|
|
388
375
|
grantedTo: bob.did,
|
|
389
376
|
dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
|
|
390
377
|
scope: { interface: DwnInterfaceName.Records, method: DwnMethodName.Read, protocol: 'https://example.com/protocol/test' }
|
|
391
378
|
});
|
|
392
379
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
393
|
-
const grantRecordsWriteReply =
|
|
380
|
+
const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
394
381
|
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
395
382
|
// Bob tries to ProtocolsQuery
|
|
396
|
-
const protocolsQuery =
|
|
383
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
397
384
|
author: bob,
|
|
398
385
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
399
386
|
});
|
|
400
|
-
const protocolsQueryReply =
|
|
387
|
+
const protocolsQueryReply = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
401
388
|
expect(protocolsQueryReply.status.code).toBe(401);
|
|
402
389
|
expect(protocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationInterfaceMismatch);
|
|
403
|
-
})
|
|
404
|
-
it('rejects with 401 if the permission grant cannot be found', () =>
|
|
390
|
+
});
|
|
391
|
+
it('rejects with 401 if the permission grant cannot be found', async () => {
|
|
405
392
|
// scenario: Bob uses a permissionGrantId to ProtocolsQuery, but no permission grant can be found.
|
|
406
|
-
const alice =
|
|
407
|
-
const bob =
|
|
393
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
394
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
408
395
|
// Bob tries to ProtocolsQuery
|
|
409
|
-
const protocolsQuery =
|
|
396
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
410
397
|
author: bob,
|
|
411
|
-
permissionGrantId:
|
|
398
|
+
permissionGrantId: await TestDataGenerator.randomCborSha256Cid(),
|
|
412
399
|
});
|
|
413
|
-
const protocolsQueryReply =
|
|
400
|
+
const protocolsQueryReply = await dwn.processMessage(alice.did, protocolsQuery.message);
|
|
414
401
|
expect(protocolsQueryReply.status.code).toBe(401);
|
|
415
402
|
expect(protocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantMissing);
|
|
416
|
-
})
|
|
417
|
-
it('rejects with 401 if the permission grant has not been grantedFor the tenant', () =>
|
|
403
|
+
});
|
|
404
|
+
it('rejects with 401 if the permission grant has not been grantedFor the tenant', async () => {
|
|
418
405
|
// Scenario:
|
|
419
406
|
// 1. Alice gives Carol a permission grant with scope ProtocolsQuery
|
|
420
407
|
// 2. Bob (for unknown reason, thus this is a super edge case) stores the grant in his DWN
|
|
421
408
|
// 3. Verify that Carol cannot use permission grant to gain access to Bob's DWN
|
|
422
|
-
const alice =
|
|
423
|
-
const bob =
|
|
424
|
-
const carol =
|
|
409
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
410
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
411
|
+
const carol = await TestDataGenerator.generateDidKeyPersona();
|
|
425
412
|
// 1. Alice gives Carol a permission grant with scope ProtocolsQuery
|
|
426
|
-
const permissionGrant =
|
|
413
|
+
const permissionGrant = await PermissionsProtocol.createGrant({
|
|
427
414
|
signer: Jws.createSigner(alice),
|
|
428
415
|
grantedTo: carol.did,
|
|
429
416
|
dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
|
|
@@ -431,20 +418,20 @@ export function testProtocolsQueryHandler() {
|
|
|
431
418
|
});
|
|
432
419
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
433
420
|
// 2. Bob (for unknown reason, thus this is a super edge case) stores the grant in his DWN
|
|
434
|
-
const bobWrappedGrant =
|
|
435
|
-
|
|
436
|
-
const grantRecordsWriteReply =
|
|
421
|
+
const bobWrappedGrant = await RecordsWrite.parse(permissionGrant.recordsWrite.message);
|
|
422
|
+
await bobWrappedGrant.signAsOwner(Jws.createSigner(bob));
|
|
423
|
+
const grantRecordsWriteReply = await dwn.processMessage(bob.did, bobWrappedGrant.message, { dataStream });
|
|
437
424
|
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
438
425
|
// 3. Verify that Carol cannot use permission grant to gain access to Bob's DWN
|
|
439
426
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
440
|
-
const protocolsQuery =
|
|
427
|
+
const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
|
|
441
428
|
author: carol,
|
|
442
429
|
permissionGrantId,
|
|
443
430
|
});
|
|
444
|
-
const protocolsQueryReply =
|
|
431
|
+
const protocolsQueryReply = await dwn.processMessage(bob.did, protocolsQuery.message);
|
|
445
432
|
expect(protocolsQueryReply.status.code).toBe(401);
|
|
446
433
|
expect(protocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationNotGrantedForTenant);
|
|
447
|
-
})
|
|
434
|
+
});
|
|
448
435
|
});
|
|
449
436
|
});
|
|
450
437
|
});
|