@enbox/dwn-sdk-js 0.0.2 → 0.0.4
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/README.md +52 -301
- package/dist/bundles/dwn.js +19 -21
- package/dist/esm/generated/precompiled-validators.js +2764 -1773
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +27 -3
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +17 -6
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +245 -69
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +4 -4
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/dwn.js +10 -8
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/enums/dwn-interface-method.js +4 -2
- package/dist/esm/src/enums/dwn-interface-method.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +1 -0
- package/dist/esm/src/handlers/messages-subscribe.js +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +116 -0
- package/dist/esm/src/handlers/messages-sync.js.map +1 -0
- package/dist/esm/src/handlers/protocols-configure.js +149 -16
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +2 -2
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +143 -0
- package/dist/esm/src/handlers/records-count.js.map +1 -0
- package/dist/esm/src/handlers/records-query.js +4 -0
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +4 -6
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +17 -18
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +9 -5
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +2 -7
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +1 -0
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/{messages-query.js → messages-sync.js} +11 -12
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-configure.js +153 -30
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +1 -0
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +91 -0
- package/dist/esm/src/interfaces/records-count.js.map +1 -0
- package/dist/esm/src/interfaces/records-read.js +15 -1
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +64 -15
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +30 -0
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +24 -0
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +1 -1
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/schema-validator.js +0 -1
- package/dist/esm/src/schema-validator.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +125 -0
- package/dist/esm/src/smt/smt-store-level.js.map +1 -0
- package/dist/esm/src/smt/smt-store-memory.js +67 -0
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -0
- package/dist/esm/src/smt/smt-utils.js +146 -0
- package/dist/esm/src/smt/smt-utils.js.map +1 -0
- package/dist/esm/src/smt/sparse-merkle-tree.js +622 -0
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -0
- package/dist/esm/src/state-index/state-index-level.js +228 -0
- package/dist/esm/src/state-index/state-index-level.js.map +1 -0
- package/dist/esm/src/store/data-store-level.js +6 -6
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level.js +375 -17
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +56 -0
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +19 -16
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/encryption-types.js +2 -0
- package/dist/esm/src/types/encryption-types.js.map +1 -0
- package/dist/esm/src/types/message-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +0 -2
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js +2 -0
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/types/smt-types.js +5 -0
- package/dist/esm/src/types/smt-types.js.map +1 -0
- package/dist/esm/src/types/state-index.js +2 -0
- package/dist/esm/src/types/state-index.js.map +1 -0
- package/dist/esm/src/utils/cid.js +2 -1
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +84 -29
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +22 -31
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +3 -3
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +4 -4
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +4 -3
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +82 -9
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +82 -26
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +4 -3
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +3 -2
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +1 -1
- package/dist/esm/src/utils/url.js +1 -1
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +2 -2
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message-reply.spec.js +3 -3
- package/dist/esm/tests/core/message-reply.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +13 -13
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +3 -3
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +27 -37
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/{event-log → event-stream}/event-emitter-stream.spec.js +14 -15
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +1 -0
- package/dist/esm/tests/{event-log → event-stream}/event-stream.spec.js +13 -15
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +281 -135
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +57 -59
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +32 -34
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +73 -95
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +1645 -0
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-create-action.spec.js +25 -27
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +42 -44
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +53 -55
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +126 -100
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +272 -272
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +35 -37
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +112 -112
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +78 -76
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +528 -0
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js +545 -152
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +70 -72
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +313 -0
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-delete.spec.js +106 -109
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +863 -463
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +439 -209
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +292 -97
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +481 -483
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +31 -11
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +5 -5
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +64 -134
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +4 -6
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +3 -5
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +9 -11
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +76 -7
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +7 -9
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +244 -48
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +15 -18
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +114 -0
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -0
- package/dist/esm/tests/protocols/permission-request.spec.js +43 -7
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +9 -11
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +90 -92
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +17 -19
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +27 -29
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +37 -39
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +163 -163
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +143 -0
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -0
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +741 -0
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -0
- package/dist/esm/tests/state-index/state-index-level.spec.js +254 -0
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -0
- package/dist/esm/tests/store/blockstore-level.spec.js +136 -0
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -0
- package/dist/esm/tests/store/blockstore-mock.spec.js +29 -28
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +23 -25
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +544 -194
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +4 -4
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +147 -73
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/store-dependent-tests.spec.js +1 -0
- package/dist/esm/tests/store-dependent-tests.spec.js.map +1 -1
- package/dist/esm/tests/test-stores.js +5 -5
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +9 -8
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +8 -11
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +167 -13
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +233 -0
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -0
- package/dist/esm/tests/utils/encryption.spec.js +34 -85
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +67 -69
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +3 -3
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +54 -3
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +6 -9
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +63 -29
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/object.spec.js +3 -3
- package/dist/esm/tests/utils/object.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +1 -1
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +6 -6
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +37 -5
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +7 -7
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +7 -7
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +47 -28
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/utils/time.spec.js +7 -7
- package/dist/esm/tests/utils/time.spec.js.map +1 -1
- package/dist/esm/tests/utils/url.spec.js +25 -27
- package/dist/esm/tests/utils/url.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +4 -4
- 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 +15 -3
- 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 -8
- 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 +8 -18
- 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 +3 -3
- 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 +9 -9
- 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 +106 -0
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +18 -18
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/esm/tests/vectors/protocol-definitions/email.json +1 -1
- package/dist/esm/tests/vectors/protocol-definitions/friend-role.json +2 -4
- package/dist/esm/tests/vectors/protocol-definitions/slack.json +2 -6
- package/dist/esm/tests/vectors/protocol-definitions/thread-role.json +2 -6
- package/dist/types/generated/precompiled-validators.d.ts +82 -64
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +27 -3
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/message-reply.d.ts +1 -1
- package/dist/types/src/core/message.d.ts +3 -3
- package/dist/types/src/core/message.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +4 -4
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +43 -2
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/records-grant-authorization.d.ts +2 -2
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts +1 -0
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +8 -8
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/enums/dwn-interface-method.d.ts +5 -3
- package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-sync.d.ts +21 -0
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -0
- package/dist/types/src/handlers/protocols-configure.d.ts +24 -4
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +43 -0
- package/dist/types/src/handlers/records-count.d.ts.map +1 -0
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +5 -5
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +72 -37
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-read.d.ts +2 -2
- package/dist/types/src/interfaces/messages-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +2 -2
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-sync.d.ts +16 -0
- package/dist/types/src/interfaces/messages-sync.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts +22 -2
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-query.d.ts +2 -2
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-count.d.ts +27 -0
- package/dist/types/src/interfaces/records-count.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-delete.d.ts +2 -2
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-query.d.ts +2 -2
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-read.d.ts +4 -2
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +2 -2
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +37 -15
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts.map +1 -1
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts +5 -1
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts.map +1 -1
- package/dist/types/src/jose/jws/general/builder.d.ts +3 -3
- package/dist/types/src/jose/jws/general/builder.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +11 -0
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +11 -0
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +4 -4
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/schema-validator.d.ts +1 -1
- package/dist/types/src/schema-validator.d.ts.map +1 -1
- package/dist/types/src/smt/smt-store-level.d.ts +32 -0
- package/dist/types/src/smt/smt-store-level.d.ts.map +1 -0
- package/dist/types/src/smt/smt-store-memory.d.ts +22 -0
- package/dist/types/src/smt/smt-store-memory.d.ts.map +1 -0
- package/dist/types/src/smt/smt-utils.d.ts +58 -0
- package/dist/types/src/smt/smt-utils.d.ts.map +1 -0
- package/dist/types/src/smt/sparse-merkle-tree.d.ts +124 -0
- package/dist/types/src/smt/sparse-merkle-tree.d.ts.map +1 -0
- package/dist/types/src/state-index/state-index-level.d.ts +83 -0
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -0
- package/dist/types/src/store/data-store-level.d.ts +1 -2
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +98 -2
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -1
- package/dist/types/src/store/message-store-level.d.ts +5 -0
- package/dist/types/src/store/message-store-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +7 -7
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/data-store.d.ts +2 -3
- package/dist/types/src/types/data-store.d.ts.map +1 -1
- package/dist/types/src/types/encryption-types.d.ts +48 -0
- package/dist/types/src/types/encryption-types.d.ts.map +1 -0
- package/dist/types/src/types/jose-types.d.ts +9 -40
- package/dist/types/src/types/jose-types.d.ts.map +1 -1
- package/dist/types/src/types/message-store.d.ts +5 -0
- package/dist/types/src/types/message-store.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +19 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +16 -11
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +1 -2
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +2 -2
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +49 -5
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +23 -7
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/signer.d.ts +1 -1
- package/dist/types/src/types/signer.d.ts.map +1 -1
- package/dist/types/src/types/smt-types.d.ts +81 -0
- package/dist/types/src/types/smt-types.d.ts.map +1 -0
- package/dist/types/src/types/state-index.d.ts +90 -0
- package/dist/types/src/types/state-index.d.ts.map +1 -0
- package/dist/types/src/utils/cid.d.ts +1 -2
- package/dist/types/src/utils/cid.d.ts.map +1 -1
- package/dist/types/src/utils/data-stream.d.ts +14 -7
- package/dist/types/src/utils/data-stream.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +2 -3
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +4 -4
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/jws.d.ts +7 -7
- package/dist/types/src/utils/jws.d.ts.map +1 -1
- package/dist/types/src/utils/private-key-signer.d.ts +4 -4
- package/dist/types/src/utils/private-key-signer.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +46 -3
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +33 -6
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/secp256k1.d.ts +11 -11
- package/dist/types/src/utils/secp256k1.d.ts.map +1 -1
- package/dist/types/src/utils/secp256r1.d.ts +8 -8
- package/dist/types/src/utils/secp256r1.d.ts.map +1 -1
- package/dist/types/src/utils/time.d.ts +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts +5 -0
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/protocols/permission-grant.spec.d.ts +2 -0
- package/dist/types/tests/protocols/permission-grant.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -1
- package/dist/types/tests/smt/smt-store-level.spec.d.ts +2 -0
- package/dist/types/tests/smt/smt-store-level.spec.d.ts.map +1 -0
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts +2 -0
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts.map +1 -0
- package/dist/types/tests/state-index/state-index-level.spec.d.ts +2 -0
- package/dist/types/tests/state-index/state-index-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/blockstore-level.spec.d.ts +2 -0
- package/dist/types/tests/store/blockstore-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -1
- package/dist/types/tests/test-stores.d.ts +4 -4
- package/dist/types/tests/test-stores.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/encryption-callbacks.spec.d.ts +2 -0
- package/dist/types/tests/utils/encryption-callbacks.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts +31 -28
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/validation/json-schemas/records/records-read.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/records/records-read.spec.d.ts.map +1 -0
- package/package.json +27 -46
- package/src/core/dwn-error.ts +27 -3
- package/src/core/message-reply.ts +1 -1
- package/src/core/message.ts +5 -5
- package/src/core/messages-grant-authorization.ts +22 -8
- package/src/core/protocol-authorization.ts +345 -68
- package/src/core/records-grant-authorization.ts +2 -2
- package/src/core/resumable-task-manager.ts +4 -5
- package/src/dwn.ts +25 -20
- package/src/enums/dwn-interface-method.ts +5 -3
- package/src/handlers/messages-subscribe.ts +1 -1
- package/src/handlers/messages-sync.ts +129 -0
- package/src/handlers/protocols-configure.ts +195 -17
- package/src/handlers/protocols-query.ts +7 -5
- package/src/handlers/records-count.ts +184 -0
- package/src/handlers/records-query.ts +4 -0
- package/src/handlers/records-read.ts +4 -8
- package/src/handlers/records-write.ts +20 -21
- package/src/index.ts +74 -37
- package/src/interfaces/messages-read.ts +6 -5
- package/src/interfaces/messages-subscribe.ts +7 -6
- package/src/interfaces/messages-sync.ts +59 -0
- package/src/interfaces/protocols-configure.ts +211 -33
- package/src/interfaces/protocols-query.ts +7 -6
- package/src/interfaces/records-count.ts +106 -0
- package/src/interfaces/records-delete.ts +2 -2
- package/src/interfaces/records-query.ts +2 -2
- package/src/interfaces/records-read.ts +26 -3
- package/src/interfaces/records-subscribe.ts +2 -2
- package/src/interfaces/records-write.ts +115 -46
- package/src/jose/algorithms/signing/ed25519.ts +13 -12
- package/src/jose/algorithms/signing/signature-algorithms.ts +6 -1
- package/src/jose/jws/general/builder.ts +3 -3
- package/src/jose/jws/general/verifier.ts +3 -3
- package/src/protocols/permission-grant.ts +51 -0
- package/src/protocols/permission-request.ts +37 -0
- package/src/protocols/permissions.ts +5 -5
- package/src/schema-validator.ts +11 -3
- package/src/smt/smt-store-level.ts +143 -0
- package/src/smt/smt-store-memory.ts +53 -0
- package/src/smt/smt-utils.ts +149 -0
- package/src/smt/sparse-merkle-tree.ts +698 -0
- package/src/state-index/state-index-level.ts +241 -0
- package/src/store/data-store-level.ts +8 -7
- package/src/store/index-level.ts +415 -19
- package/src/store/level-wrapper.ts +1 -1
- package/src/store/message-store-level.ts +62 -0
- package/src/store/storage-controller.ts +21 -19
- package/src/types/data-store.ts +2 -4
- package/src/types/encryption-types.ts +52 -0
- package/src/types/jose-types.ts +10 -42
- package/src/types/message-store.ts +11 -0
- package/src/types/message-types.ts +21 -0
- package/src/types/messages-types.ts +21 -15
- package/src/types/method-handler.ts +1 -2
- package/src/types/permission-types.ts +2 -2
- package/src/types/protocols-types.ts +55 -6
- package/src/types/records-types.ts +26 -7
- package/src/types/signer.ts +1 -1
- package/src/types/smt-types.ts +95 -0
- package/src/types/state-index.ts +100 -0
- package/src/utils/cid.ts +3 -4
- package/src/utils/data-stream.ts +75 -38
- package/src/utils/encryption.ts +24 -39
- package/src/utils/hd-key.ts +6 -6
- package/src/utils/jws.ts +9 -9
- package/src/utils/private-key-signer.ts +9 -8
- package/src/utils/protocols.ts +132 -6
- package/src/utils/records.ts +118 -29
- package/src/utils/secp256k1.ts +23 -21
- package/src/utils/secp256r1.ts +17 -15
- package/src/utils/time.ts +1 -1
- package/src/utils/url.ts +1 -1
- package/dist/cjs/index.js +0 -36749
- package/dist/cjs/package.json +0 -1
- package/dist/esm/src/event-log/event-emitter-stream.js.map +0 -1
- package/dist/esm/src/event-log/event-log-level.js +0 -63
- package/dist/esm/src/event-log/event-log-level.js.map +0 -1
- package/dist/esm/src/handlers/messages-query.js +0 -71
- package/dist/esm/src/handlers/messages-query.js.map +0 -1
- package/dist/esm/src/interfaces/messages-query.js.map +0 -1
- package/dist/esm/src/types/event-log.js +0 -2
- package/dist/esm/src/types/event-log.js.map +0 -1
- package/dist/esm/tests/event-log/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-log/event-log-level.spec.js +0 -44
- package/dist/esm/tests/event-log/event-log-level.spec.js.map +0 -1
- package/dist/esm/tests/event-log/event-log.spec.js +0 -236
- package/dist/esm/tests/event-log/event-log.spec.js.map +0 -1
- package/dist/esm/tests/event-log/event-stream.spec.js.map +0 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +0 -349
- package/dist/esm/tests/handlers/messages-query.spec.js.map +0 -1
- package/dist/esm/tests/interfaces/messagess-query.spec.js +0 -127
- package/dist/esm/tests/interfaces/messagess-query.spec.js.map +0 -1
- package/dist/esm/tests/scenarios/messages-query.spec.js +0 -395
- package/dist/esm/tests/scenarios/messages-query.spec.js.map +0 -1
- package/dist/types/src/event-log/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/src/event-log/event-log-level.d.ts +0 -35
- package/dist/types/src/event-log/event-log-level.d.ts.map +0 -1
- package/dist/types/src/handlers/messages-query.d.ts +0 -17
- package/dist/types/src/handlers/messages-query.d.ts.map +0 -1
- package/dist/types/src/interfaces/messages-query.d.ts +0 -16
- package/dist/types/src/interfaces/messages-query.d.ts.map +0 -1
- package/dist/types/src/types/event-log.d.ts +0 -52
- package/dist/types/src/types/event-log.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-log-level.spec.d.ts +0 -2
- package/dist/types/tests/event-log/event-log-level.spec.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-log.spec.d.ts +0 -2
- package/dist/types/tests/event-log/event-log.spec.d.ts.map +0 -1
- package/dist/types/tests/event-log/event-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/handlers/messages-query.spec.d.ts +0 -2
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +0 -1
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts +0 -2
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts.map +0 -1
- package/dist/types/tests/scenarios/messages-query.spec.d.ts +0 -2
- package/dist/types/tests/scenarios/messages-query.spec.d.ts.map +0 -1
- package/src/event-log/event-log-level.ts +0 -72
- package/src/handlers/messages-query.ts +0 -67
- package/src/interfaces/messages-query.ts +0 -60
- package/src/types/event-log.ts +0 -52
- /package/dist/esm/src/{event-log → event-stream}/event-emitter-stream.js +0 -0
- /package/dist/types/src/{event-log → event-stream}/event-emitter-stream.d.ts +0 -0
- /package/dist/types/tests/{event-log → event-stream}/event-emitter-stream.spec.d.ts +0 -0
- /package/dist/types/tests/{event-log → event-stream}/event-stream.spec.d.ts +0 -0
- /package/src/{event-log → event-stream}/event-emitter-stream.ts +0 -0
|
@@ -7,18 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import friendRoleProtocolDefinition from '../vectors/protocol-definitions/friend-role.json' assert { type: 'json' };
|
|
16
|
-
import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' assert { type: 'json' };
|
|
17
|
-
import nestedProtocol from '../vectors/protocol-definitions/nested.json' assert { type: 'json' };
|
|
10
|
+
import chatProtocolDefinition from '../vectors/protocol-definitions/chat.json' with { type: 'json' };
|
|
11
|
+
import emailProtocolDefinition from '../vectors/protocol-definitions/email.json' with { type: 'json' };
|
|
12
|
+
import friendRoleProtocolDefinition from '../vectors/protocol-definitions/friend-role.json' with { type: 'json' };
|
|
13
|
+
import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' with { type: 'json' };
|
|
14
|
+
import nestedProtocol from '../vectors/protocol-definitions/nested.json' with { type: 'json' };
|
|
18
15
|
import sinon from 'sinon';
|
|
19
|
-
import socialMediaProtocolDefinition from '../vectors/protocol-definitions/social-media.json'
|
|
20
|
-
import threadRoleProtocolDefinition from '../vectors/protocol-definitions/thread-role.json'
|
|
21
|
-
import chai, { expect } from 'chai';
|
|
16
|
+
import socialMediaProtocolDefinition from '../vectors/protocol-definitions/social-media.json' with { type: 'json' };
|
|
17
|
+
import threadRoleProtocolDefinition from '../vectors/protocol-definitions/thread-role.json' with { type: 'json' };
|
|
22
18
|
import { ArrayUtility } from '../../src/utils/array.js';
|
|
23
19
|
import { authenticate } from '../../src/core/auth.js';
|
|
24
20
|
import { DwnErrorCode } from '../../src/core/dwn-error.js';
|
|
@@ -30,16 +26,18 @@ import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
|
30
26
|
import { TestEventStream } from '../test-event-stream.js';
|
|
31
27
|
import { TestStores } from '../test-stores.js';
|
|
32
28
|
import { TestStubGenerator } from '../utils/test-stub-generator.js';
|
|
33
|
-
import {
|
|
29
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
30
|
+
import { DataStoreLevel, DwnConstant, MessageStoreLevel, PermissionsProtocol, Time } from '../../src/index.js';
|
|
31
|
+
import { DataStream, DateSort, Dwn, Jws, Protocols, ProtocolsConfigure, ProtocolsQuery, Records, RecordsDelete, RecordsRead, RecordsWrite, Secp256k1 } from '../../src/index.js';
|
|
34
32
|
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
35
|
-
|
|
33
|
+
import { DwnInterfaceName, DwnMethodName } from '../../src/index.js';
|
|
36
34
|
export function testRecordsReadHandler() {
|
|
37
35
|
describe('RecordsReadHandler.handle()', () => {
|
|
38
36
|
let didResolver;
|
|
39
37
|
let messageStore;
|
|
40
38
|
let dataStore;
|
|
41
39
|
let resumableTaskStore;
|
|
42
|
-
let
|
|
40
|
+
let stateIndex;
|
|
43
41
|
let eventStream;
|
|
44
42
|
let dwn;
|
|
45
43
|
beforeEach(() => {
|
|
@@ -48,24 +46,24 @@ export function testRecordsReadHandler() {
|
|
|
48
46
|
describe('functional tests', () => {
|
|
49
47
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
50
48
|
// so that different test suites can reuse the same backend store for testing
|
|
51
|
-
|
|
49
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
52
50
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
53
51
|
const stores = TestStores.get();
|
|
54
52
|
messageStore = stores.messageStore;
|
|
55
53
|
dataStore = stores.dataStore;
|
|
56
54
|
resumableTaskStore = stores.resumableTaskStore;
|
|
57
|
-
|
|
55
|
+
stateIndex = stores.stateIndex;
|
|
58
56
|
eventStream = TestEventStream.get();
|
|
59
|
-
dwn = yield Dwn.create({ didResolver, messageStore, dataStore,
|
|
57
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
60
58
|
}));
|
|
61
59
|
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
62
60
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
63
61
|
yield messageStore.clear();
|
|
64
62
|
yield dataStore.clear();
|
|
65
63
|
yield resumableTaskStore.clear();
|
|
66
|
-
yield
|
|
64
|
+
yield stateIndex.clear();
|
|
67
65
|
}));
|
|
68
|
-
|
|
66
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
69
67
|
yield dwn.close();
|
|
70
68
|
}));
|
|
71
69
|
it('should allow tenant to RecordsRead their own record', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -74,7 +72,7 @@ export function testRecordsReadHandler() {
|
|
|
74
72
|
// insert data
|
|
75
73
|
const { message, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
76
74
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
77
|
-
expect(writeReply.status.code).
|
|
75
|
+
expect(writeReply.status.code).toBe(202);
|
|
78
76
|
// testing RecordsRead
|
|
79
77
|
const recordsRead = yield RecordsRead.create({
|
|
80
78
|
filter: {
|
|
@@ -83,19 +81,19 @@ export function testRecordsReadHandler() {
|
|
|
83
81
|
signer: Jws.createSigner(alice)
|
|
84
82
|
});
|
|
85
83
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
86
|
-
expect(readReply.status.code).
|
|
87
|
-
expect(readReply.entry.recordsWrite).
|
|
88
|
-
expect((_a = readReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.authorization).
|
|
89
|
-
expect((_b = readReply.entry.recordsWrite) === null || _b === void 0 ? void 0 : _b.descriptor).
|
|
84
|
+
expect(readReply.status.code).toBe(200);
|
|
85
|
+
expect(readReply.entry.recordsWrite).toBeDefined();
|
|
86
|
+
expect((_a = readReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.authorization).toEqual(message.authorization);
|
|
87
|
+
expect((_b = readReply.entry.recordsWrite) === null || _b === void 0 ? void 0 : _b.descriptor).toEqual(message.descriptor);
|
|
90
88
|
const dataFetched = yield DataStream.toBytes(readReply.entry.data);
|
|
91
|
-
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).
|
|
89
|
+
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).toBe(true);
|
|
92
90
|
}));
|
|
93
91
|
it('should not allow non-tenant to RecordsRead a record', () => __awaiter(this, void 0, void 0, function* () {
|
|
94
92
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
95
93
|
// insert data
|
|
96
94
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
97
95
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
98
|
-
expect(writeReply.status.code).
|
|
96
|
+
expect(writeReply.status.code).toBe(202);
|
|
99
97
|
// testing RecordsRead
|
|
100
98
|
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
101
99
|
const recordsRead = yield RecordsRead.create({
|
|
@@ -105,32 +103,32 @@ export function testRecordsReadHandler() {
|
|
|
105
103
|
signer: Jws.createSigner(bob)
|
|
106
104
|
});
|
|
107
105
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
108
|
-
expect(readReply.status.code).
|
|
106
|
+
expect(readReply.status.code).toBe(401);
|
|
109
107
|
}));
|
|
110
108
|
it('should allow reading of data that is published without `authorization`', () => __awaiter(this, void 0, void 0, function* () {
|
|
111
109
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
112
110
|
// insert public data
|
|
113
111
|
const { message, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: true });
|
|
114
112
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
115
|
-
expect(writeReply.status.code).
|
|
113
|
+
expect(writeReply.status.code).toBe(202);
|
|
116
114
|
// testing public RecordsRead
|
|
117
115
|
const recordsRead = yield RecordsRead.create({
|
|
118
116
|
filter: {
|
|
119
117
|
recordId: message.recordId
|
|
120
118
|
}
|
|
121
119
|
});
|
|
122
|
-
expect(recordsRead.author).
|
|
120
|
+
expect(recordsRead.author).toBeUndefined(); // making sure no author/authorization is created
|
|
123
121
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
124
|
-
expect(readReply.status.code).
|
|
122
|
+
expect(readReply.status.code).toBe(200);
|
|
125
123
|
const dataFetched = yield DataStream.toBytes(readReply.entry.data);
|
|
126
|
-
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).
|
|
124
|
+
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).toBe(true);
|
|
127
125
|
}));
|
|
128
126
|
it('should allow an authenticated user to RecordRead data that is published', () => __awaiter(this, void 0, void 0, function* () {
|
|
129
127
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
130
128
|
// insert public data
|
|
131
129
|
const { message, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: true });
|
|
132
130
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
133
|
-
expect(writeReply.status.code).
|
|
131
|
+
expect(writeReply.status.code).toBe(202);
|
|
134
132
|
// testing public RecordsRead
|
|
135
133
|
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
136
134
|
const recordsRead = yield RecordsRead.create({
|
|
@@ -140,9 +138,9 @@ export function testRecordsReadHandler() {
|
|
|
140
138
|
signer: Jws.createSigner(bob)
|
|
141
139
|
});
|
|
142
140
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
143
|
-
expect(readReply.status.code).
|
|
141
|
+
expect(readReply.status.code).toBe(200);
|
|
144
142
|
const dataFetched = yield DataStream.toBytes(readReply.entry.data);
|
|
145
|
-
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).
|
|
143
|
+
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).toBe(true);
|
|
146
144
|
}));
|
|
147
145
|
it('should allow a non-tenant to read RecordsRead data they have received', () => __awaiter(this, void 0, void 0, function* () {
|
|
148
146
|
var _a;
|
|
@@ -154,7 +152,7 @@ export function testRecordsReadHandler() {
|
|
|
154
152
|
recipient: bob.did,
|
|
155
153
|
});
|
|
156
154
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
157
|
-
expect(writeReply.status.code).
|
|
155
|
+
expect(writeReply.status.code).toBe(202);
|
|
158
156
|
// Bob reads the data that Alice sent him
|
|
159
157
|
const recordsRead = yield RecordsRead.create({
|
|
160
158
|
filter: {
|
|
@@ -163,25 +161,25 @@ export function testRecordsReadHandler() {
|
|
|
163
161
|
signer: Jws.createSigner(bob)
|
|
164
162
|
});
|
|
165
163
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
166
|
-
expect(readReply.status.code).
|
|
167
|
-
expect(readReply.entry.recordsWrite).
|
|
168
|
-
expect((_a = readReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor).
|
|
164
|
+
expect(readReply.status.code).toBe(200);
|
|
165
|
+
expect(readReply.entry.recordsWrite).toBeDefined();
|
|
166
|
+
expect((_a = readReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor).toBeDefined();
|
|
169
167
|
const dataFetched = yield DataStream.toBytes(readReply.entry.data);
|
|
170
|
-
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).
|
|
168
|
+
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).toBe(true);
|
|
171
169
|
}));
|
|
172
170
|
it('should return 400 when fetching initial write for a deleted record fails', () => __awaiter(this, void 0, void 0, function* () {
|
|
173
171
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
174
172
|
// Write a record
|
|
175
173
|
const { message: writeMessage, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
176
174
|
const writeReply = yield dwn.processMessage(alice.did, writeMessage, { dataStream });
|
|
177
|
-
expect(writeReply.status.code).
|
|
175
|
+
expect(writeReply.status.code).toBe(202);
|
|
178
176
|
// Delete the record
|
|
179
177
|
const recordsDelete = yield RecordsDelete.create({
|
|
180
178
|
signer: Jws.createSigner(alice),
|
|
181
179
|
recordId: writeMessage.recordId
|
|
182
180
|
});
|
|
183
181
|
const deleteReply = yield dwn.processMessage(alice.did, recordsDelete.message);
|
|
184
|
-
expect(deleteReply.status.code).
|
|
182
|
+
expect(deleteReply.status.code).toBe(202);
|
|
185
183
|
// Stub the messageStore.query method to simulate failure in fetching initial write
|
|
186
184
|
const queryStub = sinon.stub(dwn['messageStore'], 'query');
|
|
187
185
|
queryStub.onFirstCall().resolves({ messages: [recordsDelete.message] });
|
|
@@ -193,8 +191,8 @@ export function testRecordsReadHandler() {
|
|
|
193
191
|
});
|
|
194
192
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
195
193
|
// Verify the response
|
|
196
|
-
expect(readReply.status.code).
|
|
197
|
-
expect(readReply.status.detail).
|
|
194
|
+
expect(readReply.status.code).toBe(400);
|
|
195
|
+
expect(readReply.status.detail).toContain(DwnErrorCode.RecordsReadInitialWriteNotFound);
|
|
198
196
|
// Restore the original messageStore.query method
|
|
199
197
|
queryStub.restore();
|
|
200
198
|
}));
|
|
@@ -223,7 +221,7 @@ export function testRecordsReadHandler() {
|
|
|
223
221
|
protocolDefinition: protocolDefinition,
|
|
224
222
|
});
|
|
225
223
|
const configureProtocolReply = yield dwn.processMessage(alice.did, configureProtocol.message);
|
|
226
|
-
expect(configureProtocolReply.status.code).
|
|
224
|
+
expect(configureProtocolReply.status.code).toBe(202);
|
|
227
225
|
// Bob writes a record to Alice's DWN
|
|
228
226
|
const { message: writeMessage, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
229
227
|
author: bob,
|
|
@@ -231,14 +229,14 @@ export function testRecordsReadHandler() {
|
|
|
231
229
|
protocolPath: 'foo'
|
|
232
230
|
});
|
|
233
231
|
const writeReply = yield dwn.processMessage(alice.did, writeMessage, { dataStream });
|
|
234
|
-
expect(writeReply.status.code).
|
|
232
|
+
expect(writeReply.status.code).toBe(202);
|
|
235
233
|
// Bob deletes the record
|
|
236
234
|
const recordsDelete = yield RecordsDelete.create({
|
|
237
235
|
signer: Jws.createSigner(bob),
|
|
238
236
|
recordId: writeMessage.recordId
|
|
239
237
|
});
|
|
240
238
|
const deleteReply = yield dwn.processMessage(alice.did, recordsDelete.message);
|
|
241
|
-
expect(deleteReply.status.code).
|
|
239
|
+
expect(deleteReply.status.code).toBe(202);
|
|
242
240
|
// Carol attempts to read the deleted record
|
|
243
241
|
const recordsRead = yield RecordsRead.create({
|
|
244
242
|
filter: { recordId: writeMessage.recordId },
|
|
@@ -246,8 +244,8 @@ export function testRecordsReadHandler() {
|
|
|
246
244
|
});
|
|
247
245
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
248
246
|
// Verify the response
|
|
249
|
-
expect(readReply.status.code).
|
|
250
|
-
expect(readReply.status.detail).
|
|
247
|
+
expect(readReply.status.code).toBe(401);
|
|
248
|
+
expect(readReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
251
249
|
}));
|
|
252
250
|
it('should allow a non-tenant to read RecordsRead data they have authored', () => __awaiter(this, void 0, void 0, function* () {
|
|
253
251
|
var _a;
|
|
@@ -275,7 +273,7 @@ export function testRecordsReadHandler() {
|
|
|
275
273
|
protocolDefinition: protocolDefinition,
|
|
276
274
|
});
|
|
277
275
|
const configureProtocolReply = yield dwn.processMessage(alice.did, configureProtocol.message);
|
|
278
|
-
expect(configureProtocolReply.status.code).
|
|
276
|
+
expect(configureProtocolReply.status.code).toBe(202);
|
|
279
277
|
// Bob writes a foo record to Alice's DWN
|
|
280
278
|
const { message, dataStream, dataBytes } = yield TestDataGenerator.generateRecordsWrite({
|
|
281
279
|
author: bob,
|
|
@@ -283,7 +281,7 @@ export function testRecordsReadHandler() {
|
|
|
283
281
|
protocolPath: 'foo',
|
|
284
282
|
});
|
|
285
283
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
286
|
-
expect(writeReply.status.code).
|
|
284
|
+
expect(writeReply.status.code).toBe(202);
|
|
287
285
|
// Bob reads the record he sent to Alice from Alice's DWN
|
|
288
286
|
const recordsRead = yield RecordsRead.create({
|
|
289
287
|
filter: {
|
|
@@ -292,11 +290,11 @@ export function testRecordsReadHandler() {
|
|
|
292
290
|
signer: Jws.createSigner(bob)
|
|
293
291
|
});
|
|
294
292
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
295
|
-
expect(readReply.status.code).
|
|
296
|
-
expect(readReply.entry.recordsWrite).
|
|
297
|
-
expect((_a = readReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor).
|
|
293
|
+
expect(readReply.status.code).toBe(200);
|
|
294
|
+
expect(readReply.entry.recordsWrite).toBeDefined();
|
|
295
|
+
expect((_a = readReply.entry.recordsWrite) === null || _a === void 0 ? void 0 : _a.descriptor).toBeDefined();
|
|
298
296
|
const dataFetched = yield DataStream.toBytes(readReply.entry.data);
|
|
299
|
-
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).
|
|
297
|
+
expect(ArrayUtility.byteArraysEqual(dataFetched, dataBytes)).toBe(true);
|
|
300
298
|
// carol attempts to read Bob's record
|
|
301
299
|
const carolRecordsRead = yield RecordsRead.create({
|
|
302
300
|
filter: {
|
|
@@ -305,24 +303,24 @@ export function testRecordsReadHandler() {
|
|
|
305
303
|
signer: Jws.createSigner(carol)
|
|
306
304
|
});
|
|
307
305
|
const carolReadReply = yield dwn.processMessage(alice.did, carolRecordsRead.message);
|
|
308
|
-
expect(carolReadReply.status.code).
|
|
306
|
+
expect(carolReadReply.status.code).toBe(401);
|
|
309
307
|
}));
|
|
310
308
|
it('should include `initialWrite` property if RecordsWrite is not initial write', () => __awaiter(this, void 0, void 0, function* () {
|
|
311
309
|
var _a;
|
|
312
310
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
313
311
|
const write = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: false });
|
|
314
312
|
const writeReply = yield dwn.processMessage(alice.did, write.message, { dataStream: write.dataStream });
|
|
315
|
-
expect(writeReply.status.code).
|
|
313
|
+
expect(writeReply.status.code).toBe(202);
|
|
316
314
|
// write an update to the record
|
|
317
315
|
const write2 = yield RecordsWrite.createFrom({ recordsWriteMessage: write.message, published: true, signer: Jws.createSigner(alice) });
|
|
318
316
|
const write2Reply = yield dwn.processMessage(alice.did, write2.message);
|
|
319
|
-
expect(write2Reply.status.code).
|
|
317
|
+
expect(write2Reply.status.code).toBe(202);
|
|
320
318
|
// make sure result returned now has `initialWrite` property
|
|
321
319
|
const messageData = yield RecordsRead.create({ filter: { recordId: write.message.recordId }, signer: Jws.createSigner(alice) });
|
|
322
320
|
const reply = yield dwn.processMessage(alice.did, messageData.message);
|
|
323
|
-
expect(reply.status.code).
|
|
324
|
-
expect(reply.entry.initialWrite).
|
|
325
|
-
expect((_a = reply.entry.initialWrite) === null || _a === void 0 ? void 0 : _a.recordId).
|
|
321
|
+
expect(reply.status.code).toBe(200);
|
|
322
|
+
expect(reply.entry.initialWrite).toBeDefined();
|
|
323
|
+
expect((_a = reply.entry.initialWrite) === null || _a === void 0 ? void 0 : _a.recordId).toBe(write.message.recordId);
|
|
326
324
|
}));
|
|
327
325
|
describe('protocol based reads', () => {
|
|
328
326
|
it('should allow read with allow-anyone rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -336,7 +334,7 @@ export function testRecordsReadHandler() {
|
|
|
336
334
|
protocolDefinition
|
|
337
335
|
});
|
|
338
336
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
339
|
-
expect(protocolsConfigureReply.status.code).
|
|
337
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
340
338
|
// Alice writes image to her DWN
|
|
341
339
|
const encodedImage = new TextEncoder().encode('cafe-aesthetic.jpg');
|
|
342
340
|
const imageRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -349,7 +347,7 @@ export function testRecordsReadHandler() {
|
|
|
349
347
|
recipient: alice.did
|
|
350
348
|
});
|
|
351
349
|
const imageReply = yield dwn.processMessage(alice.did, imageRecordsWrite.message, { dataStream: imageRecordsWrite.dataStream });
|
|
352
|
-
expect(imageReply.status.code).
|
|
350
|
+
expect(imageReply.status.code).toBe(202);
|
|
353
351
|
// Bob (anyone) reads the image that Alice wrote
|
|
354
352
|
const imageRecordsRead = yield RecordsRead.create({
|
|
355
353
|
filter: {
|
|
@@ -358,7 +356,7 @@ export function testRecordsReadHandler() {
|
|
|
358
356
|
signer: Jws.createSigner(bob)
|
|
359
357
|
});
|
|
360
358
|
const imageReadReply = yield dwn.processMessage(alice.did, imageRecordsRead.message);
|
|
361
|
-
expect(imageReadReply.status.code).
|
|
359
|
+
expect(imageReadReply.status.code).toBe(200);
|
|
362
360
|
}));
|
|
363
361
|
it('should not allow anonymous reads when there is no allow-anyone rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
364
362
|
// scenario: Alice's writes a record to a protocol. An anonymous read his Alice's DWN and is rejected
|
|
@@ -371,7 +369,7 @@ export function testRecordsReadHandler() {
|
|
|
371
369
|
protocolDefinition
|
|
372
370
|
});
|
|
373
371
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
374
|
-
expect(protocolsConfigureReply.status.code).
|
|
372
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
375
373
|
// Alice writes a message to the minimal protocol
|
|
376
374
|
const recordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
377
375
|
author: alice,
|
|
@@ -382,7 +380,7 @@ export function testRecordsReadHandler() {
|
|
|
382
380
|
data: new TextEncoder().encode('foo')
|
|
383
381
|
});
|
|
384
382
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream: recordsWrite.dataStream });
|
|
385
|
-
expect(recordsWriteReply.status.code).
|
|
383
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
386
384
|
// Anonymous tries and fails to read Alice's message
|
|
387
385
|
const recordsRead = yield RecordsRead.create({
|
|
388
386
|
filter: {
|
|
@@ -390,8 +388,8 @@ export function testRecordsReadHandler() {
|
|
|
390
388
|
}
|
|
391
389
|
});
|
|
392
390
|
const recordsReadReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
393
|
-
expect(recordsReadReply.status.code).
|
|
394
|
-
expect(recordsReadReply.status.detail).
|
|
391
|
+
expect(recordsReadReply.status.code).toBe(401);
|
|
392
|
+
expect(recordsReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
395
393
|
}));
|
|
396
394
|
describe('recipient rules', () => {
|
|
397
395
|
it('should allow read with ancestor recipient rule', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -407,7 +405,7 @@ export function testRecordsReadHandler() {
|
|
|
407
405
|
protocolDefinition,
|
|
408
406
|
});
|
|
409
407
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
410
|
-
expect(protocolsConfigureReply.status.code).
|
|
408
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
411
409
|
// Alice writes an email with Bob as recipient
|
|
412
410
|
const encodedEmail = new TextEncoder().encode('Dear Bob, hello!');
|
|
413
411
|
const emailRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -420,7 +418,7 @@ export function testRecordsReadHandler() {
|
|
|
420
418
|
recipient: bob.did
|
|
421
419
|
});
|
|
422
420
|
const imageReply = yield dwn.processMessage(alice.did, emailRecordsWrite.message, { dataStream: emailRecordsWrite.dataStream });
|
|
423
|
-
expect(imageReply.status.code).
|
|
421
|
+
expect(imageReply.status.code).toBe(202);
|
|
424
422
|
// Bob reads Alice's email
|
|
425
423
|
const bobRecordsRead = yield RecordsRead.create({
|
|
426
424
|
filter: {
|
|
@@ -429,7 +427,7 @@ export function testRecordsReadHandler() {
|
|
|
429
427
|
signer: Jws.createSigner(bob)
|
|
430
428
|
});
|
|
431
429
|
const bobReadReply = yield dwn.processMessage(alice.did, bobRecordsRead.message);
|
|
432
|
-
expect(bobReadReply.status.code).
|
|
430
|
+
expect(bobReadReply.status.code).toBe(200);
|
|
433
431
|
// ImposterBob is not able to read Alice's email
|
|
434
432
|
const imposterRecordsRead = yield RecordsRead.create({
|
|
435
433
|
filter: {
|
|
@@ -438,8 +436,8 @@ export function testRecordsReadHandler() {
|
|
|
438
436
|
signer: Jws.createSigner(imposterBob)
|
|
439
437
|
});
|
|
440
438
|
const imposterReadReply = yield dwn.processMessage(alice.did, imposterRecordsRead.message);
|
|
441
|
-
expect(imposterReadReply.status.code).
|
|
442
|
-
expect(imposterReadReply.status.detail).
|
|
439
|
+
expect(imposterReadReply.status.code).toBe(401);
|
|
440
|
+
expect(imposterReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
443
441
|
}));
|
|
444
442
|
});
|
|
445
443
|
describe('author action rules', () => {
|
|
@@ -456,7 +454,7 @@ export function testRecordsReadHandler() {
|
|
|
456
454
|
protocolDefinition
|
|
457
455
|
});
|
|
458
456
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
459
|
-
expect(protocolsConfigureReply.status.code).
|
|
457
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
460
458
|
// Alice writes an email with Bob as recipient
|
|
461
459
|
const encodedEmail = new TextEncoder().encode('Dear Alice, hello!');
|
|
462
460
|
const emailRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
@@ -469,7 +467,7 @@ export function testRecordsReadHandler() {
|
|
|
469
467
|
recipient: alice.did
|
|
470
468
|
});
|
|
471
469
|
const imageReply = yield dwn.processMessage(alice.did, emailRecordsWrite.message, { dataStream: emailRecordsWrite.dataStream });
|
|
472
|
-
expect(imageReply.status.code).
|
|
470
|
+
expect(imageReply.status.code).toBe(202);
|
|
473
471
|
// Bob reads the email he just sent
|
|
474
472
|
const bobRecordsRead = yield RecordsRead.create({
|
|
475
473
|
filter: {
|
|
@@ -478,7 +476,7 @@ export function testRecordsReadHandler() {
|
|
|
478
476
|
signer: Jws.createSigner(bob)
|
|
479
477
|
});
|
|
480
478
|
const bobReadReply = yield dwn.processMessage(alice.did, bobRecordsRead.message);
|
|
481
|
-
expect(bobReadReply.status.code).
|
|
479
|
+
expect(bobReadReply.status.code).toBe(200);
|
|
482
480
|
// ImposterBob is not able to read the email
|
|
483
481
|
const imposterRecordsRead = yield RecordsRead.create({
|
|
484
482
|
filter: {
|
|
@@ -487,8 +485,8 @@ export function testRecordsReadHandler() {
|
|
|
487
485
|
signer: Jws.createSigner(imposterBob)
|
|
488
486
|
});
|
|
489
487
|
const imposterReadReply = yield dwn.processMessage(alice.did, imposterRecordsRead.message);
|
|
490
|
-
expect(imposterReadReply.status.code).
|
|
491
|
-
expect(imposterReadReply.status.detail).
|
|
488
|
+
expect(imposterReadReply.status.code).toBe(401);
|
|
489
|
+
expect(imposterReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
492
490
|
}));
|
|
493
491
|
});
|
|
494
492
|
describe('filter based reads', () => {
|
|
@@ -500,7 +498,7 @@ export function testRecordsReadHandler() {
|
|
|
500
498
|
protocolDefinition
|
|
501
499
|
});
|
|
502
500
|
const protocolConfigReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
503
|
-
expect(protocolConfigReply.status.code).
|
|
501
|
+
expect(protocolConfigReply.status.code).toBe(202);
|
|
504
502
|
const foo1Write = yield TestDataGenerator.generateRecordsWrite({
|
|
505
503
|
author: alice,
|
|
506
504
|
protocol: protocolDefinition.protocol,
|
|
@@ -511,7 +509,7 @@ export function testRecordsReadHandler() {
|
|
|
511
509
|
recipient: alice.did
|
|
512
510
|
});
|
|
513
511
|
const foo1WriteReply = yield dwn.processMessage(alice.did, foo1Write.message, { dataStream: foo1Write.dataStream });
|
|
514
|
-
expect(foo1WriteReply.status.code).
|
|
512
|
+
expect(foo1WriteReply.status.code).toBe(202);
|
|
515
513
|
const fooPathRead = yield RecordsRead.create({
|
|
516
514
|
filter: {
|
|
517
515
|
protocol: protocolDefinition.protocol,
|
|
@@ -520,10 +518,10 @@ export function testRecordsReadHandler() {
|
|
|
520
518
|
signer: Jws.createSigner(alice),
|
|
521
519
|
});
|
|
522
520
|
const fooPathReply = yield dwn.processMessage(alice.did, fooPathRead.message);
|
|
523
|
-
expect(fooPathReply.status.code).
|
|
524
|
-
expect(fooPathReply.entry.recordsWrite.recordId).
|
|
521
|
+
expect(fooPathReply.status.code).toBe(200);
|
|
522
|
+
expect(fooPathReply.entry.recordsWrite.recordId).toBe(foo1Write.message.recordId);
|
|
525
523
|
}));
|
|
526
|
-
it('should
|
|
524
|
+
it('should return the most recently updated record when filter matches multiple results', () => __awaiter(this, void 0, void 0, function* () {
|
|
527
525
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
528
526
|
const protocolDefinition = Object.assign({}, nestedProtocol);
|
|
529
527
|
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
@@ -531,40 +529,272 @@ export function testRecordsReadHandler() {
|
|
|
531
529
|
protocolDefinition
|
|
532
530
|
});
|
|
533
531
|
const protocolConfigReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
534
|
-
expect(protocolConfigReply.status.code).
|
|
532
|
+
expect(protocolConfigReply.status.code).toBe(202);
|
|
535
533
|
const foo1Write = yield TestDataGenerator.generateRecordsWrite({
|
|
536
534
|
author: alice,
|
|
537
535
|
protocol: protocolDefinition.protocol,
|
|
538
536
|
protocolPath: 'foo',
|
|
539
537
|
schema: protocolDefinition.types.foo.schema,
|
|
540
538
|
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
541
|
-
data: new TextEncoder().encode('
|
|
539
|
+
data: new TextEncoder().encode('foo1'),
|
|
542
540
|
recipient: alice.did
|
|
543
541
|
});
|
|
544
542
|
const foo1WriteReply = yield dwn.processMessage(alice.did, foo1Write.message, { dataStream: foo1Write.dataStream });
|
|
545
|
-
expect(foo1WriteReply.status.code).
|
|
543
|
+
expect(foo1WriteReply.status.code).toBe(202);
|
|
544
|
+
yield Time.minimalSleep();
|
|
546
545
|
const foo2Write = yield TestDataGenerator.generateRecordsWrite({
|
|
547
546
|
author: alice,
|
|
548
547
|
protocol: protocolDefinition.protocol,
|
|
549
548
|
protocolPath: 'foo',
|
|
550
549
|
schema: protocolDefinition.types.foo.schema,
|
|
551
550
|
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
552
|
-
data: new TextEncoder().encode('
|
|
551
|
+
data: new TextEncoder().encode('foo2'),
|
|
552
|
+
recipient: alice.did
|
|
553
|
+
});
|
|
554
|
+
const foo2WriteReply = yield dwn.processMessage(alice.did, foo2Write.message, { dataStream: foo2Write.dataStream });
|
|
555
|
+
expect(foo2WriteReply.status.code).toBe(202);
|
|
556
|
+
// default sort is updatedDescending, so the most recently updated record should be returned
|
|
557
|
+
const fooPathRead = yield RecordsRead.create({
|
|
558
|
+
filter: {
|
|
559
|
+
protocol: protocolDefinition.protocol,
|
|
560
|
+
protocolPath: 'foo',
|
|
561
|
+
},
|
|
562
|
+
signer: Jws.createSigner(alice),
|
|
563
|
+
});
|
|
564
|
+
const fooPathReply = yield dwn.processMessage(alice.did, fooPathRead.message);
|
|
565
|
+
expect(fooPathReply.status.code).toBe(200);
|
|
566
|
+
expect(fooPathReply.entry.recordsWrite.recordId).toBe(foo2Write.message.recordId);
|
|
567
|
+
}));
|
|
568
|
+
it('should return the oldest record when `dateSort` is `CreatedAscending` and filter matches multiple results', () => __awaiter(this, void 0, void 0, function* () {
|
|
569
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
570
|
+
const protocolDefinition = Object.assign({}, nestedProtocol);
|
|
571
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
572
|
+
author: alice,
|
|
573
|
+
protocolDefinition
|
|
574
|
+
});
|
|
575
|
+
const protocolConfigReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
576
|
+
expect(protocolConfigReply.status.code).toBe(202);
|
|
577
|
+
const foo1Write = yield TestDataGenerator.generateRecordsWrite({
|
|
578
|
+
author: alice,
|
|
579
|
+
protocol: protocolDefinition.protocol,
|
|
580
|
+
protocolPath: 'foo',
|
|
581
|
+
schema: protocolDefinition.types.foo.schema,
|
|
582
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
583
|
+
data: new TextEncoder().encode('foo1'),
|
|
584
|
+
recipient: alice.did
|
|
585
|
+
});
|
|
586
|
+
const foo1WriteReply = yield dwn.processMessage(alice.did, foo1Write.message, { dataStream: foo1Write.dataStream });
|
|
587
|
+
expect(foo1WriteReply.status.code).toBe(202);
|
|
588
|
+
yield Time.minimalSleep();
|
|
589
|
+
const foo2Write = yield TestDataGenerator.generateRecordsWrite({
|
|
590
|
+
author: alice,
|
|
591
|
+
protocol: protocolDefinition.protocol,
|
|
592
|
+
protocolPath: 'foo',
|
|
593
|
+
schema: protocolDefinition.types.foo.schema,
|
|
594
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
595
|
+
data: new TextEncoder().encode('foo2'),
|
|
596
|
+
recipient: alice.did
|
|
597
|
+
});
|
|
598
|
+
const foo2WriteReply = yield dwn.processMessage(alice.did, foo2Write.message, { dataStream: foo2Write.dataStream });
|
|
599
|
+
expect(foo2WriteReply.status.code).toBe(202);
|
|
600
|
+
// with createdAscending sort, the oldest record should be returned
|
|
601
|
+
const fooPathRead = yield RecordsRead.create({
|
|
602
|
+
filter: {
|
|
603
|
+
protocol: protocolDefinition.protocol,
|
|
604
|
+
protocolPath: 'foo',
|
|
605
|
+
},
|
|
606
|
+
dateSort: DateSort.CreatedAscending,
|
|
607
|
+
signer: Jws.createSigner(alice),
|
|
608
|
+
});
|
|
609
|
+
const fooPathReply = yield dwn.processMessage(alice.did, fooPathRead.message);
|
|
610
|
+
expect(fooPathReply.status.code).toBe(200);
|
|
611
|
+
expect(fooPathReply.entry.recordsWrite.recordId).toBe(foo1Write.message.recordId);
|
|
612
|
+
}));
|
|
613
|
+
it('should return the newest record when `dateSort` is `CreatedDescending` and filter matches multiple results', () => __awaiter(this, void 0, void 0, function* () {
|
|
614
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
615
|
+
const protocolDefinition = Object.assign({}, nestedProtocol);
|
|
616
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
617
|
+
author: alice,
|
|
618
|
+
protocolDefinition
|
|
619
|
+
});
|
|
620
|
+
const protocolConfigReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
621
|
+
expect(protocolConfigReply.status.code).toBe(202);
|
|
622
|
+
const foo1Write = yield TestDataGenerator.generateRecordsWrite({
|
|
623
|
+
author: alice,
|
|
624
|
+
protocol: protocolDefinition.protocol,
|
|
625
|
+
protocolPath: 'foo',
|
|
626
|
+
schema: protocolDefinition.types.foo.schema,
|
|
627
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
628
|
+
data: new TextEncoder().encode('foo1'),
|
|
629
|
+
recipient: alice.did
|
|
630
|
+
});
|
|
631
|
+
const foo1WriteReply = yield dwn.processMessage(alice.did, foo1Write.message, { dataStream: foo1Write.dataStream });
|
|
632
|
+
expect(foo1WriteReply.status.code).toBe(202);
|
|
633
|
+
yield Time.minimalSleep();
|
|
634
|
+
const foo2Write = yield TestDataGenerator.generateRecordsWrite({
|
|
635
|
+
author: alice,
|
|
636
|
+
protocol: protocolDefinition.protocol,
|
|
637
|
+
protocolPath: 'foo',
|
|
638
|
+
schema: protocolDefinition.types.foo.schema,
|
|
639
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
640
|
+
data: new TextEncoder().encode('foo2'),
|
|
641
|
+
recipient: alice.did
|
|
642
|
+
});
|
|
643
|
+
const foo2WriteReply = yield dwn.processMessage(alice.did, foo2Write.message, { dataStream: foo2Write.dataStream });
|
|
644
|
+
expect(foo2WriteReply.status.code).toBe(202);
|
|
645
|
+
const fooPathRead = yield RecordsRead.create({
|
|
646
|
+
filter: {
|
|
647
|
+
protocol: protocolDefinition.protocol,
|
|
648
|
+
protocolPath: 'foo',
|
|
649
|
+
},
|
|
650
|
+
dateSort: DateSort.CreatedDescending,
|
|
651
|
+
signer: Jws.createSigner(alice),
|
|
652
|
+
});
|
|
653
|
+
const fooPathReply = yield dwn.processMessage(alice.did, fooPathRead.message);
|
|
654
|
+
expect(fooPathReply.status.code).toBe(200);
|
|
655
|
+
expect(fooPathReply.entry.recordsWrite.recordId).toBe(foo2Write.message.recordId);
|
|
656
|
+
}));
|
|
657
|
+
it('should return the oldest updated record when `dateSort` is `UpdatedAscending`', () => __awaiter(this, void 0, void 0, function* () {
|
|
658
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
659
|
+
const protocolDefinition = Object.assign({}, nestedProtocol);
|
|
660
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
661
|
+
author: alice,
|
|
662
|
+
protocolDefinition
|
|
663
|
+
});
|
|
664
|
+
const protocolConfigReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
665
|
+
expect(protocolConfigReply.status.code).toBe(202);
|
|
666
|
+
const foo1Write = yield TestDataGenerator.generateRecordsWrite({
|
|
667
|
+
author: alice,
|
|
668
|
+
protocol: protocolDefinition.protocol,
|
|
669
|
+
protocolPath: 'foo',
|
|
670
|
+
schema: protocolDefinition.types.foo.schema,
|
|
671
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
672
|
+
data: new TextEncoder().encode('foo1'),
|
|
673
|
+
recipient: alice.did
|
|
674
|
+
});
|
|
675
|
+
const foo1WriteReply = yield dwn.processMessage(alice.did, foo1Write.message, { dataStream: foo1Write.dataStream });
|
|
676
|
+
expect(foo1WriteReply.status.code).toBe(202);
|
|
677
|
+
yield Time.minimalSleep();
|
|
678
|
+
const foo2Write = yield TestDataGenerator.generateRecordsWrite({
|
|
679
|
+
author: alice,
|
|
680
|
+
protocol: protocolDefinition.protocol,
|
|
681
|
+
protocolPath: 'foo',
|
|
682
|
+
schema: protocolDefinition.types.foo.schema,
|
|
683
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
684
|
+
data: new TextEncoder().encode('foo2'),
|
|
685
|
+
recipient: alice.did
|
|
686
|
+
});
|
|
687
|
+
const foo2WriteReply = yield dwn.processMessage(alice.did, foo2Write.message, { dataStream: foo2Write.dataStream });
|
|
688
|
+
expect(foo2WriteReply.status.code).toBe(202);
|
|
689
|
+
const fooPathRead = yield RecordsRead.create({
|
|
690
|
+
filter: {
|
|
691
|
+
protocol: protocolDefinition.protocol,
|
|
692
|
+
protocolPath: 'foo',
|
|
693
|
+
},
|
|
694
|
+
dateSort: DateSort.UpdatedAscending,
|
|
695
|
+
signer: Jws.createSigner(alice),
|
|
696
|
+
});
|
|
697
|
+
const fooPathReply = yield dwn.processMessage(alice.did, fooPathRead.message);
|
|
698
|
+
expect(fooPathReply.status.code).toBe(200);
|
|
699
|
+
expect(fooPathReply.entry.recordsWrite.recordId).toBe(foo1Write.message.recordId);
|
|
700
|
+
}));
|
|
701
|
+
it('should return the most recently updated record when `dateSort` is `UpdatedDescending`', () => __awaiter(this, void 0, void 0, function* () {
|
|
702
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
703
|
+
const protocolDefinition = Object.assign({}, nestedProtocol);
|
|
704
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
705
|
+
author: alice,
|
|
706
|
+
protocolDefinition
|
|
707
|
+
});
|
|
708
|
+
const protocolConfigReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
709
|
+
expect(protocolConfigReply.status.code).toBe(202);
|
|
710
|
+
const foo1Write = yield TestDataGenerator.generateRecordsWrite({
|
|
711
|
+
author: alice,
|
|
712
|
+
protocol: protocolDefinition.protocol,
|
|
713
|
+
protocolPath: 'foo',
|
|
714
|
+
schema: protocolDefinition.types.foo.schema,
|
|
715
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
716
|
+
data: new TextEncoder().encode('foo1'),
|
|
717
|
+
recipient: alice.did
|
|
718
|
+
});
|
|
719
|
+
const foo1WriteReply = yield dwn.processMessage(alice.did, foo1Write.message, { dataStream: foo1Write.dataStream });
|
|
720
|
+
expect(foo1WriteReply.status.code).toBe(202);
|
|
721
|
+
yield Time.minimalSleep();
|
|
722
|
+
const foo2Write = yield TestDataGenerator.generateRecordsWrite({
|
|
723
|
+
author: alice,
|
|
724
|
+
protocol: protocolDefinition.protocol,
|
|
725
|
+
protocolPath: 'foo',
|
|
726
|
+
schema: protocolDefinition.types.foo.schema,
|
|
727
|
+
dataFormat: protocolDefinition.types.foo.dataFormats[0],
|
|
728
|
+
data: new TextEncoder().encode('foo2'),
|
|
553
729
|
recipient: alice.did
|
|
554
730
|
});
|
|
555
731
|
const foo2WriteReply = yield dwn.processMessage(alice.did, foo2Write.message, { dataStream: foo2Write.dataStream });
|
|
556
|
-
expect(foo2WriteReply.status.code).
|
|
557
|
-
// Since there are two 'foo' records, this should fail.
|
|
732
|
+
expect(foo2WriteReply.status.code).toBe(202);
|
|
558
733
|
const fooPathRead = yield RecordsRead.create({
|
|
559
734
|
filter: {
|
|
560
735
|
protocol: protocolDefinition.protocol,
|
|
561
736
|
protocolPath: 'foo',
|
|
562
737
|
},
|
|
738
|
+
dateSort: DateSort.UpdatedDescending,
|
|
563
739
|
signer: Jws.createSigner(alice),
|
|
564
740
|
});
|
|
565
741
|
const fooPathReply = yield dwn.processMessage(alice.did, fooPathRead.message);
|
|
566
|
-
expect(fooPathReply.status.code).
|
|
567
|
-
expect(fooPathReply.
|
|
742
|
+
expect(fooPathReply.status.code).toBe(200);
|
|
743
|
+
expect(fooPathReply.entry.recordsWrite.recordId).toBe(foo2Write.message.recordId);
|
|
744
|
+
}));
|
|
745
|
+
it('should return the earliest published record when `dateSort` is `PublishedAscending`', () => __awaiter(this, void 0, void 0, function* () {
|
|
746
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
747
|
+
const schema = 'aSchema';
|
|
748
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({
|
|
749
|
+
author: alice,
|
|
750
|
+
schema,
|
|
751
|
+
published: true,
|
|
752
|
+
});
|
|
753
|
+
const write1Reply = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
754
|
+
expect(write1Reply.status.code).toBe(202);
|
|
755
|
+
yield Time.minimalSleep();
|
|
756
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({
|
|
757
|
+
author: alice,
|
|
758
|
+
schema,
|
|
759
|
+
published: true,
|
|
760
|
+
});
|
|
761
|
+
const write2Reply = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
762
|
+
expect(write2Reply.status.code).toBe(202);
|
|
763
|
+
const read = yield RecordsRead.create({
|
|
764
|
+
filter: { schema },
|
|
765
|
+
dateSort: DateSort.PublishedAscending,
|
|
766
|
+
signer: Jws.createSigner(alice),
|
|
767
|
+
});
|
|
768
|
+
const readReply = yield dwn.processMessage(alice.did, read.message);
|
|
769
|
+
expect(readReply.status.code).toBe(200);
|
|
770
|
+
expect(readReply.entry.recordsWrite.recordId).toBe(write1.message.recordId);
|
|
771
|
+
}));
|
|
772
|
+
it('should return the latest published record when `dateSort` is `PublishedDescending`', () => __awaiter(this, void 0, void 0, function* () {
|
|
773
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
774
|
+
const schema = 'aSchema';
|
|
775
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({
|
|
776
|
+
author: alice,
|
|
777
|
+
schema,
|
|
778
|
+
published: true,
|
|
779
|
+
});
|
|
780
|
+
const write1Reply = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
781
|
+
expect(write1Reply.status.code).toBe(202);
|
|
782
|
+
yield Time.minimalSleep();
|
|
783
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({
|
|
784
|
+
author: alice,
|
|
785
|
+
schema,
|
|
786
|
+
published: true,
|
|
787
|
+
});
|
|
788
|
+
const write2Reply = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
789
|
+
expect(write2Reply.status.code).toBe(202);
|
|
790
|
+
const read = yield RecordsRead.create({
|
|
791
|
+
filter: { schema },
|
|
792
|
+
dateSort: DateSort.PublishedDescending,
|
|
793
|
+
signer: Jws.createSigner(alice),
|
|
794
|
+
});
|
|
795
|
+
const readReply = yield dwn.processMessage(alice.did, read.message);
|
|
796
|
+
expect(readReply.status.code).toBe(200);
|
|
797
|
+
expect(readReply.entry.recordsWrite.recordId).toBe(write2.message.recordId);
|
|
568
798
|
}));
|
|
569
799
|
});
|
|
570
800
|
describe('protocolRole based reads', () => {
|
|
@@ -579,7 +809,7 @@ export function testRecordsReadHandler() {
|
|
|
579
809
|
protocolDefinition
|
|
580
810
|
});
|
|
581
811
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
582
|
-
expect(protocolsConfigureReply.status.code).
|
|
812
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
583
813
|
// Alice writes a 'friend' root-level role record with Bob as recipient
|
|
584
814
|
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
585
815
|
author: alice,
|
|
@@ -589,7 +819,7 @@ export function testRecordsReadHandler() {
|
|
|
589
819
|
data: new TextEncoder().encode('Bob is my friend'),
|
|
590
820
|
});
|
|
591
821
|
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
592
|
-
expect(friendRoleReply.status.code).
|
|
822
|
+
expect(friendRoleReply.status.code).toBe(202);
|
|
593
823
|
// Alice writes a 'chat' record
|
|
594
824
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
595
825
|
author: alice,
|
|
@@ -599,7 +829,7 @@ export function testRecordsReadHandler() {
|
|
|
599
829
|
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
600
830
|
});
|
|
601
831
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
602
|
-
expect(chatReply.status.code).
|
|
832
|
+
expect(chatReply.status.code).toBe(202);
|
|
603
833
|
// Bob reads Alice's chat record
|
|
604
834
|
const readChatRecord = yield RecordsRead.create({
|
|
605
835
|
signer: Jws.createSigner(bob),
|
|
@@ -609,7 +839,7 @@ export function testRecordsReadHandler() {
|
|
|
609
839
|
protocolRole: 'friend'
|
|
610
840
|
});
|
|
611
841
|
const chatReadReply = yield dwn.processMessage(alice.did, readChatRecord.message);
|
|
612
|
-
expect(chatReadReply.status.code).
|
|
842
|
+
expect(chatReadReply.status.code).toBe(200);
|
|
613
843
|
}));
|
|
614
844
|
it('rejects root-level role authorized reads if the protocolRole is not a valid protocol path to an active role record', () => __awaiter(this, void 0, void 0, function* () {
|
|
615
845
|
// scenario: Alice writes a chat message writes a chat message. Bob tries to invoke the 'chat' role,
|
|
@@ -622,7 +852,7 @@ export function testRecordsReadHandler() {
|
|
|
622
852
|
protocolDefinition
|
|
623
853
|
});
|
|
624
854
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
625
|
-
expect(protocolsConfigureReply.status.code).
|
|
855
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
626
856
|
// Alice writes a 'chat' record
|
|
627
857
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
628
858
|
author: alice,
|
|
@@ -632,7 +862,7 @@ export function testRecordsReadHandler() {
|
|
|
632
862
|
data: new TextEncoder().encode('Blah blah blah'),
|
|
633
863
|
});
|
|
634
864
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
635
|
-
expect(chatReply.status.code).
|
|
865
|
+
expect(chatReply.status.code).toBe(202);
|
|
636
866
|
// Bob tries to invoke a 'chat' role but 'chat' is not a role
|
|
637
867
|
const readChatRecord = yield RecordsRead.create({
|
|
638
868
|
signer: Jws.createSigner(bob),
|
|
@@ -642,8 +872,8 @@ export function testRecordsReadHandler() {
|
|
|
642
872
|
protocolRole: 'chat'
|
|
643
873
|
});
|
|
644
874
|
const chatReadReply = yield dwn.processMessage(alice.did, readChatRecord.message);
|
|
645
|
-
expect(chatReadReply.status.code).
|
|
646
|
-
expect(chatReadReply.status.detail).
|
|
875
|
+
expect(chatReadReply.status.code).toBe(401);
|
|
876
|
+
expect(chatReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationNotARole);
|
|
647
877
|
}));
|
|
648
878
|
it('rejects root-level role authorized reads if there is no active role for the recipient', () => __awaiter(this, void 0, void 0, function* () {
|
|
649
879
|
// scenario: Alice writes a chat message writes a chat message. Bob tries to invoke a role,
|
|
@@ -656,7 +886,7 @@ export function testRecordsReadHandler() {
|
|
|
656
886
|
protocolDefinition
|
|
657
887
|
});
|
|
658
888
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
659
|
-
expect(protocolsConfigureReply.status.code).
|
|
889
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
660
890
|
// Alice writes a 'chat' record
|
|
661
891
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
662
892
|
author: alice,
|
|
@@ -666,7 +896,7 @@ export function testRecordsReadHandler() {
|
|
|
666
896
|
data: new TextEncoder().encode('Blah blah blah'),
|
|
667
897
|
});
|
|
668
898
|
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
669
|
-
expect(chatReply.status.code).
|
|
899
|
+
expect(chatReply.status.code).toBe(202);
|
|
670
900
|
// Bob tries to invoke a 'friend' role but he is not a 'friend'
|
|
671
901
|
const readChatRecord = yield RecordsRead.create({
|
|
672
902
|
signer: Jws.createSigner(bob),
|
|
@@ -676,8 +906,8 @@ export function testRecordsReadHandler() {
|
|
|
676
906
|
protocolRole: 'friend',
|
|
677
907
|
});
|
|
678
908
|
const chatReadReply = yield dwn.processMessage(alice.did, readChatRecord.message);
|
|
679
|
-
expect(chatReadReply.status.code).
|
|
680
|
-
expect(chatReadReply.status.detail).
|
|
909
|
+
expect(chatReadReply.status.code).toBe(401);
|
|
910
|
+
expect(chatReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound);
|
|
681
911
|
}));
|
|
682
912
|
it('can authorize a read using a context role', () => __awaiter(this, void 0, void 0, function* () {
|
|
683
913
|
// scenario: Alice creates a thread and adds Bob to the 'thread/participant' role. Alice writes a chat message.
|
|
@@ -690,7 +920,7 @@ export function testRecordsReadHandler() {
|
|
|
690
920
|
protocolDefinition
|
|
691
921
|
});
|
|
692
922
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
693
|
-
expect(protocolsConfigureReply.status.code).
|
|
923
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
694
924
|
// Alice creates a thread
|
|
695
925
|
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
696
926
|
author: alice,
|
|
@@ -698,7 +928,7 @@ export function testRecordsReadHandler() {
|
|
|
698
928
|
protocolPath: 'thread'
|
|
699
929
|
});
|
|
700
930
|
const threadRecordReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
701
|
-
expect(threadRecordReply.status.code).
|
|
931
|
+
expect(threadRecordReply.status.code).toBe(202);
|
|
702
932
|
// Alice adds Bob as a 'thread/participant' in that thread
|
|
703
933
|
const participantRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
704
934
|
author: alice,
|
|
@@ -708,7 +938,7 @@ export function testRecordsReadHandler() {
|
|
|
708
938
|
parentContextId: threadRecord.message.contextId,
|
|
709
939
|
});
|
|
710
940
|
const participantRecordReply = yield dwn.processMessage(alice.did, participantRecord.message, { dataStream: participantRecord.dataStream });
|
|
711
|
-
expect(participantRecordReply.status.code).
|
|
941
|
+
expect(participantRecordReply.status.code).toBe(202);
|
|
712
942
|
// Alice writes a chat message in the thread
|
|
713
943
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
714
944
|
author: alice,
|
|
@@ -717,7 +947,7 @@ export function testRecordsReadHandler() {
|
|
|
717
947
|
parentContextId: threadRecord.message.contextId,
|
|
718
948
|
});
|
|
719
949
|
const chatRecordReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
720
|
-
expect(chatRecordReply.status.code).
|
|
950
|
+
expect(chatRecordReply.status.code).toBe(202);
|
|
721
951
|
// Bob is able to read his own 'participant' role
|
|
722
952
|
// He doesn't need to invoke the role because recipients of a record are always authorized to read it
|
|
723
953
|
const participantRead = yield RecordsRead.create({
|
|
@@ -729,7 +959,7 @@ export function testRecordsReadHandler() {
|
|
|
729
959
|
},
|
|
730
960
|
});
|
|
731
961
|
const participantReadReply = yield dwn.processMessage(alice.did, participantRead.message);
|
|
732
|
-
expect(participantReadReply.status.code).
|
|
962
|
+
expect(participantReadReply.status.code).toBe(200);
|
|
733
963
|
// Bob is able to read the thread root record
|
|
734
964
|
const threadRead = yield RecordsRead.create({
|
|
735
965
|
signer: Jws.createSigner(bob),
|
|
@@ -739,7 +969,7 @@ export function testRecordsReadHandler() {
|
|
|
739
969
|
protocolRole: 'thread/participant'
|
|
740
970
|
});
|
|
741
971
|
const threadReadReply = yield dwn.processMessage(alice.did, threadRead.message);
|
|
742
|
-
expect(threadReadReply.status.code).
|
|
972
|
+
expect(threadReadReply.status.code).toBe(200);
|
|
743
973
|
// Bob invokes his 'participant' role to read the chat message
|
|
744
974
|
const chatRead = yield RecordsRead.create({
|
|
745
975
|
signer: Jws.createSigner(bob),
|
|
@@ -749,7 +979,7 @@ export function testRecordsReadHandler() {
|
|
|
749
979
|
protocolRole: 'thread/participant'
|
|
750
980
|
});
|
|
751
981
|
const chatReadReply = yield dwn.processMessage(alice.did, chatRead.message);
|
|
752
|
-
expect(chatReadReply.status.code).
|
|
982
|
+
expect(chatReadReply.status.code).toBe(200);
|
|
753
983
|
}));
|
|
754
984
|
it('should not allow context role to be invoked against a wrong context', () => __awaiter(this, void 0, void 0, function* () {
|
|
755
985
|
// scenario: Alice creates a thread and adds Bob as a participant. Alice creates another thread. Bob tries and fails to invoke his
|
|
@@ -762,7 +992,7 @@ export function testRecordsReadHandler() {
|
|
|
762
992
|
protocolDefinition
|
|
763
993
|
});
|
|
764
994
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
765
|
-
expect(protocolsConfigureReply.status.code).
|
|
995
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
766
996
|
// Alice creates a thread
|
|
767
997
|
const threadRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
768
998
|
author: alice,
|
|
@@ -771,7 +1001,7 @@ export function testRecordsReadHandler() {
|
|
|
771
1001
|
protocolPath: 'thread'
|
|
772
1002
|
});
|
|
773
1003
|
const threadRecordReply1 = yield dwn.processMessage(alice.did, threadRecord1.message, { dataStream: threadRecord1.dataStream });
|
|
774
|
-
expect(threadRecordReply1.status.code).
|
|
1004
|
+
expect(threadRecordReply1.status.code).toBe(202);
|
|
775
1005
|
// Alice adds Bob as a 'thread/participant' in that thread
|
|
776
1006
|
const participantRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
777
1007
|
author: alice,
|
|
@@ -781,7 +1011,7 @@ export function testRecordsReadHandler() {
|
|
|
781
1011
|
parentContextId: threadRecord1.message.contextId,
|
|
782
1012
|
});
|
|
783
1013
|
const participantRecordReply = yield dwn.processMessage(alice.did, participantRecord.message, { dataStream: participantRecord.dataStream });
|
|
784
|
-
expect(participantRecordReply.status.code).
|
|
1014
|
+
expect(participantRecordReply.status.code).toBe(202);
|
|
785
1015
|
// Alice creates a second thread
|
|
786
1016
|
const threadRecord2 = yield TestDataGenerator.generateRecordsWrite({
|
|
787
1017
|
author: alice,
|
|
@@ -790,7 +1020,7 @@ export function testRecordsReadHandler() {
|
|
|
790
1020
|
protocolPath: 'thread'
|
|
791
1021
|
});
|
|
792
1022
|
const threadRecordReply2 = yield dwn.processMessage(alice.did, threadRecord2.message, { dataStream: threadRecord2.dataStream });
|
|
793
|
-
expect(threadRecordReply2.status.code).
|
|
1023
|
+
expect(threadRecordReply2.status.code).toBe(202);
|
|
794
1024
|
// Alice writes a chat message in the thread
|
|
795
1025
|
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
796
1026
|
author: alice,
|
|
@@ -799,7 +1029,7 @@ export function testRecordsReadHandler() {
|
|
|
799
1029
|
parentContextId: threadRecord2.message.contextId,
|
|
800
1030
|
});
|
|
801
1031
|
const chatRecordReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
802
|
-
expect(chatRecordReply.status.code).
|
|
1032
|
+
expect(chatRecordReply.status.code).toBe(202);
|
|
803
1033
|
// Bob invokes his 'participant' role to read the chat message
|
|
804
1034
|
const chatRead = yield RecordsRead.create({
|
|
805
1035
|
signer: Jws.createSigner(bob),
|
|
@@ -809,8 +1039,8 @@ export function testRecordsReadHandler() {
|
|
|
809
1039
|
protocolRole: 'thread/participant'
|
|
810
1040
|
});
|
|
811
1041
|
const chatReadReply = yield dwn.processMessage(alice.did, chatRead.message);
|
|
812
|
-
expect(chatReadReply.status.code).
|
|
813
|
-
expect(chatReadReply.status.detail).
|
|
1042
|
+
expect(chatReadReply.status.code).toBe(401);
|
|
1043
|
+
expect(chatReadReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound);
|
|
814
1044
|
}));
|
|
815
1045
|
});
|
|
816
1046
|
});
|
|
@@ -824,7 +1054,7 @@ export function testRecordsReadHandler() {
|
|
|
824
1054
|
author: alice,
|
|
825
1055
|
});
|
|
826
1056
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
827
|
-
expect(recordsWriteReply.status.code).
|
|
1057
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
828
1058
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
829
1059
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
830
1060
|
signer: Jws.createSigner(alice),
|
|
@@ -838,7 +1068,7 @@ export function testRecordsReadHandler() {
|
|
|
838
1068
|
});
|
|
839
1069
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
840
1070
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
841
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1071
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
842
1072
|
// Bob tries to RecordsRead
|
|
843
1073
|
const recordsRead = yield RecordsRead.create({
|
|
844
1074
|
filter: {
|
|
@@ -848,8 +1078,8 @@ export function testRecordsReadHandler() {
|
|
|
848
1078
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
849
1079
|
});
|
|
850
1080
|
const recordsReadReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
851
|
-
expect(recordsReadReply.status.code).
|
|
852
|
-
expect(recordsReadReply.status.detail).
|
|
1081
|
+
expect(recordsReadReply.status.code).toBe(401);
|
|
1082
|
+
expect(recordsReadReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationMethodMismatch);
|
|
853
1083
|
}));
|
|
854
1084
|
describe('protocol records', () => {
|
|
855
1085
|
it('allows reads of protocol records with unrestricted grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -864,7 +1094,7 @@ export function testRecordsReadHandler() {
|
|
|
864
1094
|
protocolDefinition
|
|
865
1095
|
});
|
|
866
1096
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
867
|
-
expect(protocolsConfigureReply.status.code).
|
|
1097
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
868
1098
|
// Alice writes a record which Bob will later try to read
|
|
869
1099
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
870
1100
|
author: alice,
|
|
@@ -872,7 +1102,7 @@ export function testRecordsReadHandler() {
|
|
|
872
1102
|
protocolPath: 'foo',
|
|
873
1103
|
});
|
|
874
1104
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
875
|
-
expect(recordsWriteReply.status.code).
|
|
1105
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
876
1106
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
877
1107
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
878
1108
|
signer: Jws.createSigner(alice),
|
|
@@ -886,7 +1116,7 @@ export function testRecordsReadHandler() {
|
|
|
886
1116
|
});
|
|
887
1117
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
888
1118
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
889
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1119
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
890
1120
|
// Bob is unable to read the record without using the permission grant
|
|
891
1121
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
892
1122
|
filter: {
|
|
@@ -895,8 +1125,8 @@ export function testRecordsReadHandler() {
|
|
|
895
1125
|
signer: Jws.createSigner(bob),
|
|
896
1126
|
});
|
|
897
1127
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
898
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
899
|
-
expect(recordsReadWithoutGrantReply.status.detail).
|
|
1128
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(401);
|
|
1129
|
+
expect(recordsReadWithoutGrantReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionRulesNotFound);
|
|
900
1130
|
// Bob is able to read the record when he uses the permission grant
|
|
901
1131
|
const recordsReadWithGrant = yield RecordsRead.create({
|
|
902
1132
|
filter: {
|
|
@@ -906,7 +1136,7 @@ export function testRecordsReadHandler() {
|
|
|
906
1136
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
907
1137
|
});
|
|
908
1138
|
const recordsReadWithGrantReply = yield dwn.processMessage(alice.did, recordsReadWithGrant.message);
|
|
909
|
-
expect(recordsReadWithGrantReply.status.code).
|
|
1139
|
+
expect(recordsReadWithGrantReply.status.code).toBe(200);
|
|
910
1140
|
}));
|
|
911
1141
|
it('allows reads of protocol records with matching protocol grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
912
1142
|
// scenario: Alice writes a protocol record. Alice gives Bob a grant to read all records in the protocol
|
|
@@ -920,7 +1150,7 @@ export function testRecordsReadHandler() {
|
|
|
920
1150
|
protocolDefinition
|
|
921
1151
|
});
|
|
922
1152
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
923
|
-
expect(protocolsConfigureReply.status.code).
|
|
1153
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
924
1154
|
// Alice writes a record which Bob will later try to read
|
|
925
1155
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
926
1156
|
author: alice,
|
|
@@ -928,7 +1158,7 @@ export function testRecordsReadHandler() {
|
|
|
928
1158
|
protocolPath: 'foo',
|
|
929
1159
|
});
|
|
930
1160
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
931
|
-
expect(recordsWriteReply.status.code).
|
|
1161
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
932
1162
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
933
1163
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
934
1164
|
signer: Jws.createSigner(alice),
|
|
@@ -942,7 +1172,7 @@ export function testRecordsReadHandler() {
|
|
|
942
1172
|
});
|
|
943
1173
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
944
1174
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
945
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1175
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
946
1176
|
// Bob is unable to read the record without using the permission grant
|
|
947
1177
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
948
1178
|
filter: {
|
|
@@ -951,8 +1181,8 @@ export function testRecordsReadHandler() {
|
|
|
951
1181
|
signer: Jws.createSigner(bob),
|
|
952
1182
|
});
|
|
953
1183
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
954
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
955
|
-
expect(recordsReadWithoutGrantReply.status.detail).
|
|
1184
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(401);
|
|
1185
|
+
expect(recordsReadWithoutGrantReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionRulesNotFound);
|
|
956
1186
|
// Bob is able to read the record when he uses the permission grant
|
|
957
1187
|
const recordsReadWithGrant = yield RecordsRead.create({
|
|
958
1188
|
filter: {
|
|
@@ -962,7 +1192,7 @@ export function testRecordsReadHandler() {
|
|
|
962
1192
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
963
1193
|
});
|
|
964
1194
|
const recordsReadWithGrantReply = yield dwn.processMessage(alice.did, recordsReadWithGrant.message);
|
|
965
|
-
expect(recordsReadWithGrantReply.status.code).
|
|
1195
|
+
expect(recordsReadWithGrantReply.status.code).toBe(200);
|
|
966
1196
|
}));
|
|
967
1197
|
it('rejects reads of protocol records with mismatching protocol grant scopes', () => __awaiter(this, void 0, void 0, function* () {
|
|
968
1198
|
// scenario: Alice writes a protocol record. Alice gives Bob a grant to read a different protocol
|
|
@@ -976,7 +1206,7 @@ export function testRecordsReadHandler() {
|
|
|
976
1206
|
protocolDefinition
|
|
977
1207
|
});
|
|
978
1208
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
979
|
-
expect(protocolsConfigureReply.status.code).
|
|
1209
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
980
1210
|
// Alice writes a record which Bob will later try to read
|
|
981
1211
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
982
1212
|
author: alice,
|
|
@@ -984,7 +1214,7 @@ export function testRecordsReadHandler() {
|
|
|
984
1214
|
protocolPath: 'foo',
|
|
985
1215
|
});
|
|
986
1216
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
987
|
-
expect(recordsWriteReply.status.code).
|
|
1217
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
988
1218
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
989
1219
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
990
1220
|
signer: Jws.createSigner(alice),
|
|
@@ -998,7 +1228,7 @@ export function testRecordsReadHandler() {
|
|
|
998
1228
|
});
|
|
999
1229
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
1000
1230
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
1001
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1231
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
1002
1232
|
// Bob is unable to read the record using the mismatched permission grant
|
|
1003
1233
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
1004
1234
|
filter: {
|
|
@@ -1008,8 +1238,8 @@ export function testRecordsReadHandler() {
|
|
|
1008
1238
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
1009
1239
|
});
|
|
1010
1240
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
1011
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
1012
|
-
expect(recordsReadWithoutGrantReply.status.detail).
|
|
1241
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(401);
|
|
1242
|
+
expect(recordsReadWithoutGrantReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
|
|
1013
1243
|
}));
|
|
1014
1244
|
it('allows reads of records in the contextId specified in the grant', () => __awaiter(this, void 0, void 0, function* () {
|
|
1015
1245
|
// scenario: Alice grants Bob access to RecordsRead records with a specific contextId.
|
|
@@ -1023,7 +1253,7 @@ export function testRecordsReadHandler() {
|
|
|
1023
1253
|
protocolDefinition
|
|
1024
1254
|
});
|
|
1025
1255
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1026
|
-
expect(protocolsConfigureReply.status.code).
|
|
1256
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1027
1257
|
// Alice writes a record which Bob will later try to read
|
|
1028
1258
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
1029
1259
|
author: alice,
|
|
@@ -1031,7 +1261,7 @@ export function testRecordsReadHandler() {
|
|
|
1031
1261
|
protocolPath: 'foo',
|
|
1032
1262
|
});
|
|
1033
1263
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
1034
|
-
expect(recordsWriteReply.status.code).
|
|
1264
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
1035
1265
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
1036
1266
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
1037
1267
|
signer: Jws.createSigner(alice),
|
|
@@ -1046,7 +1276,7 @@ export function testRecordsReadHandler() {
|
|
|
1046
1276
|
});
|
|
1047
1277
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
1048
1278
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
1049
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1279
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
1050
1280
|
// Bob is unable to read the record using the mismatched permission grant
|
|
1051
1281
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
1052
1282
|
filter: {
|
|
@@ -1056,7 +1286,7 @@ export function testRecordsReadHandler() {
|
|
|
1056
1286
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
1057
1287
|
});
|
|
1058
1288
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
1059
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
1289
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(200);
|
|
1060
1290
|
}));
|
|
1061
1291
|
it('rejects reads of records in a different contextId than is specified in the grant', () => __awaiter(this, void 0, void 0, function* () {
|
|
1062
1292
|
// scenario: Alice grants Bob access to RecordsRead records with a specific contextId.
|
|
@@ -1070,7 +1300,7 @@ export function testRecordsReadHandler() {
|
|
|
1070
1300
|
protocolDefinition
|
|
1071
1301
|
});
|
|
1072
1302
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1073
|
-
expect(protocolsConfigureReply.status.code).
|
|
1303
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1074
1304
|
// Alice writes a record which Bob will later try to read
|
|
1075
1305
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
1076
1306
|
author: alice,
|
|
@@ -1078,7 +1308,7 @@ export function testRecordsReadHandler() {
|
|
|
1078
1308
|
protocolPath: 'foo',
|
|
1079
1309
|
});
|
|
1080
1310
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
1081
|
-
expect(recordsWriteReply.status.code).
|
|
1311
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
1082
1312
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
1083
1313
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
1084
1314
|
signer: Jws.createSigner(alice),
|
|
@@ -1093,7 +1323,7 @@ export function testRecordsReadHandler() {
|
|
|
1093
1323
|
});
|
|
1094
1324
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
1095
1325
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
1096
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1326
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
1097
1327
|
// Bob is unable to read the record using the mismatched permission grant
|
|
1098
1328
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
1099
1329
|
filter: {
|
|
@@ -1103,8 +1333,8 @@ export function testRecordsReadHandler() {
|
|
|
1103
1333
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
1104
1334
|
});
|
|
1105
1335
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
1106
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
1107
|
-
expect(recordsReadWithoutGrantReply.status.detail).
|
|
1336
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(401);
|
|
1337
|
+
expect(recordsReadWithoutGrantReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeContextIdMismatch);
|
|
1108
1338
|
}));
|
|
1109
1339
|
it('allows reads of records in the protocolPath specified in the grant', () => __awaiter(this, void 0, void 0, function* () {
|
|
1110
1340
|
// scenario: Alice grants Bob access to RecordsRead records with a specific protocolPath.
|
|
@@ -1118,7 +1348,7 @@ export function testRecordsReadHandler() {
|
|
|
1118
1348
|
protocolDefinition
|
|
1119
1349
|
});
|
|
1120
1350
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1121
|
-
expect(protocolsConfigureReply.status.code).
|
|
1351
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1122
1352
|
// Alice writes a record which Bob will later try to read
|
|
1123
1353
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
1124
1354
|
author: alice,
|
|
@@ -1126,7 +1356,7 @@ export function testRecordsReadHandler() {
|
|
|
1126
1356
|
protocolPath: 'foo',
|
|
1127
1357
|
});
|
|
1128
1358
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
1129
|
-
expect(recordsWriteReply.status.code).
|
|
1359
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
1130
1360
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
1131
1361
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
1132
1362
|
signer: Jws.createSigner(alice),
|
|
@@ -1141,7 +1371,7 @@ export function testRecordsReadHandler() {
|
|
|
1141
1371
|
});
|
|
1142
1372
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
1143
1373
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
1144
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1374
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
1145
1375
|
// Bob is unable to read the record using the mismatched permission grant
|
|
1146
1376
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
1147
1377
|
filter: {
|
|
@@ -1151,7 +1381,7 @@ export function testRecordsReadHandler() {
|
|
|
1151
1381
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
1152
1382
|
});
|
|
1153
1383
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
1154
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
1384
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(200);
|
|
1155
1385
|
}));
|
|
1156
1386
|
it('rejects reads of records in a different protocolPath than is specified in the grant', () => __awaiter(this, void 0, void 0, function* () {
|
|
1157
1387
|
// scenario: Alice grants Bob access to RecordsRead records with a specific protocolPath.
|
|
@@ -1165,7 +1395,7 @@ export function testRecordsReadHandler() {
|
|
|
1165
1395
|
protocolDefinition
|
|
1166
1396
|
});
|
|
1167
1397
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
1168
|
-
expect(protocolsConfigureReply.status.code).
|
|
1398
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1169
1399
|
// Alice writes a record which Bob will later try to read
|
|
1170
1400
|
const { recordsWrite, dataStream } = yield TestDataGenerator.generateRecordsWrite({
|
|
1171
1401
|
author: alice,
|
|
@@ -1173,7 +1403,7 @@ export function testRecordsReadHandler() {
|
|
|
1173
1403
|
protocolPath: 'foo',
|
|
1174
1404
|
});
|
|
1175
1405
|
const recordsWriteReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
1176
|
-
expect(recordsWriteReply.status.code).
|
|
1406
|
+
expect(recordsWriteReply.status.code).toBe(202);
|
|
1177
1407
|
// Alice gives Bob a permission grant with scope RecordsRead
|
|
1178
1408
|
const permissionGrant = yield PermissionsProtocol.createGrant({
|
|
1179
1409
|
signer: Jws.createSigner(alice),
|
|
@@ -1188,7 +1418,7 @@ export function testRecordsReadHandler() {
|
|
|
1188
1418
|
});
|
|
1189
1419
|
const grantDataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
1190
1420
|
const permissionGrantWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream: grantDataStream });
|
|
1191
|
-
expect(permissionGrantWriteReply.status.code).
|
|
1421
|
+
expect(permissionGrantWriteReply.status.code).toBe(202);
|
|
1192
1422
|
// Bob is unable to read the record using the mismatched permission grant
|
|
1193
1423
|
const recordsReadWithoutGrant = yield RecordsRead.create({
|
|
1194
1424
|
filter: {
|
|
@@ -1198,8 +1428,8 @@ export function testRecordsReadHandler() {
|
|
|
1198
1428
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId,
|
|
1199
1429
|
});
|
|
1200
1430
|
const recordsReadWithoutGrantReply = yield dwn.processMessage(alice.did, recordsReadWithoutGrant.message);
|
|
1201
|
-
expect(recordsReadWithoutGrantReply.status.code).
|
|
1202
|
-
expect(recordsReadWithoutGrantReply.status.detail).
|
|
1431
|
+
expect(recordsReadWithoutGrantReply.status.code).toBe(401);
|
|
1432
|
+
expect(recordsReadWithoutGrantReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolPathMismatch);
|
|
1203
1433
|
}));
|
|
1204
1434
|
});
|
|
1205
1435
|
});
|
|
@@ -1212,7 +1442,7 @@ export function testRecordsReadHandler() {
|
|
|
1212
1442
|
signer: Jws.createSigner(alice)
|
|
1213
1443
|
});
|
|
1214
1444
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1215
|
-
expect(readReply.status.code).
|
|
1445
|
+
expect(readReply.status.code).toBe(404);
|
|
1216
1446
|
}));
|
|
1217
1447
|
it('should return 404 RecordRead if data has been deleted', () => __awaiter(this, void 0, void 0, function* () {
|
|
1218
1448
|
var _a;
|
|
@@ -1220,22 +1450,22 @@ export function testRecordsReadHandler() {
|
|
|
1220
1450
|
// insert public data
|
|
1221
1451
|
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: true });
|
|
1222
1452
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1223
|
-
expect(writeReply.status.code).
|
|
1453
|
+
expect(writeReply.status.code).toBe(202);
|
|
1224
1454
|
// ensure data is inserted
|
|
1225
1455
|
const queryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1226
1456
|
author: alice,
|
|
1227
1457
|
filter: { recordId: message.recordId }
|
|
1228
1458
|
});
|
|
1229
1459
|
const reply = yield dwn.processMessage(alice.did, queryData.message);
|
|
1230
|
-
expect(reply.status.code).
|
|
1231
|
-
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
1460
|
+
expect(reply.status.code).toBe(200);
|
|
1461
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
1232
1462
|
// RecordsDelete
|
|
1233
1463
|
const recordsDelete = yield RecordsDelete.create({
|
|
1234
1464
|
recordId: message.recordId,
|
|
1235
1465
|
signer: Jws.createSigner(alice)
|
|
1236
1466
|
});
|
|
1237
1467
|
const deleteReply = yield dwn.processMessage(alice.did, recordsDelete.message);
|
|
1238
|
-
expect(deleteReply.status.code).
|
|
1468
|
+
expect(deleteReply.status.code).toBe(202);
|
|
1239
1469
|
// RecordsRead
|
|
1240
1470
|
const recordsRead = yield RecordsRead.create({
|
|
1241
1471
|
filter: {
|
|
@@ -1244,7 +1474,7 @@ export function testRecordsReadHandler() {
|
|
|
1244
1474
|
signer: Jws.createSigner(alice)
|
|
1245
1475
|
});
|
|
1246
1476
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1247
|
-
expect(readReply.status.code).
|
|
1477
|
+
expect(readReply.status.code).toBe(404);
|
|
1248
1478
|
}));
|
|
1249
1479
|
it('should return 404 underlying data store cannot locate the data when data is above threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
1250
1480
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -1255,7 +1485,7 @@ export function testRecordsReadHandler() {
|
|
|
1255
1485
|
data: TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1)
|
|
1256
1486
|
});
|
|
1257
1487
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1258
|
-
expect(writeReply.status.code).
|
|
1488
|
+
expect(writeReply.status.code).toBe(202);
|
|
1259
1489
|
// testing RecordsRead
|
|
1260
1490
|
const recordsRead = yield RecordsRead.create({
|
|
1261
1491
|
filter: {
|
|
@@ -1264,7 +1494,7 @@ export function testRecordsReadHandler() {
|
|
|
1264
1494
|
signer: Jws.createSigner(alice)
|
|
1265
1495
|
});
|
|
1266
1496
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1267
|
-
expect(readReply.status.code).
|
|
1497
|
+
expect(readReply.status.code).toBe(404);
|
|
1268
1498
|
}));
|
|
1269
1499
|
describe('data from encodedData', () => {
|
|
1270
1500
|
it('should not get data from DataStore if encodedData exists', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1275,7 +1505,7 @@ export function testRecordsReadHandler() {
|
|
|
1275
1505
|
data: TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded)
|
|
1276
1506
|
});
|
|
1277
1507
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1278
|
-
expect(writeReply.status.code).
|
|
1508
|
+
expect(writeReply.status.code).toBe(202);
|
|
1279
1509
|
const recordRead = yield RecordsRead.create({
|
|
1280
1510
|
filter: {
|
|
1281
1511
|
recordId: message.recordId,
|
|
@@ -1284,12 +1514,12 @@ export function testRecordsReadHandler() {
|
|
|
1284
1514
|
});
|
|
1285
1515
|
const dataStoreGet = sinon.spy(dataStore, 'get');
|
|
1286
1516
|
const recordsReadResponse = yield dwn.processMessage(alice.did, recordRead.message);
|
|
1287
|
-
expect(recordsReadResponse.status.code).
|
|
1288
|
-
expect(recordsReadResponse.entry.recordsWrite).
|
|
1289
|
-
expect(recordsReadResponse.entry.data).
|
|
1517
|
+
expect(recordsReadResponse.status.code).toBe(200);
|
|
1518
|
+
expect(recordsReadResponse.entry.recordsWrite).toBeDefined();
|
|
1519
|
+
expect(recordsReadResponse.entry.data).toBeDefined();
|
|
1290
1520
|
sinon.assert.notCalled(dataStoreGet);
|
|
1291
1521
|
const readData = yield DataStream.toBytes(recordsReadResponse.entry.data);
|
|
1292
|
-
expect(readData).
|
|
1522
|
+
expect(readData).toEqual(dataBytes);
|
|
1293
1523
|
}));
|
|
1294
1524
|
it('should get data from DataStore if encodedData does not exist', () => __awaiter(this, void 0, void 0, function* () {
|
|
1295
1525
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -1299,7 +1529,7 @@ export function testRecordsReadHandler() {
|
|
|
1299
1529
|
data: TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1)
|
|
1300
1530
|
});
|
|
1301
1531
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1302
|
-
expect(writeReply.status.code).
|
|
1532
|
+
expect(writeReply.status.code).toBe(202);
|
|
1303
1533
|
const recordRead = yield RecordsRead.create({
|
|
1304
1534
|
filter: {
|
|
1305
1535
|
recordId: message.recordId,
|
|
@@ -1308,12 +1538,12 @@ export function testRecordsReadHandler() {
|
|
|
1308
1538
|
});
|
|
1309
1539
|
const dataStoreGet = sinon.spy(dataStore, 'get');
|
|
1310
1540
|
const recordsReadResponse = yield dwn.processMessage(alice.did, recordRead.message);
|
|
1311
|
-
expect(recordsReadResponse.status.code).
|
|
1312
|
-
expect(recordsReadResponse.entry.recordsWrite).
|
|
1313
|
-
expect(recordsReadResponse.entry.data).
|
|
1541
|
+
expect(recordsReadResponse.status.code).toBe(200);
|
|
1542
|
+
expect(recordsReadResponse.entry.recordsWrite).toBeDefined();
|
|
1543
|
+
expect(recordsReadResponse.entry.data).toBeDefined();
|
|
1314
1544
|
sinon.assert.calledOnce(dataStoreGet);
|
|
1315
1545
|
const readData = yield DataStream.toBytes(recordsReadResponse.entry.data);
|
|
1316
|
-
expect(readData).
|
|
1546
|
+
expect(readData).toEqual(dataBytes);
|
|
1317
1547
|
}));
|
|
1318
1548
|
});
|
|
1319
1549
|
describe('encryption scenarios', () => {
|
|
@@ -1328,7 +1558,7 @@ export function testRecordsReadHandler() {
|
|
|
1328
1558
|
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
1329
1559
|
const encryptedDataStream = yield Encryption.aes256CtrEncrypt(dataEncryptionKey, dataEncryptionInitializationVector, originalDataStream);
|
|
1330
1560
|
const encryptedDataBytes = yield DataStream.toBytes(encryptedDataStream);
|
|
1331
|
-
// TODO: #450 - Should not require a root key to specify the derivation scheme (https://github.com/
|
|
1561
|
+
// TODO: #450 - Should not require a root key to specify the derivation scheme (https://github.com/enboxorg/enbox/issues/450)
|
|
1332
1562
|
const rootPrivateKeyWithSchemasScheme = {
|
|
1333
1563
|
rootKeyId: alice.keyId,
|
|
1334
1564
|
derivationScheme: KeyDerivationScheme.Schemas,
|
|
@@ -1368,7 +1598,7 @@ export function testRecordsReadHandler() {
|
|
|
1368
1598
|
encryptionInput
|
|
1369
1599
|
});
|
|
1370
1600
|
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1371
|
-
expect(writeReply.status.code).
|
|
1601
|
+
expect(writeReply.status.code).toBe(202);
|
|
1372
1602
|
const recordsRead = yield RecordsRead.create({
|
|
1373
1603
|
filter: {
|
|
1374
1604
|
recordId: message.recordId,
|
|
@@ -1377,26 +1607,26 @@ export function testRecordsReadHandler() {
|
|
|
1377
1607
|
});
|
|
1378
1608
|
// test able to derive correct key using `schemas` scheme from root key to decrypt the message
|
|
1379
1609
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1380
|
-
expect(readReply.status.code).
|
|
1610
|
+
expect(readReply.status.code).toBe(200);
|
|
1381
1611
|
const recordsWriteMessage = readReply.entry.recordsWrite;
|
|
1382
1612
|
const cipherStream = readReply.entry.data;
|
|
1383
1613
|
const plaintextDataStream = yield Records.decrypt(recordsWriteMessage, schemaDerivedPrivateKey, cipherStream);
|
|
1384
1614
|
const plaintextBytes = yield DataStream.toBytes(plaintextDataStream);
|
|
1385
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes, originalData)).
|
|
1615
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes, originalData)).toBe(true);
|
|
1386
1616
|
// test able to derive correct key using `dataFormat` scheme from root key to decrypt the message
|
|
1387
1617
|
const readReply2 = yield dwn.processMessage(alice.did, recordsRead.message); // send the same read message to get a new cipher stream
|
|
1388
|
-
expect(readReply2.status.code).
|
|
1618
|
+
expect(readReply2.status.code).toBe(200);
|
|
1389
1619
|
const cipherStream2 = readReply2.entry.data;
|
|
1390
1620
|
const plaintextDataStream2 = yield Records.decrypt(recordsWriteMessage, rootPrivateKeyWithDataFormatsScheme, cipherStream2);
|
|
1391
1621
|
const plaintextBytes2 = yield DataStream.toBytes(plaintextDataStream2);
|
|
1392
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes2, originalData)).
|
|
1622
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes2, originalData)).toBe(true);
|
|
1393
1623
|
// test unable to decrypt the message if dataFormat-derived key is derived without taking `schema` as input to derivation path
|
|
1394
1624
|
const readReply3 = yield dwn.processMessage(alice.did, recordsRead.message); // process the same read message to get a new cipher stream
|
|
1395
|
-
expect(readReply3.status.code).
|
|
1625
|
+
expect(readReply3.status.code).toBe(200);
|
|
1396
1626
|
const cipherStream3 = readReply3.entry.data;
|
|
1397
1627
|
const invalidDerivationPath = [KeyDerivationScheme.DataFormats, message.descriptor.dataFormat];
|
|
1398
1628
|
const inValidDescendantPrivateKey = yield HdKey.derivePrivateKey(rootPrivateKeyWithDataFormatsScheme, invalidDerivationPath);
|
|
1399
|
-
yield expect(Records.decrypt(recordsWriteMessage, inValidDescendantPrivateKey, cipherStream3)).
|
|
1629
|
+
yield expect(Records.decrypt(recordsWriteMessage, inValidDescendantPrivateKey, cipherStream3)).rejects.toThrow(DwnErrorCode.RecordsInvalidAncestorKeyDerivationSegment);
|
|
1400
1630
|
}));
|
|
1401
1631
|
it('should be able to decrypt flat-space schema-less record with the correct derived key', () => __awaiter(this, void 0, void 0, function* () {
|
|
1402
1632
|
// scenario: Alice writes into her own DWN an encrypted record and she is able to decrypt it
|
|
@@ -1409,7 +1639,7 @@ export function testRecordsReadHandler() {
|
|
|
1409
1639
|
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
1410
1640
|
const encryptedDataStream = yield Encryption.aes256CtrEncrypt(dataEncryptionKey, dataEncryptionInitializationVector, originalDataStream);
|
|
1411
1641
|
const encryptedDataBytes = yield DataStream.toBytes(encryptedDataStream);
|
|
1412
|
-
// TODO: #450 - Should not require a root key to specify the derivation scheme (https://github.com/
|
|
1642
|
+
// TODO: #450 - Should not require a root key to specify the derivation scheme (https://github.com/enboxorg/enbox/issues/450)
|
|
1413
1643
|
const rootPrivateKeyWithDataFormatsScheme = {
|
|
1414
1644
|
rootKeyId: alice.keyId,
|
|
1415
1645
|
derivationScheme: KeyDerivationScheme.DataFormats,
|
|
@@ -1435,7 +1665,7 @@ export function testRecordsReadHandler() {
|
|
|
1435
1665
|
});
|
|
1436
1666
|
const dataStream = DataStream.fromBytes(encryptedDataBytes);
|
|
1437
1667
|
const writeReply = yield dwn.processMessage(alice.did, recordsWrite.message, { dataStream });
|
|
1438
|
-
expect(writeReply.status.code).
|
|
1668
|
+
expect(writeReply.status.code).toBe(202);
|
|
1439
1669
|
const recordsRead = yield RecordsRead.create({
|
|
1440
1670
|
filter: {
|
|
1441
1671
|
recordId: recordsWrite.message.recordId,
|
|
@@ -1444,12 +1674,12 @@ export function testRecordsReadHandler() {
|
|
|
1444
1674
|
});
|
|
1445
1675
|
// test able to derive correct key using `dataFormat` scheme from root key to decrypt the message
|
|
1446
1676
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message); // send the same read message to get a new cipher stream
|
|
1447
|
-
expect(readReply.status.code).
|
|
1677
|
+
expect(readReply.status.code).toBe(200);
|
|
1448
1678
|
const cipherStream = readReply.entry.data;
|
|
1449
1679
|
const recordsWriteMessage = readReply.entry.recordsWrite;
|
|
1450
1680
|
const plaintextDataStream = yield Records.decrypt(recordsWriteMessage, rootPrivateKeyWithDataFormatsScheme, cipherStream);
|
|
1451
1681
|
const plaintextBytes = yield DataStream.toBytes(plaintextDataStream);
|
|
1452
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes, originalData)).
|
|
1682
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes, originalData)).toBe(true);
|
|
1453
1683
|
}));
|
|
1454
1684
|
it('should only be able to decrypt record with a correct derived private key - `protocol-context` derivation scheme', () => __awaiter(this, void 0, void 0, function* () {
|
|
1455
1685
|
// scenario: Bob initiated an encrypted chat thread with Alice,
|
|
@@ -1466,7 +1696,7 @@ export function testRecordsReadHandler() {
|
|
|
1466
1696
|
protocolDefinition: protocolDefinitionForAlice
|
|
1467
1697
|
});
|
|
1468
1698
|
const protocolsConfigureForAliceReply = yield dwn.processMessage(alice.did, protocolsConfigureForAlice.message);
|
|
1469
|
-
expect(protocolsConfigureForAliceReply.status.code).
|
|
1699
|
+
expect(protocolsConfigureForAliceReply.status.code).toBe(202);
|
|
1470
1700
|
// Bob configures chat protocol with encryption
|
|
1471
1701
|
const protocolDefinitionForBob = yield Protocols.deriveAndInjectPublicEncryptionKeys(protocolDefinition, bob.keyId, bob.keyPair.privateJwk);
|
|
1472
1702
|
const protocolsConfigureForBob = yield TestDataGenerator.generateProtocolsConfigure({
|
|
@@ -1474,7 +1704,7 @@ export function testRecordsReadHandler() {
|
|
|
1474
1704
|
protocolDefinition: protocolDefinitionForBob
|
|
1475
1705
|
});
|
|
1476
1706
|
const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfigureForBob.message);
|
|
1477
|
-
expect(protocolsConfigureReply.status.code).
|
|
1707
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1478
1708
|
// Bob queries for Alice's chat protocol definition
|
|
1479
1709
|
const protocolsQuery = yield ProtocolsQuery.create({
|
|
1480
1710
|
filter: { protocol: chatProtocolDefinition.protocol }
|
|
@@ -1484,7 +1714,7 @@ export function testRecordsReadHandler() {
|
|
|
1484
1714
|
// Bob verifies that the chat protocol definition is authored by Alice
|
|
1485
1715
|
yield authenticate(protocolsConfigureMessageReceived.authorization, didResolver);
|
|
1486
1716
|
const protocolsConfigureFetched = yield ProtocolsConfigure.parse(protocolsConfigureMessageReceived);
|
|
1487
|
-
expect(protocolsConfigureFetched.author).
|
|
1717
|
+
expect(protocolsConfigureFetched.author).toBe(alice.did);
|
|
1488
1718
|
// Bob creates an initiating a chat thread RecordsWrite
|
|
1489
1719
|
const plaintextMessageToAlice = TestDataGenerator.randomBytes(100);
|
|
1490
1720
|
const { message: threadMessage, dataStream, recordsWrite, encryptedDataBytes, encryptionInput } = yield TestDataGenerator.generateProtocolEncryptedRecordsWrite({
|
|
@@ -1497,7 +1727,7 @@ export function testRecordsReadHandler() {
|
|
|
1497
1727
|
});
|
|
1498
1728
|
// Bob writes the encrypted chat thread to Alice's DWN
|
|
1499
1729
|
const bobToAliceWriteReply = yield dwn.processMessage(alice.did, threadMessage, { dataStream });
|
|
1500
|
-
expect(bobToAliceWriteReply.status.code).
|
|
1730
|
+
expect(bobToAliceWriteReply.status.code).toBe(202);
|
|
1501
1731
|
// Bob also needs to write the same encrypted chat thread to his own DWN
|
|
1502
1732
|
// Opportunity here to create a much nicer utility method for this entire block
|
|
1503
1733
|
const bobToBobRecordsWrite = yield RecordsWrite.createFrom({
|
|
@@ -1523,7 +1753,7 @@ export function testRecordsReadHandler() {
|
|
|
1523
1753
|
yield bobToBobRecordsWrite.sign({ signer: Jws.createSigner(bob) });
|
|
1524
1754
|
const dataStreamForBobsDwn = DataStream.fromBytes(encryptedDataBytes);
|
|
1525
1755
|
const bobToBobWriteReply = yield dwn.processMessage(bob.did, bobToBobRecordsWrite.message, { dataStream: dataStreamForBobsDwn });
|
|
1526
|
-
expect(bobToBobWriteReply.status.code).
|
|
1756
|
+
expect(bobToBobWriteReply.status.code).toBe(202);
|
|
1527
1757
|
// NOTE: we know Alice is able to decrypt the message using protocol-path derived key through other tests, so we won't verify it again
|
|
1528
1758
|
// test that anyone with the protocol-context derived private key is able to decrypt the message
|
|
1529
1759
|
const recordsRead = yield RecordsRead.create({
|
|
@@ -1533,14 +1763,14 @@ export function testRecordsReadHandler() {
|
|
|
1533
1763
|
signer: Jws.createSigner(alice)
|
|
1534
1764
|
});
|
|
1535
1765
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1536
|
-
expect(readReply.status.code).
|
|
1766
|
+
expect(readReply.status.code).toBe(200);
|
|
1537
1767
|
const fetchedRecordsWrite = readReply.entry.recordsWrite;
|
|
1538
1768
|
const cipherStream = readReply.entry.data;
|
|
1539
1769
|
const derivationPathFromReadContext = Records.constructKeyDerivationPathUsingProtocolContextScheme(fetchedRecordsWrite.contextId);
|
|
1540
1770
|
const protocolContextDerivedPrivateJwk = yield HdKey.derivePrivateKey(bobRootPrivateKey, derivationPathFromReadContext);
|
|
1541
1771
|
const plaintextDataStream = yield Records.decrypt(fetchedRecordsWrite, protocolContextDerivedPrivateJwk, cipherStream);
|
|
1542
1772
|
const plaintextBytes = yield DataStream.toBytes(plaintextDataStream);
|
|
1543
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes, plaintextMessageToAlice)).
|
|
1773
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes, plaintextMessageToAlice)).toBe(true);
|
|
1544
1774
|
// verify that Alice is able to send an encrypted message using the protocol-context derived public key and Bob is able to decrypt it
|
|
1545
1775
|
// NOTE: we will skip verification of Bob's protocol configuration because we have test the such scenario above as well as in other tests
|
|
1546
1776
|
const { derivedPublicKey: protocolContextDerivedPublicJwkReturned, rootKeyId: protocolContextDerivingRootKeyIdReturned } = fetchedRecordsWrite.encryption.keyEncryption.find(encryptedKey => encryptedKey.derivationScheme === KeyDerivationScheme.ProtocolContext);
|
|
@@ -1552,13 +1782,13 @@ export function testRecordsReadHandler() {
|
|
|
1552
1782
|
protocolPath: 'thread/message',
|
|
1553
1783
|
protocolParentContextId: fetchedRecordsWrite.contextId,
|
|
1554
1784
|
protocolContextDerivingRootKeyId: protocolContextDerivingRootKeyIdReturned,
|
|
1555
|
-
|
|
1785
|
+
protocolContextDerivedPublicKeyJwk: protocolContextDerivedPublicJwkReturned,
|
|
1556
1786
|
encryptSymmetricKeyWithProtocolPathDerivedKey: true,
|
|
1557
1787
|
encryptSymmetricKeyWithProtocolContextDerivedKey: true
|
|
1558
1788
|
});
|
|
1559
1789
|
// Alice sends the message to Bob
|
|
1560
1790
|
const aliceWriteReply = yield dwn.processMessage(bob.did, recordsWriteToBob.message, { dataStream: recordsWriteToBob.dataStream });
|
|
1561
|
-
expect(aliceWriteReply.status.code).
|
|
1791
|
+
expect(aliceWriteReply.status.code).toBe(202);
|
|
1562
1792
|
// test that Bob is able to read and decrypt Alice's message
|
|
1563
1793
|
const recordsReadByBob = yield RecordsRead.create({
|
|
1564
1794
|
filter: {
|
|
@@ -1567,12 +1797,12 @@ export function testRecordsReadHandler() {
|
|
|
1567
1797
|
signer: Jws.createSigner(bob)
|
|
1568
1798
|
});
|
|
1569
1799
|
const readByBobReply = yield dwn.processMessage(bob.did, recordsReadByBob.message);
|
|
1570
|
-
expect(readByBobReply.status.code).
|
|
1800
|
+
expect(readByBobReply.status.code).toBe(200);
|
|
1571
1801
|
const fetchedRecordsWrite2 = readByBobReply.entry.recordsWrite;
|
|
1572
1802
|
const cipherStream2 = readByBobReply.entry.data;
|
|
1573
1803
|
const plaintextDataStream2 = yield Records.decrypt(fetchedRecordsWrite2, protocolContextDerivedPrivateJwk, cipherStream2);
|
|
1574
1804
|
const plaintextBytes2 = yield DataStream.toBytes(plaintextDataStream2);
|
|
1575
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes2, plaintextMessageToBob)).
|
|
1805
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes2, plaintextMessageToBob)).toBe(true);
|
|
1576
1806
|
}));
|
|
1577
1807
|
it('should only be able to decrypt record with a correct derived private key - `protocols` derivation scheme', () => __awaiter(this, void 0, void 0, function* () {
|
|
1578
1808
|
// scenario: Bob writes into Alice's DWN an encrypted "email", alice is able to decrypt it
|
|
@@ -1589,7 +1819,7 @@ export function testRecordsReadHandler() {
|
|
|
1589
1819
|
protocolDefinition: encryptedProtocolDefinition
|
|
1590
1820
|
});
|
|
1591
1821
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
1592
|
-
expect(protocolsConfigureReply.status.code).
|
|
1822
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
1593
1823
|
// Bob queries for Alice's email protocol definition
|
|
1594
1824
|
const protocolsQuery = yield ProtocolsQuery.create({
|
|
1595
1825
|
filter: { protocol: emailProtocolDefinition.protocol }
|
|
@@ -1599,7 +1829,7 @@ export function testRecordsReadHandler() {
|
|
|
1599
1829
|
// Bob verifies that the email protocol definition is authored by Alice
|
|
1600
1830
|
yield authenticate(protocolsConfigureMessageReceived.authorization, didResolver);
|
|
1601
1831
|
const protocolsConfigureFetched = yield ProtocolsConfigure.parse(protocolsConfigureMessageReceived);
|
|
1602
|
-
expect(protocolsConfigureFetched.author).
|
|
1832
|
+
expect(protocolsConfigureFetched.author).toBe(alice.did);
|
|
1603
1833
|
// Bob encrypts his email to Alice with a randomly generated symmetric key
|
|
1604
1834
|
const bobMessageBytes = TestDataGenerator.randomBytes(100);
|
|
1605
1835
|
const bobMessageStream = DataStream.fromBytes(bobMessageBytes);
|
|
@@ -1610,7 +1840,7 @@ export function testRecordsReadHandler() {
|
|
|
1610
1840
|
// Bob generates an encrypted RecordsWrite,
|
|
1611
1841
|
// the public encryption key designated by Alice is used to encrypt the symmetric key Bob generated above
|
|
1612
1842
|
const publicJwk = (_a = protocolsConfigureFetched.message.descriptor.definition.structure.email.$encryption) === null || _a === void 0 ? void 0 : _a.publicKeyJwk;
|
|
1613
|
-
expect(publicJwk).
|
|
1843
|
+
expect(publicJwk).toBeDefined();
|
|
1614
1844
|
const encryptionInput = {
|
|
1615
1845
|
initializationVector: dataEncryptionInitializationVector,
|
|
1616
1846
|
key: dataEncryptionKey,
|
|
@@ -1631,7 +1861,7 @@ export function testRecordsReadHandler() {
|
|
|
1631
1861
|
});
|
|
1632
1862
|
// Bob writes the encrypted email to Alice's DWN
|
|
1633
1863
|
const bobWriteReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1634
|
-
expect(bobWriteReply.status.code).
|
|
1864
|
+
expect(bobWriteReply.status.code).toBe(202);
|
|
1635
1865
|
// Alice reads the encrypted email
|
|
1636
1866
|
// assume Alice already made query to get the `recordId` of the email
|
|
1637
1867
|
const recordsRead = yield RecordsRead.create({
|
|
@@ -1641,7 +1871,7 @@ export function testRecordsReadHandler() {
|
|
|
1641
1871
|
signer: Jws.createSigner(alice)
|
|
1642
1872
|
});
|
|
1643
1873
|
const readReply = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1644
|
-
expect(readReply.status.code).
|
|
1874
|
+
expect(readReply.status.code).toBe(200);
|
|
1645
1875
|
// test that Alice is able decrypt the encrypted email from Bob using the root key
|
|
1646
1876
|
const rootPrivateKey = {
|
|
1647
1877
|
rootKeyId: alice.keyId,
|
|
@@ -1652,35 +1882,35 @@ export function testRecordsReadHandler() {
|
|
|
1652
1882
|
const cipherStream = readReply.entry.data;
|
|
1653
1883
|
const plaintextDataStream = yield Records.decrypt(fetchedRecordsWrite, rootPrivateKey, cipherStream);
|
|
1654
1884
|
const plaintextBytes = yield DataStream.toBytes(plaintextDataStream);
|
|
1655
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes, bobMessageBytes)).
|
|
1885
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes, bobMessageBytes)).toBe(true);
|
|
1656
1886
|
// test that a correct derived key is able decrypt the encrypted email from Bob
|
|
1657
1887
|
const readReply2 = yield dwn.processMessage(alice.did, recordsRead.message);
|
|
1658
|
-
expect(readReply2.status.code).
|
|
1888
|
+
expect(readReply2.status.code).toBe(200);
|
|
1659
1889
|
const relativeDescendantDerivationPath = Records.constructKeyDerivationPath(KeyDerivationScheme.ProtocolPath, fetchedRecordsWrite);
|
|
1660
1890
|
const derivedPrivateKey = yield HdKey.derivePrivateKey(rootPrivateKey, relativeDescendantDerivationPath);
|
|
1661
1891
|
const fetchedRecordsWrite2 = readReply2.entry.recordsWrite;
|
|
1662
1892
|
const cipherStream2 = readReply2.entry.data;
|
|
1663
1893
|
const plaintextDataStream2 = yield Records.decrypt(fetchedRecordsWrite2, derivedPrivateKey, cipherStream2);
|
|
1664
1894
|
const plaintextBytes2 = yield DataStream.toBytes(plaintextDataStream2);
|
|
1665
|
-
expect(ArrayUtility.byteArraysEqual(plaintextBytes2, bobMessageBytes)).
|
|
1895
|
+
expect(ArrayUtility.byteArraysEqual(plaintextBytes2, bobMessageBytes)).toBe(true);
|
|
1666
1896
|
// test unable to decrypt the message if derived key has an unexpected path
|
|
1667
1897
|
const invalidDerivationPath = [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol, 'invalidContextId'];
|
|
1668
1898
|
const inValidDescendantPrivateKey = yield HdKey.derivePrivateKey(rootPrivateKey, invalidDerivationPath);
|
|
1669
|
-
yield expect(Records.decrypt(fetchedRecordsWrite, inValidDescendantPrivateKey, cipherStream)).
|
|
1899
|
+
yield expect(Records.decrypt(fetchedRecordsWrite, inValidDescendantPrivateKey, cipherStream)).rejects.toThrow(DwnErrorCode.RecordsInvalidAncestorKeyDerivationSegment);
|
|
1670
1900
|
// test unable to decrypt the message if no derivation scheme used by the message matches the scheme used by the given private key
|
|
1671
1901
|
const privateKeyWithMismatchingDerivationScheme = {
|
|
1672
1902
|
rootKeyId: alice.keyId,
|
|
1673
1903
|
derivationScheme: 'scheme-that-is-not-protocol-context',
|
|
1674
1904
|
derivedPrivateKey: alice.keyPair.privateJwk
|
|
1675
1905
|
};
|
|
1676
|
-
yield expect(Records.decrypt(fetchedRecordsWrite, privateKeyWithMismatchingDerivationScheme, cipherStream)).
|
|
1906
|
+
yield expect(Records.decrypt(fetchedRecordsWrite, privateKeyWithMismatchingDerivationScheme, cipherStream)).rejects.toThrow(DwnErrorCode.RecordsDecryptNoMatchingKeyEncryptedFound);
|
|
1677
1907
|
// test unable to decrypt the message if public key ID does not match the derived private key
|
|
1678
1908
|
const privateKeyWithMismatchingKeyId = {
|
|
1679
1909
|
rootKeyId: 'mismatchingKeyId',
|
|
1680
1910
|
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
1681
1911
|
derivedPrivateKey: alice.keyPair.privateJwk
|
|
1682
1912
|
};
|
|
1683
|
-
yield expect(Records.decrypt(fetchedRecordsWrite, privateKeyWithMismatchingKeyId, cipherStream)).
|
|
1913
|
+
yield expect(Records.decrypt(fetchedRecordsWrite, privateKeyWithMismatchingKeyId, cipherStream)).rejects.toThrow(DwnErrorCode.RecordsDecryptNoMatchingKeyEncryptedFound);
|
|
1684
1914
|
}));
|
|
1685
1915
|
});
|
|
1686
1916
|
});
|
|
@@ -1700,7 +1930,7 @@ export function testRecordsReadHandler() {
|
|
|
1700
1930
|
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
1701
1931
|
const recordsReadHandler = new RecordsReadHandler(didResolver, messageStoreStub, dataStoreStub);
|
|
1702
1932
|
const reply = yield recordsReadHandler.handle({ tenant: alice.did, message: recordsRead.message });
|
|
1703
|
-
expect(reply.status.code).
|
|
1933
|
+
expect(reply.status.code).toBe(401);
|
|
1704
1934
|
}));
|
|
1705
1935
|
it('should return 400 if fail parsing the message', () => __awaiter(this, void 0, void 0, function* () {
|
|
1706
1936
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -1717,7 +1947,7 @@ export function testRecordsReadHandler() {
|
|
|
1717
1947
|
// stub the `parse()` function to throw an error
|
|
1718
1948
|
sinon.stub(RecordsRead, 'parse').throws('anyError');
|
|
1719
1949
|
const reply = yield recordsReadHandler.handle({ tenant: alice.did, message: recordsRead.message });
|
|
1720
|
-
expect(reply.status.code).
|
|
1950
|
+
expect(reply.status.code).toBe(400);
|
|
1721
1951
|
}));
|
|
1722
1952
|
});
|
|
1723
1953
|
}
|