@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 freeForAll from '../vectors/protocol-definitions/free-for-all.json' with { type: 'json' };
|
|
11
2
|
import { Jws } from '../../src/utils/jws.js';
|
|
12
3
|
import { Message } from '../../src/core/message.js';
|
|
@@ -28,7 +19,7 @@ export function testMessagesSyncHandler() {
|
|
|
28
19
|
let stateIndex;
|
|
29
20
|
let eventStream;
|
|
30
21
|
let dwn;
|
|
31
|
-
beforeAll(() =>
|
|
22
|
+
beforeAll(async () => {
|
|
32
23
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
33
24
|
const stores = TestStores.get();
|
|
34
25
|
messageStore = stores.messageStore;
|
|
@@ -36,236 +27,236 @@ export function testMessagesSyncHandler() {
|
|
|
36
27
|
resumableTaskStore = stores.resumableTaskStore;
|
|
37
28
|
stateIndex = stores.stateIndex;
|
|
38
29
|
eventStream = TestEventStream.get();
|
|
39
|
-
dwn =
|
|
40
|
-
})
|
|
41
|
-
beforeEach(() =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
afterAll(() =>
|
|
48
|
-
|
|
49
|
-
})
|
|
30
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
31
|
+
});
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
await messageStore.clear();
|
|
34
|
+
await dataStore.clear();
|
|
35
|
+
await resumableTaskStore.clear();
|
|
36
|
+
await stateIndex.clear();
|
|
37
|
+
});
|
|
38
|
+
afterAll(async () => {
|
|
39
|
+
await dwn.close();
|
|
40
|
+
});
|
|
50
41
|
describe('root action', () => {
|
|
51
|
-
it('returns the empty root hash for a tenant with no messages', () =>
|
|
52
|
-
const alice =
|
|
53
|
-
const { message } =
|
|
42
|
+
it('returns the empty root hash for a tenant with no messages', async () => {
|
|
43
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
44
|
+
const { message } = await MessagesSync.create({
|
|
54
45
|
signer: Jws.createSigner(alice),
|
|
55
46
|
action: 'root',
|
|
56
47
|
});
|
|
57
|
-
const reply =
|
|
48
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
58
49
|
expect(reply.status.code).toBe(200);
|
|
59
50
|
expect(typeof reply.root).toBe('string');
|
|
60
51
|
expect(reply.root.length).toBe(64); // hex-encoded 32-byte hash
|
|
61
|
-
})
|
|
62
|
-
it('returns a different root hash after writing a message', () =>
|
|
63
|
-
const alice =
|
|
52
|
+
});
|
|
53
|
+
it('returns a different root hash after writing a message', async () => {
|
|
54
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
64
55
|
// get the empty root
|
|
65
|
-
const { message: rootMsg1 } =
|
|
56
|
+
const { message: rootMsg1 } = await MessagesSync.create({
|
|
66
57
|
signer: Jws.createSigner(alice),
|
|
67
58
|
action: 'root',
|
|
68
59
|
});
|
|
69
|
-
const reply1 =
|
|
60
|
+
const reply1 = await dwn.processMessage(alice.did, rootMsg1);
|
|
70
61
|
expect(reply1.status.code).toBe(200);
|
|
71
62
|
const emptyRoot = reply1.root;
|
|
72
63
|
// write a record
|
|
73
|
-
const { message: recordMessage, dataStream } =
|
|
74
|
-
const writeReply =
|
|
64
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
65
|
+
const writeReply = await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
75
66
|
expect(writeReply.status.code).toBe(202);
|
|
76
67
|
// get the root again
|
|
77
|
-
const { message: rootMsg2 } =
|
|
68
|
+
const { message: rootMsg2 } = await MessagesSync.create({
|
|
78
69
|
signer: Jws.createSigner(alice),
|
|
79
70
|
action: 'root',
|
|
80
71
|
});
|
|
81
|
-
const reply2 =
|
|
72
|
+
const reply2 = await dwn.processMessage(alice.did, rootMsg2);
|
|
82
73
|
expect(reply2.status.code).toBe(200);
|
|
83
74
|
expect(reply2.root).not.toBe(emptyRoot);
|
|
84
|
-
})
|
|
85
|
-
it('returns protocol-scoped root hash when protocol is specified', () =>
|
|
86
|
-
const alice =
|
|
87
|
-
const protocolDefinition =
|
|
75
|
+
});
|
|
76
|
+
it('returns protocol-scoped root hash when protocol is specified', async () => {
|
|
77
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
78
|
+
const protocolDefinition = { ...freeForAll, published: true };
|
|
88
79
|
// configure the protocol
|
|
89
|
-
const { message: protocolMessage } =
|
|
80
|
+
const { message: protocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
90
81
|
author: alice,
|
|
91
82
|
protocolDefinition,
|
|
92
83
|
});
|
|
93
|
-
const configureReply =
|
|
84
|
+
const configureReply = await dwn.processMessage(alice.did, protocolMessage);
|
|
94
85
|
expect(configureReply.status.code).toBe(202);
|
|
95
86
|
// write a record for this protocol
|
|
96
|
-
const { message: recordMessage, dataStream } =
|
|
87
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({
|
|
97
88
|
author: alice,
|
|
98
89
|
protocol: protocolDefinition.protocol,
|
|
99
90
|
protocolPath: 'post',
|
|
100
91
|
schema: protocolDefinition.types.post.schema,
|
|
101
92
|
});
|
|
102
|
-
const writeReply =
|
|
93
|
+
const writeReply = await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
103
94
|
expect(writeReply.status.code).toBe(202);
|
|
104
95
|
// write a flat-space (non-protocol) record to diverge the global root
|
|
105
|
-
const { message: flatRecord, dataStream: flatDataStream } =
|
|
106
|
-
const flatWriteReply =
|
|
96
|
+
const { message: flatRecord, dataStream: flatDataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
97
|
+
const flatWriteReply = await dwn.processMessage(alice.did, flatRecord, { dataStream: flatDataStream });
|
|
107
98
|
expect(flatWriteReply.status.code).toBe(202);
|
|
108
99
|
// get the global root
|
|
109
|
-
const { message: globalRootMsg } =
|
|
100
|
+
const { message: globalRootMsg } = await MessagesSync.create({
|
|
110
101
|
signer: Jws.createSigner(alice),
|
|
111
102
|
action: 'root',
|
|
112
103
|
});
|
|
113
|
-
const globalReply =
|
|
104
|
+
const globalReply = await dwn.processMessage(alice.did, globalRootMsg);
|
|
114
105
|
expect(globalReply.status.code).toBe(200);
|
|
115
106
|
// get the protocol-scoped root
|
|
116
|
-
const { message: protoRootMsg } =
|
|
107
|
+
const { message: protoRootMsg } = await MessagesSync.create({
|
|
117
108
|
signer: Jws.createSigner(alice),
|
|
118
109
|
action: 'root',
|
|
119
110
|
protocol: protocolDefinition.protocol,
|
|
120
111
|
});
|
|
121
|
-
const protoReply =
|
|
112
|
+
const protoReply = await dwn.processMessage(alice.did, protoRootMsg);
|
|
122
113
|
expect(protoReply.status.code).toBe(200);
|
|
123
114
|
// global root and protocol root should be different
|
|
124
115
|
// (global includes the flat-space record which is not in any protocol)
|
|
125
116
|
expect(protoReply.root).not.toBe(globalReply.root);
|
|
126
117
|
// both should be non-empty roots
|
|
127
118
|
expect(protoReply.root.length).toBe(64);
|
|
128
|
-
})
|
|
119
|
+
});
|
|
129
120
|
});
|
|
130
121
|
describe('subtree action', () => {
|
|
131
|
-
it('returns a subtree hash for a given bit prefix', () =>
|
|
132
|
-
const alice =
|
|
122
|
+
it('returns a subtree hash for a given bit prefix', async () => {
|
|
123
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
133
124
|
// write a record so the tree is non-empty
|
|
134
|
-
const { message: recordMessage, dataStream } =
|
|
135
|
-
const writeReply =
|
|
125
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
126
|
+
const writeReply = await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
136
127
|
expect(writeReply.status.code).toBe(202);
|
|
137
|
-
const { message } =
|
|
128
|
+
const { message } = await MessagesSync.create({
|
|
138
129
|
signer: Jws.createSigner(alice),
|
|
139
130
|
action: 'subtree',
|
|
140
131
|
prefix: '0',
|
|
141
132
|
});
|
|
142
|
-
const reply =
|
|
133
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
143
134
|
expect(reply.status.code).toBe(200);
|
|
144
135
|
expect(typeof reply.hash).toBe('string');
|
|
145
136
|
expect(reply.hash.length).toBe(64);
|
|
146
|
-
})
|
|
147
|
-
it('returns different hashes for different prefixes', () =>
|
|
148
|
-
const alice =
|
|
137
|
+
});
|
|
138
|
+
it('returns different hashes for different prefixes', async () => {
|
|
139
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
149
140
|
// write several records to populate various subtrees
|
|
150
141
|
for (let i = 0; i < 10; i++) {
|
|
151
|
-
const { message: recordMessage, dataStream } =
|
|
152
|
-
const writeReply =
|
|
142
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
143
|
+
const writeReply = await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
153
144
|
expect(writeReply.status.code).toBe(202);
|
|
154
145
|
}
|
|
155
|
-
const { message: msg0 } =
|
|
146
|
+
const { message: msg0 } = await MessagesSync.create({
|
|
156
147
|
signer: Jws.createSigner(alice),
|
|
157
148
|
action: 'subtree',
|
|
158
149
|
prefix: '0',
|
|
159
150
|
});
|
|
160
|
-
const reply0 =
|
|
161
|
-
const { message: msg1 } =
|
|
151
|
+
const reply0 = await dwn.processMessage(alice.did, msg0);
|
|
152
|
+
const { message: msg1 } = await MessagesSync.create({
|
|
162
153
|
signer: Jws.createSigner(alice),
|
|
163
154
|
action: 'subtree',
|
|
164
155
|
prefix: '1',
|
|
165
156
|
});
|
|
166
|
-
const reply1 =
|
|
157
|
+
const reply1 = await dwn.processMessage(alice.did, msg1);
|
|
167
158
|
expect(reply0.status.code).toBe(200);
|
|
168
159
|
expect(reply1.status.code).toBe(200);
|
|
169
160
|
// With 10 messages, it's very likely the two halves of the tree differ
|
|
170
161
|
// (not guaranteed but probabilistically near-certain)
|
|
171
|
-
})
|
|
162
|
+
});
|
|
172
163
|
});
|
|
173
164
|
describe('leaves action', () => {
|
|
174
|
-
it('returns all message CIDs for an empty prefix', () =>
|
|
175
|
-
const alice =
|
|
165
|
+
it('returns all message CIDs for an empty prefix', async () => {
|
|
166
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
176
167
|
// write some messages
|
|
177
168
|
const expectedCids = [];
|
|
178
169
|
for (let i = 0; i < 3; i++) {
|
|
179
|
-
const { message: recordMessage, dataStream } =
|
|
180
|
-
const writeReply =
|
|
170
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
171
|
+
const writeReply = await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
181
172
|
expect(writeReply.status.code).toBe(202);
|
|
182
|
-
expectedCids.push(
|
|
173
|
+
expectedCids.push(await Message.getCid(recordMessage));
|
|
183
174
|
}
|
|
184
|
-
const { message } =
|
|
175
|
+
const { message } = await MessagesSync.create({
|
|
185
176
|
signer: Jws.createSigner(alice),
|
|
186
177
|
action: 'leaves',
|
|
187
178
|
prefix: '',
|
|
188
179
|
});
|
|
189
|
-
const reply =
|
|
180
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
190
181
|
expect(reply.status.code).toBe(200);
|
|
191
182
|
expect(Array.isArray(reply.entries)).toBe(true);
|
|
192
183
|
expect(reply.entries.length).toBe(3);
|
|
193
184
|
for (const cid of expectedCids) {
|
|
194
185
|
expect(reply.entries).toContain(cid);
|
|
195
186
|
}
|
|
196
|
-
})
|
|
197
|
-
it('returns protocol-scoped leaves when protocol is specified', () =>
|
|
198
|
-
const alice =
|
|
199
|
-
const protocolDefinition =
|
|
187
|
+
});
|
|
188
|
+
it('returns protocol-scoped leaves when protocol is specified', async () => {
|
|
189
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
190
|
+
const protocolDefinition = { ...freeForAll, published: true };
|
|
200
191
|
// configure the protocol
|
|
201
|
-
const { message: protocolMessage } =
|
|
192
|
+
const { message: protocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
202
193
|
author: alice,
|
|
203
194
|
protocolDefinition,
|
|
204
195
|
});
|
|
205
|
-
const configureReply =
|
|
196
|
+
const configureReply = await dwn.processMessage(alice.did, protocolMessage);
|
|
206
197
|
expect(configureReply.status.code).toBe(202);
|
|
207
198
|
// write a protocol-scoped record
|
|
208
|
-
const { message: protoRecord, dataStream: protoDataStream } =
|
|
199
|
+
const { message: protoRecord, dataStream: protoDataStream } = await TestDataGenerator.generateRecordsWrite({
|
|
209
200
|
author: alice,
|
|
210
201
|
protocol: protocolDefinition.protocol,
|
|
211
202
|
protocolPath: 'post',
|
|
212
203
|
schema: protocolDefinition.types.post.schema,
|
|
213
204
|
});
|
|
214
|
-
const protoWriteReply =
|
|
205
|
+
const protoWriteReply = await dwn.processMessage(alice.did, protoRecord, { dataStream: protoDataStream });
|
|
215
206
|
expect(protoWriteReply.status.code).toBe(202);
|
|
216
207
|
// write a non-protocol record
|
|
217
|
-
const { message: flatRecord, dataStream: flatDataStream } =
|
|
218
|
-
const flatWriteReply =
|
|
208
|
+
const { message: flatRecord, dataStream: flatDataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
209
|
+
const flatWriteReply = await dwn.processMessage(alice.did, flatRecord, { dataStream: flatDataStream });
|
|
219
210
|
expect(flatWriteReply.status.code).toBe(202);
|
|
220
211
|
// query protocol-scoped leaves
|
|
221
|
-
const { message } =
|
|
212
|
+
const { message } = await MessagesSync.create({
|
|
222
213
|
signer: Jws.createSigner(alice),
|
|
223
214
|
action: 'leaves',
|
|
224
215
|
prefix: '',
|
|
225
216
|
protocol: protocolDefinition.protocol,
|
|
226
217
|
});
|
|
227
|
-
const reply =
|
|
218
|
+
const reply = await dwn.processMessage(alice.did, message);
|
|
228
219
|
expect(reply.status.code).toBe(200);
|
|
229
220
|
// should contain the ProtocolsConfigure and the protocol-scoped record, but not the flat record
|
|
230
221
|
expect(reply.entries.length).toBe(2);
|
|
231
|
-
const protocolCid =
|
|
232
|
-
const recordCid =
|
|
222
|
+
const protocolCid = await Message.getCid(protocolMessage);
|
|
223
|
+
const recordCid = await Message.getCid(protoRecord);
|
|
233
224
|
expect(reply.entries).toContain(protocolCid);
|
|
234
225
|
expect(reply.entries).toContain(recordCid);
|
|
235
|
-
})
|
|
226
|
+
});
|
|
236
227
|
});
|
|
237
228
|
describe('authorization', () => {
|
|
238
|
-
it('returns 401 if tenant is not the author', () =>
|
|
239
|
-
const alice =
|
|
240
|
-
const bob =
|
|
241
|
-
const { message } =
|
|
229
|
+
it('returns 401 if tenant is not the author', async () => {
|
|
230
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
231
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
232
|
+
const { message } = await MessagesSync.create({
|
|
242
233
|
signer: Jws.createSigner(alice),
|
|
243
234
|
action: 'root',
|
|
244
235
|
});
|
|
245
|
-
const reply =
|
|
236
|
+
const reply = await dwn.processMessage(bob.did, message);
|
|
246
237
|
expect(reply.status.code).toBe(401);
|
|
247
|
-
})
|
|
248
|
-
it('returns 400 if message is invalid', () =>
|
|
249
|
-
const alice =
|
|
250
|
-
const { message } =
|
|
238
|
+
});
|
|
239
|
+
it('returns 400 if message is invalid', async () => {
|
|
240
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
241
|
+
const { message } = await MessagesSync.create({
|
|
251
242
|
signer: Jws.createSigner(alice),
|
|
252
243
|
action: 'root',
|
|
253
244
|
});
|
|
254
245
|
message['descriptor']['troll'] = 'hehe';
|
|
255
246
|
const handler = new MessagesSyncHandler(didResolver, messageStore, stateIndex);
|
|
256
|
-
const reply =
|
|
247
|
+
const reply = await handler.handle({ tenant: alice.did, message });
|
|
257
248
|
expect(reply.status.code).toBe(400);
|
|
258
|
-
})
|
|
249
|
+
});
|
|
259
250
|
describe('grant-based sync', () => {
|
|
260
|
-
it('allows sync with a matching MessagesSync grant scope', () =>
|
|
261
|
-
const alice =
|
|
262
|
-
const bob =
|
|
251
|
+
it('allows sync with a matching MessagesSync grant scope', async () => {
|
|
252
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
253
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
263
254
|
// write a record so the tree is non-empty
|
|
264
|
-
const { message: recordMessage, dataStream } =
|
|
265
|
-
const writeReply =
|
|
255
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
256
|
+
const writeReply = await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
266
257
|
expect(writeReply.status.code).toBe(202);
|
|
267
258
|
// grant bob permission to sync Alice's messages
|
|
268
|
-
const { message: grantMessage, dataStream: grantDataStream } =
|
|
259
|
+
const { message: grantMessage, dataStream: grantDataStream } = await TestDataGenerator.generateGrantCreate({
|
|
269
260
|
author: alice,
|
|
270
261
|
grantedTo: bob,
|
|
271
262
|
scope: {
|
|
@@ -273,38 +264,38 @@ export function testMessagesSyncHandler() {
|
|
|
273
264
|
method: DwnMethodName.Sync,
|
|
274
265
|
},
|
|
275
266
|
});
|
|
276
|
-
const grantReply =
|
|
267
|
+
const grantReply = await dwn.processMessage(alice.did, grantMessage, { dataStream: grantDataStream });
|
|
277
268
|
expect(grantReply.status.code).toBe(202);
|
|
278
269
|
// bob syncs using the grant — root action
|
|
279
|
-
const { message: syncMsg } =
|
|
270
|
+
const { message: syncMsg } = await MessagesSync.create({
|
|
280
271
|
signer: Jws.createSigner(bob),
|
|
281
272
|
action: 'root',
|
|
282
273
|
permissionGrantId: grantMessage.recordId,
|
|
283
274
|
});
|
|
284
|
-
const reply =
|
|
275
|
+
const reply = await dwn.processMessage(alice.did, syncMsg);
|
|
285
276
|
expect(reply.status.code).toBe(200);
|
|
286
277
|
expect(typeof reply.root).toBe('string');
|
|
287
278
|
expect(reply.root.length).toBe(64);
|
|
288
|
-
})
|
|
289
|
-
it('allows sync with a protocol-scoped grant', () =>
|
|
290
|
-
const alice =
|
|
291
|
-
const bob =
|
|
292
|
-
const protocolDefinition =
|
|
279
|
+
});
|
|
280
|
+
it('allows sync with a protocol-scoped grant', async () => {
|
|
281
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
282
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
283
|
+
const protocolDefinition = { ...freeForAll, published: true };
|
|
293
284
|
// configure and write a protocol record
|
|
294
|
-
const { message: protocolMessage } =
|
|
285
|
+
const { message: protocolMessage } = await TestDataGenerator.generateProtocolsConfigure({
|
|
295
286
|
author: alice,
|
|
296
287
|
protocolDefinition,
|
|
297
288
|
});
|
|
298
|
-
|
|
299
|
-
const { message: recordMessage, dataStream } =
|
|
289
|
+
await dwn.processMessage(alice.did, protocolMessage);
|
|
290
|
+
const { message: recordMessage, dataStream } = await TestDataGenerator.generateRecordsWrite({
|
|
300
291
|
author: alice,
|
|
301
292
|
protocol: protocolDefinition.protocol,
|
|
302
293
|
protocolPath: 'post',
|
|
303
294
|
schema: protocolDefinition.types.post.schema,
|
|
304
295
|
});
|
|
305
|
-
|
|
296
|
+
await dwn.processMessage(alice.did, recordMessage, { dataStream });
|
|
306
297
|
// grant bob permission to sync Alice's messages scoped to this protocol
|
|
307
|
-
const { message: grantMessage, dataStream: grantDataStream } =
|
|
298
|
+
const { message: grantMessage, dataStream: grantDataStream } = await TestDataGenerator.generateGrantCreate({
|
|
308
299
|
author: alice,
|
|
309
300
|
grantedTo: bob,
|
|
310
301
|
scope: {
|
|
@@ -313,31 +304,31 @@ export function testMessagesSyncHandler() {
|
|
|
313
304
|
protocol: protocolDefinition.protocol,
|
|
314
305
|
},
|
|
315
306
|
});
|
|
316
|
-
const grantReply =
|
|
307
|
+
const grantReply = await dwn.processMessage(alice.did, grantMessage, { dataStream: grantDataStream });
|
|
317
308
|
expect(grantReply.status.code).toBe(202);
|
|
318
309
|
// bob syncs leaves with the protocol-scoped grant
|
|
319
|
-
const { message: syncMsg } =
|
|
310
|
+
const { message: syncMsg } = await MessagesSync.create({
|
|
320
311
|
signer: Jws.createSigner(bob),
|
|
321
312
|
action: 'leaves',
|
|
322
313
|
prefix: '',
|
|
323
314
|
protocol: protocolDefinition.protocol,
|
|
324
315
|
permissionGrantId: grantMessage.recordId,
|
|
325
316
|
});
|
|
326
|
-
const reply =
|
|
317
|
+
const reply = await dwn.processMessage(alice.did, syncMsg);
|
|
327
318
|
expect(reply.status.code).toBe(200);
|
|
328
319
|
expect(Array.isArray(reply.entries)).toBe(true);
|
|
329
320
|
// includes both the ProtocolsConfigure and the RecordsWrite
|
|
330
321
|
expect(reply.entries.length).toBe(2);
|
|
331
|
-
const protocolCid =
|
|
332
|
-
const recordCid =
|
|
322
|
+
const protocolCid = await Message.getCid(protocolMessage);
|
|
323
|
+
const recordCid = await Message.getCid(recordMessage);
|
|
333
324
|
expect(reply.entries).toContain(protocolCid);
|
|
334
325
|
expect(reply.entries).toContain(recordCid);
|
|
335
|
-
})
|
|
336
|
-
it('rejects sync with mismatching interface grant scope', () =>
|
|
337
|
-
const alice =
|
|
338
|
-
const bob =
|
|
326
|
+
});
|
|
327
|
+
it('rejects sync with mismatching interface grant scope', async () => {
|
|
328
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
329
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
339
330
|
// create a RecordsWrite grant (wrong interface for MessagesSync)
|
|
340
|
-
const { message: grantMessage, dataStream } =
|
|
331
|
+
const { message: grantMessage, dataStream } = await TestDataGenerator.generateGrantCreate({
|
|
341
332
|
author: alice,
|
|
342
333
|
grantedTo: bob,
|
|
343
334
|
scope: {
|
|
@@ -346,22 +337,22 @@ export function testMessagesSyncHandler() {
|
|
|
346
337
|
protocol: freeForAll.protocol,
|
|
347
338
|
},
|
|
348
339
|
});
|
|
349
|
-
const grantReply =
|
|
340
|
+
const grantReply = await dwn.processMessage(alice.did, grantMessage, { dataStream });
|
|
350
341
|
expect(grantReply.status.code).toBe(202);
|
|
351
|
-
const { message: syncMsg } =
|
|
342
|
+
const { message: syncMsg } = await MessagesSync.create({
|
|
352
343
|
signer: Jws.createSigner(bob),
|
|
353
344
|
action: 'root',
|
|
354
345
|
permissionGrantId: grantMessage.recordId,
|
|
355
346
|
});
|
|
356
|
-
const reply =
|
|
347
|
+
const reply = await dwn.processMessage(alice.did, syncMsg);
|
|
357
348
|
expect(reply.status.code).toBe(401);
|
|
358
349
|
expect(reply.status.detail).toContain(DwnErrorCode.GrantAuthorizationInterfaceMismatch);
|
|
359
|
-
})
|
|
360
|
-
it('rejects sync with mismatching method grant scope', () =>
|
|
361
|
-
const alice =
|
|
362
|
-
const bob =
|
|
350
|
+
});
|
|
351
|
+
it('rejects sync with mismatching method grant scope', async () => {
|
|
352
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
353
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
363
354
|
// create a MessagesSubscribe grant (wrong method for MessagesSync)
|
|
364
|
-
const { message: grantMessage, dataStream } =
|
|
355
|
+
const { message: grantMessage, dataStream } = await TestDataGenerator.generateGrantCreate({
|
|
365
356
|
author: alice,
|
|
366
357
|
grantedTo: bob,
|
|
367
358
|
scope: {
|
|
@@ -369,22 +360,22 @@ export function testMessagesSyncHandler() {
|
|
|
369
360
|
method: DwnMethodName.Subscribe,
|
|
370
361
|
},
|
|
371
362
|
});
|
|
372
|
-
const grantReply =
|
|
363
|
+
const grantReply = await dwn.processMessage(alice.did, grantMessage, { dataStream });
|
|
373
364
|
expect(grantReply.status.code).toBe(202);
|
|
374
|
-
const { message: syncMsg } =
|
|
365
|
+
const { message: syncMsg } = await MessagesSync.create({
|
|
375
366
|
signer: Jws.createSigner(bob),
|
|
376
367
|
action: 'root',
|
|
377
368
|
permissionGrantId: grantMessage.recordId,
|
|
378
369
|
});
|
|
379
|
-
const reply =
|
|
370
|
+
const reply = await dwn.processMessage(alice.did, syncMsg);
|
|
380
371
|
expect(reply.status.code).toBe(401);
|
|
381
372
|
expect(reply.status.detail).toContain(DwnErrorCode.GrantAuthorizationMethodMismatch);
|
|
382
|
-
})
|
|
383
|
-
it('rejects sync with mismatching protocol grant scope', () =>
|
|
384
|
-
const alice =
|
|
385
|
-
const bob =
|
|
373
|
+
});
|
|
374
|
+
it('rejects sync with mismatching protocol grant scope', async () => {
|
|
375
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
376
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
386
377
|
// grant bob permission to sync protocol1
|
|
387
|
-
const { message: grantMessage, dataStream } =
|
|
378
|
+
const { message: grantMessage, dataStream } = await TestDataGenerator.generateGrantCreate({
|
|
388
379
|
author: alice,
|
|
389
380
|
grantedTo: bob,
|
|
390
381
|
scope: {
|
|
@@ -393,39 +384,39 @@ export function testMessagesSyncHandler() {
|
|
|
393
384
|
protocol: 'http://protocol1',
|
|
394
385
|
},
|
|
395
386
|
});
|
|
396
|
-
const grantReply =
|
|
387
|
+
const grantReply = await dwn.processMessage(alice.did, grantMessage, { dataStream });
|
|
397
388
|
expect(grantReply.status.code).toBe(202);
|
|
398
389
|
// bob attempts to sync protocol2 using the protocol1 grant
|
|
399
|
-
const { message: syncMsg } =
|
|
390
|
+
const { message: syncMsg } = await MessagesSync.create({
|
|
400
391
|
signer: Jws.createSigner(bob),
|
|
401
392
|
action: 'root',
|
|
402
393
|
protocol: 'http://protocol2',
|
|
403
394
|
permissionGrantId: grantMessage.recordId,
|
|
404
395
|
});
|
|
405
|
-
const reply =
|
|
396
|
+
const reply = await dwn.processMessage(alice.did, syncMsg);
|
|
406
397
|
expect(reply.status.code).toBe(401);
|
|
407
398
|
expect(reply.status.detail).toContain(DwnErrorCode.MessagesGrantAuthorizationMismatchedProtocol);
|
|
408
|
-
})
|
|
399
|
+
});
|
|
409
400
|
});
|
|
410
401
|
});
|
|
411
402
|
describe('input validation', () => {
|
|
412
|
-
it('returns 400 for an unknown action', () =>
|
|
413
|
-
const alice =
|
|
414
|
-
const { message } =
|
|
403
|
+
it('returns 400 for an unknown action', async () => {
|
|
404
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
405
|
+
const { message } = await MessagesSync.create({
|
|
415
406
|
signer: Jws.createSigner(alice),
|
|
416
407
|
action: 'root',
|
|
417
408
|
});
|
|
418
409
|
// manually override to an invalid action
|
|
419
410
|
message.descriptor.action = 'invalid';
|
|
420
411
|
const handler = new MessagesSyncHandler(didResolver, messageStore, stateIndex);
|
|
421
|
-
const reply =
|
|
412
|
+
const reply = await handler.handle({ tenant: alice.did, message });
|
|
422
413
|
expect(reply.status.code).toBe(400);
|
|
423
414
|
// the JSON schema validator catches the invalid action before the handler switch/case
|
|
424
415
|
expect(reply.status.detail).toContain('SchemaValidatorFailure');
|
|
425
|
-
})
|
|
426
|
-
it('returns 400 for unknown action that bypasses schema validation (default case)', () =>
|
|
427
|
-
const alice =
|
|
428
|
-
const { message } =
|
|
416
|
+
});
|
|
417
|
+
it('returns 400 for unknown action that bypasses schema validation (default case)', async () => {
|
|
418
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
419
|
+
const { message } = await MessagesSync.create({
|
|
429
420
|
signer: Jws.createSigner(alice),
|
|
430
421
|
action: 'root',
|
|
431
422
|
});
|
|
@@ -439,17 +430,17 @@ export function testMessagesSyncHandler() {
|
|
|
439
430
|
// Override action to something that passes the stub but hits the default case
|
|
440
431
|
message.descriptor.action = 'bogusAction';
|
|
441
432
|
const handler = new MessagesSyncHandler(didResolver, messageStore, stateIndex);
|
|
442
|
-
const reply =
|
|
433
|
+
const reply = await handler.handle({ tenant: alice.did, message });
|
|
443
434
|
expect(reply.status.code).toBe(400);
|
|
444
435
|
expect(reply.status.detail).toContain('Unknown action');
|
|
445
436
|
}
|
|
446
437
|
finally {
|
|
447
438
|
parseStub.restore();
|
|
448
439
|
}
|
|
449
|
-
})
|
|
450
|
-
it('returns 500 for invalid prefix with non-binary characters (via stubbed parse)', () =>
|
|
451
|
-
const alice =
|
|
452
|
-
const { message } =
|
|
440
|
+
});
|
|
441
|
+
it('returns 500 for invalid prefix with non-binary characters (via stubbed parse)', async () => {
|
|
442
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
443
|
+
const { message } = await MessagesSync.create({
|
|
453
444
|
signer: Jws.createSigner(alice),
|
|
454
445
|
action: 'subtree',
|
|
455
446
|
prefix: '0',
|
|
@@ -464,17 +455,17 @@ export function testMessagesSyncHandler() {
|
|
|
464
455
|
// Override prefix to contain invalid characters
|
|
465
456
|
message.descriptor.prefix = 'abc';
|
|
466
457
|
const handler = new MessagesSyncHandler(didResolver, messageStore, stateIndex);
|
|
467
|
-
const reply =
|
|
458
|
+
const reply = await handler.handle({ tenant: alice.did, message });
|
|
468
459
|
expect(reply.status.code).toBe(500);
|
|
469
460
|
expect(reply.status.detail).toContain('MessagesSyncInvalidPrefix');
|
|
470
461
|
}
|
|
471
462
|
finally {
|
|
472
463
|
parseStub.restore();
|
|
473
464
|
}
|
|
474
|
-
})
|
|
475
|
-
it('returns 500 for prefix exceeding 256 characters (via stubbed parse)', () =>
|
|
476
|
-
const alice =
|
|
477
|
-
const { message } =
|
|
465
|
+
});
|
|
466
|
+
it('returns 500 for prefix exceeding 256 characters (via stubbed parse)', async () => {
|
|
467
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
468
|
+
const { message } = await MessagesSync.create({
|
|
478
469
|
signer: Jws.createSigner(alice),
|
|
479
470
|
action: 'subtree',
|
|
480
471
|
prefix: '0',
|
|
@@ -489,39 +480,39 @@ export function testMessagesSyncHandler() {
|
|
|
489
480
|
// Override prefix to be too long
|
|
490
481
|
message.descriptor.prefix = '0'.repeat(257);
|
|
491
482
|
const handler = new MessagesSyncHandler(didResolver, messageStore, stateIndex);
|
|
492
|
-
const reply =
|
|
483
|
+
const reply = await handler.handle({ tenant: alice.did, message });
|
|
493
484
|
expect(reply.status.code).toBe(500);
|
|
494
485
|
expect(reply.status.detail).toContain('MessagesSyncInvalidPrefix');
|
|
495
486
|
}
|
|
496
487
|
finally {
|
|
497
488
|
parseStub.restore();
|
|
498
489
|
}
|
|
499
|
-
})
|
|
490
|
+
});
|
|
500
491
|
});
|
|
501
492
|
describe('error handling', () => {
|
|
502
|
-
it('returns 500 when stateIndex throws an unexpected error', () =>
|
|
503
|
-
const alice =
|
|
493
|
+
it('returns 500 when stateIndex throws an unexpected error', async () => {
|
|
494
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
504
495
|
const failingStateIndex = {
|
|
505
|
-
open: () =>
|
|
506
|
-
close: () =>
|
|
507
|
-
clear: () =>
|
|
508
|
-
insert: () =>
|
|
509
|
-
delete: () =>
|
|
510
|
-
getRoot: () =>
|
|
511
|
-
getProtocolRoot: () =>
|
|
512
|
-
getSubtreeHash: () =>
|
|
513
|
-
getProtocolSubtreeHash: () =>
|
|
514
|
-
getLeaves: () =>
|
|
515
|
-
getProtocolLeaves: () =>
|
|
496
|
+
open: async () => { },
|
|
497
|
+
close: async () => { },
|
|
498
|
+
clear: async () => { },
|
|
499
|
+
insert: async () => { },
|
|
500
|
+
delete: async () => { },
|
|
501
|
+
getRoot: async () => { throw new Error('Unexpected DB failure'); },
|
|
502
|
+
getProtocolRoot: async () => { throw new Error('Unexpected DB failure'); },
|
|
503
|
+
getSubtreeHash: async () => { throw new Error('Unexpected DB failure'); },
|
|
504
|
+
getProtocolSubtreeHash: async () => { throw new Error('Unexpected DB failure'); },
|
|
505
|
+
getLeaves: async () => { throw new Error('Unexpected DB failure'); },
|
|
506
|
+
getProtocolLeaves: async () => { throw new Error('Unexpected DB failure'); },
|
|
516
507
|
};
|
|
517
508
|
const handler = new MessagesSyncHandler(didResolver, messageStore, failingStateIndex);
|
|
518
|
-
const { message } =
|
|
509
|
+
const { message } = await MessagesSync.create({
|
|
519
510
|
signer: Jws.createSigner(alice),
|
|
520
511
|
action: 'root',
|
|
521
512
|
});
|
|
522
|
-
const reply =
|
|
513
|
+
const reply = await handler.handle({ tenant: alice.did, message });
|
|
523
514
|
expect(reply.status.code).toBe(500);
|
|
524
|
-
})
|
|
515
|
+
});
|
|
525
516
|
});
|
|
526
517
|
});
|
|
527
518
|
}
|