@enbox/dwn-sdk-js 0.0.1 → 0.0.3
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 +26 -45
- 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,11 +7,9 @@ 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
|
|
10
|
+
import dexProtocolDefinition from '../vectors/protocol-definitions/dex.json' with { type: 'json' };
|
|
11
|
+
import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' with { type: 'json' };
|
|
11
12
|
import sinon from 'sinon';
|
|
12
|
-
import chai, { expect } from 'chai';
|
|
13
|
-
import dexProtocolDefinition from '../vectors/protocol-definitions/dex.json' assert { type: 'json' };
|
|
14
|
-
import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' assert { type: 'json' };
|
|
15
13
|
import { GeneralJwsBuilder } from '../../src/jose/jws/general/builder.js';
|
|
16
14
|
import { lexicographicalCompare } from '../../src/utils/string.js';
|
|
17
15
|
import { Message } from '../../src/core/message.js';
|
|
@@ -21,30 +19,30 @@ import { TestEventStream } from '../test-event-stream.js';
|
|
|
21
19
|
import { TestStores } from '../test-stores.js';
|
|
22
20
|
import { TestStubGenerator } from '../utils/test-stub-generator.js';
|
|
23
21
|
import { Time } from '../../src/utils/time.js';
|
|
24
|
-
import {
|
|
22
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
23
|
+
import { DataStream, Dwn, DwnErrorCode, DwnInterfaceName, DwnMethodName, Encoder, Jws, PermissionGrant, PermissionsProtocol, RecordsDelete, RecordsRead, RecordsWrite } from '../../src/index.js';
|
|
25
24
|
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
26
|
-
chai.use(chaiAsPromised);
|
|
27
25
|
export function testProtocolsConfigureHandler() {
|
|
28
26
|
describe('ProtocolsConfigureHandler.handle()', () => {
|
|
29
27
|
let didResolver;
|
|
30
28
|
let messageStore;
|
|
31
29
|
let dataStore;
|
|
32
30
|
let resumableTaskStore;
|
|
33
|
-
let
|
|
31
|
+
let stateIndex;
|
|
34
32
|
let eventStream;
|
|
35
33
|
let dwn;
|
|
36
34
|
describe('functional tests', () => {
|
|
37
35
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
38
36
|
// so that different test suites can reuse the same backend store for testing
|
|
39
|
-
|
|
37
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
40
38
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
41
39
|
const stores = TestStores.get();
|
|
42
40
|
messageStore = stores.messageStore;
|
|
43
41
|
dataStore = stores.dataStore;
|
|
44
42
|
resumableTaskStore = stores.resumableTaskStore;
|
|
45
|
-
|
|
43
|
+
stateIndex = stores.stateIndex;
|
|
46
44
|
eventStream = TestEventStream.get();
|
|
47
|
-
dwn = yield Dwn.create({ didResolver, messageStore, dataStore,
|
|
45
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
48
46
|
}));
|
|
49
47
|
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
50
48
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
@@ -52,9 +50,9 @@ export function testProtocolsConfigureHandler() {
|
|
|
52
50
|
yield messageStore.clear();
|
|
53
51
|
yield dataStore.clear();
|
|
54
52
|
yield resumableTaskStore.clear();
|
|
55
|
-
yield
|
|
53
|
+
yield stateIndex.clear();
|
|
56
54
|
}));
|
|
57
|
-
|
|
55
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
58
56
|
yield dwn.close();
|
|
59
57
|
}));
|
|
60
58
|
it('should allow a protocol definition with schema or dataFormat omitted', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -65,7 +63,7 @@ export function testProtocolsConfigureHandler() {
|
|
|
65
63
|
protocolDefinition,
|
|
66
64
|
});
|
|
67
65
|
const reply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
68
|
-
expect(reply.status.code).
|
|
66
|
+
expect(reply.status.code).toBe(202);
|
|
69
67
|
}));
|
|
70
68
|
it('should return 400 if more than 1 signature is provided in `authorization`', () => __awaiter(this, void 0, void 0, function* () {
|
|
71
69
|
const { author, message, protocolsConfigure } = yield TestDataGenerator.generateProtocolsConfigure();
|
|
@@ -79,8 +77,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
79
77
|
message.authorization = { signature: jwsBuilder.getJws() };
|
|
80
78
|
TestStubGenerator.stubDidResolver(didResolver, [author]);
|
|
81
79
|
const reply = yield dwn.processMessage(tenant, message);
|
|
82
|
-
expect(reply.status.code).
|
|
83
|
-
expect(reply.status.detail).
|
|
80
|
+
expect(reply.status.code).toBe(400);
|
|
81
|
+
expect(reply.status.detail).toContain('expected no more than 1 signature');
|
|
84
82
|
}));
|
|
85
83
|
it('should return 401 if auth fails', () => __awaiter(this, void 0, void 0, function* () {
|
|
86
84
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -89,10 +87,10 @@ export function testProtocolsConfigureHandler() {
|
|
|
89
87
|
const badSignature = yield TestDataGenerator.randomSignatureString();
|
|
90
88
|
message.authorization.signature.signatures[0].signature = badSignature;
|
|
91
89
|
const reply = yield dwn.processMessage(alice.did, message);
|
|
92
|
-
expect(reply.status.code).
|
|
93
|
-
expect(reply.status.detail).
|
|
90
|
+
expect(reply.status.code).toBe(401);
|
|
91
|
+
expect(reply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
|
|
94
92
|
}));
|
|
95
|
-
it('should
|
|
93
|
+
it('should store all protocol versions and query should only return the latest', () => __awaiter(this, void 0, void 0, function* () {
|
|
96
94
|
var _a;
|
|
97
95
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
98
96
|
const protocolDefinition = minimalProtocolDefinition;
|
|
@@ -107,27 +105,27 @@ export function testProtocolsConfigureHandler() {
|
|
|
107
105
|
});
|
|
108
106
|
// first ProtocolsConfigure
|
|
109
107
|
const reply1 = yield dwn.processMessage(alice.did, middleProtocolsConfigure.message);
|
|
110
|
-
expect(reply1.status.code).
|
|
111
|
-
// older messages
|
|
108
|
+
expect(reply1.status.code).toBe(202);
|
|
109
|
+
// older messages are also accepted (stored as historical versions)
|
|
112
110
|
const reply2 = yield dwn.processMessage(alice.did, oldProtocolsConfigure.message);
|
|
113
|
-
expect(reply2.status.code).
|
|
114
|
-
// newer message
|
|
111
|
+
expect(reply2.status.code).toBe(202);
|
|
112
|
+
// newer message is also accepted and becomes the latest
|
|
115
113
|
const newProtocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
116
114
|
author: alice,
|
|
117
115
|
protocolDefinition,
|
|
118
116
|
});
|
|
119
117
|
const reply3 = yield dwn.processMessage(alice.did, newProtocolsConfigure.message);
|
|
120
|
-
expect(reply3.status.code).
|
|
121
|
-
// only the newest protocol should
|
|
118
|
+
expect(reply3.status.code).toBe(202);
|
|
119
|
+
// only the newest protocol should be returned by query (ProtocolsQuery returns only latest)
|
|
122
120
|
const queryMessageData = yield TestDataGenerator.generateProtocolsQuery({
|
|
123
121
|
author: alice,
|
|
124
122
|
filter: { protocol: protocolDefinition.protocol }
|
|
125
123
|
});
|
|
126
124
|
const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
|
|
127
|
-
expect(queryReply.status.code).
|
|
128
|
-
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
125
|
+
expect(queryReply.status.code).toBe(200);
|
|
126
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
129
127
|
}));
|
|
130
|
-
it('should
|
|
128
|
+
it('should store all protocol versions with identical timestamps and query should only return the newest (by CID tiebreak)', () => __awaiter(this, void 0, void 0, function* () {
|
|
131
129
|
var _a;
|
|
132
130
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
133
131
|
// Alter each protocol slightly to create lexicographic difference between them
|
|
@@ -158,21 +156,21 @@ export function testProtocolsConfigureHandler() {
|
|
|
158
156
|
const [lowestProtocolsConfigure, middleProtocolsConfigure, highestProtocolsConfigure] = messageDataWithCid.sort((messageDataA, messageDataB) => { return lexicographicalCompare(messageDataA.cid, messageDataB.cid); });
|
|
159
157
|
// write the protocol with the middle lexicographic value
|
|
160
158
|
const reply1 = yield dwn.processMessage(alice.did, middleProtocolsConfigure.message);
|
|
161
|
-
expect(reply1.status.code).
|
|
162
|
-
//
|
|
159
|
+
expect(reply1.status.code).toBe(202);
|
|
160
|
+
// all versions are accepted (stored as historical versions)
|
|
163
161
|
const reply2 = yield dwn.processMessage(alice.did, lowestProtocolsConfigure.message);
|
|
164
|
-
expect(reply2.status.code).
|
|
165
|
-
//
|
|
162
|
+
expect(reply2.status.code).toBe(202);
|
|
163
|
+
// highest lexicographic value is also accepted and becomes the latest
|
|
166
164
|
const reply3 = yield dwn.processMessage(alice.did, highestProtocolsConfigure.message);
|
|
167
|
-
expect(reply3.status.code).
|
|
168
|
-
//
|
|
165
|
+
expect(reply3.status.code).toBe(202);
|
|
166
|
+
// query should only return the latest protocol definition (highest by CID tiebreak)
|
|
169
167
|
const queryMessageData = yield TestDataGenerator.generateProtocolsQuery({
|
|
170
168
|
author: alice,
|
|
171
169
|
filter: { protocol: protocolDefinition1.protocol }
|
|
172
170
|
});
|
|
173
171
|
const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
|
|
174
|
-
expect(queryReply.status.code).
|
|
175
|
-
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).
|
|
172
|
+
expect(queryReply.status.code).toBe(200);
|
|
173
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
176
174
|
}));
|
|
177
175
|
it('should return 400 if protocol is not normalized', () => __awaiter(this, void 0, void 0, function* () {
|
|
178
176
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -190,8 +188,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
190
188
|
});
|
|
191
189
|
// Send records write message
|
|
192
190
|
const reply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
193
|
-
expect(reply.status.code).
|
|
194
|
-
expect(reply.status.detail).
|
|
191
|
+
expect(reply.status.code).toBe(400);
|
|
192
|
+
expect(reply.status.detail).toContain(DwnErrorCode.UrlProtocolNotNormalized);
|
|
195
193
|
}));
|
|
196
194
|
it('should return 400 if schema is not normalized', () => __awaiter(this, void 0, void 0, function* () {
|
|
197
195
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -209,8 +207,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
209
207
|
});
|
|
210
208
|
// Send records write message
|
|
211
209
|
const reply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
212
|
-
expect(reply.status.code).
|
|
213
|
-
expect(reply.status.detail).
|
|
210
|
+
expect(reply.status.code).toBe(400);
|
|
211
|
+
expect(reply.status.detail).toContain(DwnErrorCode.UrlSchemaNotNormalized);
|
|
214
212
|
}));
|
|
215
213
|
it('rejects non-tenant non-granted ProtocolsConfigures with 401', () => __awaiter(this, void 0, void 0, function* () {
|
|
216
214
|
// Bob tries to ProtocolsConfigure to Alice's DWN without a permission grant
|
|
@@ -222,8 +220,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
222
220
|
protocolDefinition,
|
|
223
221
|
});
|
|
224
222
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
225
|
-
expect(protocolsConfigureReply.status.code).
|
|
226
|
-
expect(protocolsConfigureReply.status.detail).
|
|
223
|
+
expect(protocolsConfigureReply.status.code).toBe(401);
|
|
224
|
+
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureAuthorizationFailed);
|
|
227
225
|
}));
|
|
228
226
|
it('should reject ProtocolsConfigure with action rule containing duplicated actor (`who` or `who` + `of` combination) within a rule set', () => __awaiter(this, void 0, void 0, function* () {
|
|
229
227
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -262,8 +260,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
262
260
|
});
|
|
263
261
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
264
262
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
265
|
-
expect(protocolsConfigureReply.status.code).
|
|
266
|
-
expect(protocolsConfigureReply.status.detail).
|
|
263
|
+
expect(protocolsConfigureReply.status.code).toBe(400);
|
|
264
|
+
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateActorInRuleSet);
|
|
267
265
|
// similar test as above but with `of` property
|
|
268
266
|
const protocolDefinition2 = {
|
|
269
267
|
protocol: 'http://foo-bar',
|
|
@@ -304,8 +302,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
304
302
|
});
|
|
305
303
|
const protocolsConfigureMessage2 = { descriptor: descriptor2, authorization: authorization2 };
|
|
306
304
|
const protocolsConfigure2Reply = yield dwn.processMessage(alice.did, protocolsConfigureMessage2);
|
|
307
|
-
expect(protocolsConfigure2Reply.status.code).
|
|
308
|
-
expect(protocolsConfigure2Reply.status.detail).
|
|
305
|
+
expect(protocolsConfigure2Reply.status.code).toBe(400);
|
|
306
|
+
expect(protocolsConfigure2Reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateActorInRuleSet);
|
|
309
307
|
}));
|
|
310
308
|
it('should reject ProtocolsConfigure with action rule containing duplicated role within a rule set', () => __awaiter(this, void 0, void 0, function* () {
|
|
311
309
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -348,145 +346,163 @@ export function testProtocolsConfigureHandler() {
|
|
|
348
346
|
});
|
|
349
347
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
350
348
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
351
|
-
expect(protocolsConfigureReply.status.code).
|
|
352
|
-
expect(protocolsConfigureReply.status.detail).
|
|
349
|
+
expect(protocolsConfigureReply.status.code).toBe(400);
|
|
350
|
+
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateRoleInRuleSet);
|
|
353
351
|
}));
|
|
354
|
-
it('should reject ProtocolsConfigure with
|
|
352
|
+
it('should reject ProtocolsConfigure with action rule `of` pointing to a sibling type (not an ancestor)', () => __awaiter(this, void 0, void 0, function* () {
|
|
355
353
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
356
|
-
//
|
|
357
|
-
const
|
|
358
|
-
protocol: 'http://
|
|
354
|
+
// `bar` and `baz` are siblings under `foo`, so `baz` action rule cannot reference `of: 'foo/bar'`
|
|
355
|
+
const protocolDefinition = {
|
|
356
|
+
protocol: 'http://example.com/sibling-of-test',
|
|
359
357
|
published: true,
|
|
360
358
|
types: {
|
|
361
|
-
friend: {},
|
|
362
359
|
foo: {},
|
|
360
|
+
bar: {},
|
|
361
|
+
baz: {},
|
|
363
362
|
},
|
|
364
363
|
structure: {
|
|
365
|
-
friend: {
|
|
366
|
-
$role: true
|
|
367
|
-
},
|
|
368
364
|
foo: {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
365
|
+
bar: {},
|
|
366
|
+
baz: {
|
|
367
|
+
$actions: [
|
|
368
|
+
{
|
|
369
|
+
who: 'author',
|
|
370
|
+
of: 'foo/bar', // sibling, not ancestor
|
|
371
|
+
can: [ProtocolAction.Create]
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
};
|
|
378
378
|
// manually craft the invalid ProtocolsConfigure message because our library will not let you create an invalid definition
|
|
379
|
-
|
|
379
|
+
const descriptor = {
|
|
380
380
|
interface: DwnInterfaceName.Protocols,
|
|
381
381
|
method: DwnMethodName.Configure,
|
|
382
382
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
383
|
-
definition:
|
|
383
|
+
definition: protocolDefinition
|
|
384
384
|
};
|
|
385
|
-
|
|
385
|
+
const authorization = yield Message.createAuthorization({
|
|
386
386
|
descriptor,
|
|
387
387
|
signer: Jws.createSigner(alice)
|
|
388
388
|
});
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
expect(
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
389
|
+
const protocolsConfigureMessage = { descriptor, authorization };
|
|
390
|
+
const reply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
391
|
+
expect(reply.status.code).toBe(400);
|
|
392
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidActionOfNotAnAncestor);
|
|
393
|
+
}));
|
|
394
|
+
it('should reject ProtocolsConfigure with action rule `of` pointing to an unrelated type', () => __awaiter(this, void 0, void 0, function* () {
|
|
395
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
396
|
+
// `comment` is a top-level type unrelated to the nested `thread/reply` path
|
|
397
|
+
const protocolDefinition = {
|
|
398
|
+
protocol: 'http://example.com/unrelated-of-test',
|
|
395
399
|
published: true,
|
|
396
400
|
types: {
|
|
397
|
-
|
|
398
|
-
|
|
401
|
+
thread: {},
|
|
402
|
+
reply: {},
|
|
403
|
+
comment: {},
|
|
399
404
|
},
|
|
400
405
|
structure: {
|
|
401
|
-
|
|
402
|
-
|
|
406
|
+
thread: {
|
|
407
|
+
reply: {
|
|
408
|
+
$actions: [
|
|
409
|
+
{
|
|
410
|
+
who: 'author',
|
|
411
|
+
of: 'comment', // unrelated type, not an ancestor of 'thread/reply'
|
|
412
|
+
can: [ProtocolAction.Create]
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
}
|
|
403
416
|
},
|
|
404
|
-
|
|
405
|
-
$actions: [
|
|
406
|
-
{
|
|
407
|
-
role: 'friend',
|
|
408
|
-
can: [ProtocolAction.Read, ProtocolAction.Subscribe] // missing `query`
|
|
409
|
-
}
|
|
410
|
-
]
|
|
411
|
-
}
|
|
417
|
+
comment: {}
|
|
412
418
|
}
|
|
413
419
|
};
|
|
414
|
-
descriptor = {
|
|
420
|
+
const descriptor = {
|
|
415
421
|
interface: DwnInterfaceName.Protocols,
|
|
416
422
|
method: DwnMethodName.Configure,
|
|
417
423
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
418
|
-
definition:
|
|
424
|
+
definition: protocolDefinition
|
|
419
425
|
};
|
|
420
|
-
authorization = yield Message.createAuthorization({
|
|
426
|
+
const authorization = yield Message.createAuthorization({
|
|
421
427
|
descriptor,
|
|
422
428
|
signer: Jws.createSigner(alice)
|
|
423
429
|
});
|
|
424
|
-
protocolsConfigureMessage = { descriptor, authorization };
|
|
425
|
-
const
|
|
426
|
-
expect(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
+
const protocolsConfigureMessage = { descriptor, authorization };
|
|
431
|
+
const reply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
432
|
+
expect(reply.status.code).toBe(400);
|
|
433
|
+
expect(reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidActionOfNotAnAncestor);
|
|
434
|
+
}));
|
|
435
|
+
it('should accept ProtocolsConfigure with action rule `of` pointing to itself (same protocol path)', () => __awaiter(this, void 0, void 0, function* () {
|
|
436
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
437
|
+
// `of` pointing to the same protocol path is valid: "the author of this record can update it"
|
|
438
|
+
const protocolDefinition = {
|
|
439
|
+
protocol: 'http://example.com/self-of-test',
|
|
430
440
|
published: true,
|
|
431
441
|
types: {
|
|
432
|
-
friend: {},
|
|
433
442
|
foo: {},
|
|
443
|
+
bar: {},
|
|
434
444
|
},
|
|
435
445
|
structure: {
|
|
436
|
-
friend: {
|
|
437
|
-
$role: true
|
|
438
|
-
},
|
|
439
446
|
foo: {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
447
|
+
bar: {
|
|
448
|
+
$actions: [
|
|
449
|
+
{
|
|
450
|
+
who: 'author',
|
|
451
|
+
of: 'foo/bar', // same as current protocol path — valid self-reference
|
|
452
|
+
can: [ProtocolAction.Create]
|
|
453
|
+
}
|
|
454
|
+
]
|
|
455
|
+
}
|
|
446
456
|
}
|
|
447
457
|
}
|
|
448
458
|
};
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
messageTimestamp: Time.getCurrentTimestamp(),
|
|
453
|
-
definition: protocolDefinitionWithoutRead
|
|
454
|
-
};
|
|
455
|
-
authorization = yield Message.createAuthorization({
|
|
456
|
-
descriptor,
|
|
457
|
-
signer: Jws.createSigner(alice)
|
|
459
|
+
const protocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
460
|
+
author: alice,
|
|
461
|
+
protocolDefinition,
|
|
458
462
|
});
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
const
|
|
464
|
-
|
|
463
|
+
const reply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
464
|
+
expect(reply.status.code).toBe(202);
|
|
465
|
+
}));
|
|
466
|
+
it('should accept ProtocolsConfigure with action rule `of` pointing to a valid ancestor', () => __awaiter(this, void 0, void 0, function* () {
|
|
467
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
468
|
+
// `of: 'thread'` is a valid ancestor of `thread/reply/reaction`
|
|
469
|
+
const protocolDefinition = {
|
|
470
|
+
protocol: 'http://example.com/valid-ancestor-of-test',
|
|
465
471
|
published: true,
|
|
466
472
|
types: {
|
|
467
|
-
|
|
468
|
-
|
|
473
|
+
thread: {},
|
|
474
|
+
reply: {},
|
|
475
|
+
reaction: {},
|
|
469
476
|
},
|
|
470
477
|
structure: {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
478
|
+
thread: {
|
|
479
|
+
reply: {
|
|
480
|
+
$actions: [
|
|
481
|
+
{
|
|
482
|
+
who: 'author',
|
|
483
|
+
of: 'thread', // valid ancestor
|
|
484
|
+
can: [ProtocolAction.Create]
|
|
485
|
+
}
|
|
486
|
+
],
|
|
487
|
+
reaction: {
|
|
488
|
+
$actions: [
|
|
489
|
+
{
|
|
490
|
+
who: 'author',
|
|
491
|
+
of: 'thread/reply', // valid immediate parent ancestor
|
|
492
|
+
can: [ProtocolAction.Create]
|
|
493
|
+
}
|
|
494
|
+
]
|
|
479
495
|
}
|
|
480
|
-
|
|
496
|
+
}
|
|
481
497
|
}
|
|
482
498
|
}
|
|
483
499
|
};
|
|
484
|
-
const
|
|
500
|
+
const protocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
485
501
|
author: alice,
|
|
486
|
-
protocolDefinition
|
|
502
|
+
protocolDefinition,
|
|
487
503
|
});
|
|
488
|
-
const
|
|
489
|
-
expect(
|
|
504
|
+
const reply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
505
|
+
expect(reply.status.code).toBe(202);
|
|
490
506
|
}));
|
|
491
507
|
describe('Grant authorization', () => {
|
|
492
508
|
it('allows an external party to ProtocolsConfigure only if they have a valid grant', () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -508,7 +524,7 @@ export function testProtocolsConfigureHandler() {
|
|
|
508
524
|
});
|
|
509
525
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
510
526
|
const grantRecordsWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
511
|
-
expect(grantRecordsWriteReply.status.code).
|
|
527
|
+
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
512
528
|
// 2. Verify Bob can perform a ProtocolsConfigure
|
|
513
529
|
const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
|
|
514
530
|
const protocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
@@ -517,7 +533,7 @@ export function testProtocolsConfigureHandler() {
|
|
|
517
533
|
protocolDefinition: minimalProtocolDefinition
|
|
518
534
|
});
|
|
519
535
|
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
|
|
520
|
-
expect(protocolsConfigureReply.status.code).
|
|
536
|
+
expect(protocolsConfigureReply.status.code).toBe(202);
|
|
521
537
|
// 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
|
|
522
538
|
const malloryProtocolsQuery = yield TestDataGenerator.generateProtocolsConfigure({
|
|
523
539
|
permissionGrantId,
|
|
@@ -525,8 +541,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
525
541
|
protocolDefinition: minimalProtocolDefinition
|
|
526
542
|
});
|
|
527
543
|
const malloryProtocolsQueryReply = yield dwn.processMessage(alice.did, malloryProtocolsQuery.message);
|
|
528
|
-
expect(malloryProtocolsQueryReply.status.code).
|
|
529
|
-
expect(malloryProtocolsQueryReply.status.detail).
|
|
544
|
+
expect(malloryProtocolsQueryReply.status.code).toBe(401);
|
|
545
|
+
expect(malloryProtocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationNotGrantedToAuthor);
|
|
530
546
|
// 4. Alice revokes Bob's grant
|
|
531
547
|
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
532
548
|
signer: Jws.createSigner(alice),
|
|
@@ -534,7 +550,7 @@ export function testProtocolsConfigureHandler() {
|
|
|
534
550
|
dateRevoked: Time.getCurrentTimestamp()
|
|
535
551
|
});
|
|
536
552
|
const revokeWriteReply = yield dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
|
|
537
|
-
expect(revokeWriteReply.status.code).
|
|
553
|
+
expect(revokeWriteReply.status.code).toBe(202);
|
|
538
554
|
// 5. Verify Bob cannot perform ProtocolsQuery with the revoked grant
|
|
539
555
|
const unauthorizedProtocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
540
556
|
permissionGrantId,
|
|
@@ -542,8 +558,8 @@ export function testProtocolsConfigureHandler() {
|
|
|
542
558
|
protocolDefinition: Object.assign(Object.assign({}, minimalProtocolDefinition), { protocol: 'https://example.com/protocol/another-protocol' })
|
|
543
559
|
});
|
|
544
560
|
const unauthorizedProtocolsConfigureReply = yield dwn.processMessage(alice.did, unauthorizedProtocolsConfigure.message);
|
|
545
|
-
expect(unauthorizedProtocolsConfigureReply.status.code).
|
|
546
|
-
expect(unauthorizedProtocolsConfigureReply.status.detail).
|
|
561
|
+
expect(unauthorizedProtocolsConfigureReply.status.code).toBe(401);
|
|
562
|
+
expect(unauthorizedProtocolsConfigureReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
547
563
|
}));
|
|
548
564
|
it('should allow to scope a ProtocolsConfigure to a specific protocol', () => __awaiter(this, void 0, void 0, function* () {
|
|
549
565
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -557,7 +573,7 @@ export function testProtocolsConfigureHandler() {
|
|
|
557
573
|
});
|
|
558
574
|
const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
|
|
559
575
|
const grantRecordsWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
|
|
560
|
-
expect(grantRecordsWriteReply.status.code).
|
|
576
|
+
expect(grantRecordsWriteReply.status.code).toBe(202);
|
|
561
577
|
// Bob tries to ProtocolsConfigure to Alice's DWN for the allowed protocol
|
|
562
578
|
const protocolConfigureAllowed = yield TestDataGenerator.generateProtocolsConfigure({
|
|
563
579
|
author: bob,
|
|
@@ -565,7 +581,7 @@ export function testProtocolsConfigureHandler() {
|
|
|
565
581
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
566
582
|
});
|
|
567
583
|
const protocolConfigureAllowedReply = yield dwn.processMessage(alice.did, protocolConfigureAllowed.message);
|
|
568
|
-
expect(protocolConfigureAllowedReply.status.code).
|
|
584
|
+
expect(protocolConfigureAllowedReply.status.code).toBe(202);
|
|
569
585
|
// Bob tries to ProtocolsConfigure to Alice's DWN for a different protocol
|
|
570
586
|
const protocolConfigureNotAllowed = yield TestDataGenerator.generateProtocolsConfigure({
|
|
571
587
|
author: bob,
|
|
@@ -573,33 +589,410 @@ export function testProtocolsConfigureHandler() {
|
|
|
573
589
|
permissionGrantId: permissionGrant.recordsWrite.message.recordId
|
|
574
590
|
});
|
|
575
591
|
const protocolConfigureNotAllowedReply = yield dwn.processMessage(alice.did, protocolConfigureNotAllowed.message);
|
|
576
|
-
expect(protocolConfigureNotAllowedReply.status.code).
|
|
592
|
+
expect(protocolConfigureNotAllowedReply.status.code).toBe(401);
|
|
577
593
|
}));
|
|
578
594
|
});
|
|
579
|
-
describe('
|
|
595
|
+
describe('state index', () => {
|
|
580
596
|
it('should add event for ProtocolsConfigure', () => __awaiter(this, void 0, void 0, function* () {
|
|
581
597
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
582
598
|
const { message } = yield TestDataGenerator.generateProtocolsConfigure({ author: alice });
|
|
583
599
|
const reply = yield dwn.processMessage(alice.did, message);
|
|
584
|
-
expect(reply.status.code).
|
|
585
|
-
const
|
|
586
|
-
expect(events.length).
|
|
600
|
+
expect(reply.status.code).toBe(202);
|
|
601
|
+
const events = yield stateIndex.getLeaves(alice.did, []);
|
|
602
|
+
expect(events.length).toBe(1);
|
|
587
603
|
const messageCid = yield Message.getCid(message);
|
|
588
|
-
expect(events[0]).
|
|
604
|
+
expect(events[0]).toBe(messageCid);
|
|
589
605
|
}));
|
|
590
|
-
it('should
|
|
606
|
+
it('should retain all ProtocolsConfigure events for protocol versioning', () => __awaiter(this, void 0, void 0, function* () {
|
|
591
607
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
592
608
|
const oldestWrite = yield TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
|
|
593
609
|
yield Time.minimalSleep();
|
|
594
610
|
const newestWrite = yield TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
|
|
595
611
|
let reply = yield dwn.processMessage(alice.did, oldestWrite.message);
|
|
596
|
-
expect(reply.status.code).
|
|
612
|
+
expect(reply.status.code).toBe(202);
|
|
597
613
|
reply = yield dwn.processMessage(alice.did, newestWrite.message);
|
|
598
|
-
expect(reply.status.code).
|
|
599
|
-
const
|
|
600
|
-
expect(events.length).
|
|
614
|
+
expect(reply.status.code).toBe(202);
|
|
615
|
+
const events = yield stateIndex.getLeaves(alice.did, []);
|
|
616
|
+
expect(events.length).toBe(2);
|
|
617
|
+
const oldestMessageCid = yield Message.getCid(oldestWrite.message);
|
|
601
618
|
const newestMessageCid = yield Message.getCid(newestWrite.message);
|
|
602
|
-
expect(events
|
|
619
|
+
expect(events).toContain(oldestMessageCid);
|
|
620
|
+
expect(events).toContain(newestMessageCid);
|
|
621
|
+
}));
|
|
622
|
+
});
|
|
623
|
+
describe('temporal protocol versioning', () => {
|
|
624
|
+
it('should authorize records created under v1 even after re-configuring to v2 that removes the type', () => __awaiter(this, void 0, void 0, function* () {
|
|
625
|
+
// scenario:
|
|
626
|
+
// 1. Alice installs protocol v1 with types `post` and `comment`
|
|
627
|
+
// 2. Alice writes a `post` record under v1
|
|
628
|
+
// 3. Alice re-configures the protocol to v2 which removes the `comment` type
|
|
629
|
+
// 4. Alice should still be able to read the v1 `post` record
|
|
630
|
+
// 5. Alice should still be able to update the v1 `post` record (governed by v1 definition)
|
|
631
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
632
|
+
// v1: has `post` and `comment` types
|
|
633
|
+
const protocolUri = 'https://example.com/versioned-protocol';
|
|
634
|
+
const protocolDefinitionV1 = {
|
|
635
|
+
protocol: protocolUri,
|
|
636
|
+
published: true,
|
|
637
|
+
types: {
|
|
638
|
+
post: { schema: 'https://example.com/post', dataFormats: ['application/json'] },
|
|
639
|
+
comment: { schema: 'https://example.com/comment', dataFormats: ['application/json'] },
|
|
640
|
+
},
|
|
641
|
+
structure: {
|
|
642
|
+
post: {
|
|
643
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read, ProtocolAction.Update] }],
|
|
644
|
+
comment: {
|
|
645
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
651
|
+
author: alice,
|
|
652
|
+
protocolDefinition: protocolDefinitionV1,
|
|
653
|
+
});
|
|
654
|
+
const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
|
|
655
|
+
expect(configureV1Reply.status.code).toBe(202);
|
|
656
|
+
// write a `post` record under v1
|
|
657
|
+
const postRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
658
|
+
author: alice,
|
|
659
|
+
protocol: protocolUri,
|
|
660
|
+
protocolPath: 'post',
|
|
661
|
+
schema: 'https://example.com/post',
|
|
662
|
+
dataFormat: 'application/json',
|
|
663
|
+
});
|
|
664
|
+
const postReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
665
|
+
expect(postReply.status.code).toBe(202);
|
|
666
|
+
// write a `comment` record under v1
|
|
667
|
+
const commentRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
668
|
+
author: alice,
|
|
669
|
+
protocol: protocolUri,
|
|
670
|
+
protocolPath: 'post/comment',
|
|
671
|
+
schema: 'https://example.com/comment',
|
|
672
|
+
dataFormat: 'application/json',
|
|
673
|
+
parentContextId: postRecord.message.contextId,
|
|
674
|
+
});
|
|
675
|
+
const commentReply = yield dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
|
|
676
|
+
expect(commentReply.status.code).toBe(202);
|
|
677
|
+
yield Time.minimalSleep();
|
|
678
|
+
// v2: removes the `comment` type entirely, changes `post` schema
|
|
679
|
+
const protocolDefinitionV2 = {
|
|
680
|
+
protocol: protocolUri,
|
|
681
|
+
published: true,
|
|
682
|
+
types: {
|
|
683
|
+
post: { schema: 'https://example.com/post-v2', dataFormats: ['application/json'] },
|
|
684
|
+
},
|
|
685
|
+
structure: {
|
|
686
|
+
post: {
|
|
687
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read, ProtocolAction.Update] }],
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
692
|
+
author: alice,
|
|
693
|
+
protocolDefinition: protocolDefinitionV2,
|
|
694
|
+
});
|
|
695
|
+
const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
|
|
696
|
+
expect(configureV2Reply.status.code).toBe(202);
|
|
697
|
+
// read the v1 `post` record — should succeed because read authorization uses v1 definition
|
|
698
|
+
const readPost = yield RecordsRead.create({
|
|
699
|
+
filter: { recordId: postRecord.message.recordId },
|
|
700
|
+
signer: Jws.createSigner(alice),
|
|
701
|
+
});
|
|
702
|
+
const readPostReply = yield dwn.processMessage(alice.did, readPost.message);
|
|
703
|
+
expect(readPostReply.status.code).toBe(200);
|
|
704
|
+
// read the v1 `comment` record — should succeed (governed by v1 definition where `comment` exists)
|
|
705
|
+
const readComment = yield RecordsRead.create({
|
|
706
|
+
filter: { recordId: commentRecord.message.recordId },
|
|
707
|
+
signer: Jws.createSigner(alice),
|
|
708
|
+
});
|
|
709
|
+
const readCommentReply = yield dwn.processMessage(alice.did, readComment.message);
|
|
710
|
+
expect(readCommentReply.status.code).toBe(200);
|
|
711
|
+
// update the v1 `post` record — should succeed (governed by v1 definition)
|
|
712
|
+
const updatedData = new TextEncoder().encode('{"title":"updated post"}');
|
|
713
|
+
const updatePost = yield RecordsWrite.createFrom({
|
|
714
|
+
recordsWriteMessage: postRecord.message,
|
|
715
|
+
data: updatedData,
|
|
716
|
+
signer: Jws.createSigner(alice),
|
|
717
|
+
});
|
|
718
|
+
const updatePostReply = yield dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
|
|
719
|
+
expect(updatePostReply.status.code).toBe(202);
|
|
720
|
+
}));
|
|
721
|
+
it('should authorize new records against the latest protocol definition, not an older one', () => __awaiter(this, void 0, void 0, function* () {
|
|
722
|
+
// scenario:
|
|
723
|
+
// 1. Alice installs protocol v1 with type `post`
|
|
724
|
+
// 2. Alice re-configures to v2 that changes `post` schema to 'https://example.com/post-v2'
|
|
725
|
+
// 3. A new record with v1 schema should be rejected (not matching the latest definition)
|
|
726
|
+
// 4. A new record with v2 schema should be accepted
|
|
727
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
728
|
+
const protocolUri = 'https://example.com/versioned-protocol-2';
|
|
729
|
+
const protocolDefinitionV1 = {
|
|
730
|
+
protocol: protocolUri,
|
|
731
|
+
published: true,
|
|
732
|
+
types: {
|
|
733
|
+
post: { schema: 'https://example.com/post-v1', dataFormats: ['application/json'] },
|
|
734
|
+
},
|
|
735
|
+
structure: {
|
|
736
|
+
post: {
|
|
737
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
742
|
+
author: alice,
|
|
743
|
+
protocolDefinition: protocolDefinitionV1,
|
|
744
|
+
});
|
|
745
|
+
const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
|
|
746
|
+
expect(configureV1Reply.status.code).toBe(202);
|
|
747
|
+
yield Time.minimalSleep();
|
|
748
|
+
// v2: changes `post` schema
|
|
749
|
+
const protocolDefinitionV2 = {
|
|
750
|
+
protocol: protocolUri,
|
|
751
|
+
published: true,
|
|
752
|
+
types: {
|
|
753
|
+
post: { schema: 'https://example.com/post-v2', dataFormats: ['application/json'] },
|
|
754
|
+
},
|
|
755
|
+
structure: {
|
|
756
|
+
post: {
|
|
757
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
762
|
+
author: alice,
|
|
763
|
+
protocolDefinition: protocolDefinitionV2,
|
|
764
|
+
});
|
|
765
|
+
const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
|
|
766
|
+
expect(configureV2Reply.status.code).toBe(202);
|
|
767
|
+
// write a new record with v1 schema — should fail (latest definition requires v2 schema)
|
|
768
|
+
const postV1 = yield TestDataGenerator.generateRecordsWrite({
|
|
769
|
+
author: alice,
|
|
770
|
+
protocol: protocolUri,
|
|
771
|
+
protocolPath: 'post',
|
|
772
|
+
schema: 'https://example.com/post-v1',
|
|
773
|
+
dataFormat: 'application/json',
|
|
774
|
+
});
|
|
775
|
+
const postV1Reply = yield dwn.processMessage(alice.did, postV1.message, { dataStream: postV1.dataStream });
|
|
776
|
+
expect(postV1Reply.status.code).toBe(400);
|
|
777
|
+
expect(postV1Reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationInvalidSchema);
|
|
778
|
+
// write a new record with v2 schema — should succeed
|
|
779
|
+
const postV2 = yield TestDataGenerator.generateRecordsWrite({
|
|
780
|
+
author: alice,
|
|
781
|
+
protocol: protocolUri,
|
|
782
|
+
protocolPath: 'post',
|
|
783
|
+
schema: 'https://example.com/post-v2',
|
|
784
|
+
dataFormat: 'application/json',
|
|
785
|
+
});
|
|
786
|
+
const postV2Reply = yield dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
|
|
787
|
+
expect(postV2Reply.status.code).toBe(202);
|
|
788
|
+
}));
|
|
789
|
+
it('should authorize deletes of v1 records after re-configuring to v2 that removes the type', () => __awaiter(this, void 0, void 0, function* () {
|
|
790
|
+
// scenario:
|
|
791
|
+
// 1. Alice installs protocol v1 with types `post` (with delete action) and `comment`
|
|
792
|
+
// 2. Alice writes a `post/comment` record
|
|
793
|
+
// 3. Alice re-configures to v2 which removes the `comment` type
|
|
794
|
+
// 4. Alice should still be able to delete the v1 `comment` record (governed by v1 definition)
|
|
795
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
796
|
+
const protocolUri = 'https://example.com/versioned-protocol-3';
|
|
797
|
+
const protocolDefinitionV1 = {
|
|
798
|
+
protocol: protocolUri,
|
|
799
|
+
published: true,
|
|
800
|
+
types: {
|
|
801
|
+
post: {},
|
|
802
|
+
comment: {},
|
|
803
|
+
},
|
|
804
|
+
structure: {
|
|
805
|
+
post: {
|
|
806
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
807
|
+
comment: {
|
|
808
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read, ProtocolAction.Delete] }],
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
814
|
+
author: alice,
|
|
815
|
+
protocolDefinition: protocolDefinitionV1,
|
|
816
|
+
});
|
|
817
|
+
const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
|
|
818
|
+
expect(configureV1Reply.status.code).toBe(202);
|
|
819
|
+
// write a `post` record
|
|
820
|
+
const postRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
821
|
+
author: alice,
|
|
822
|
+
protocol: protocolUri,
|
|
823
|
+
protocolPath: 'post',
|
|
824
|
+
});
|
|
825
|
+
const postReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
826
|
+
expect(postReply.status.code).toBe(202);
|
|
827
|
+
// write a `comment` record under the post
|
|
828
|
+
const commentRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
829
|
+
author: alice,
|
|
830
|
+
protocol: protocolUri,
|
|
831
|
+
protocolPath: 'post/comment',
|
|
832
|
+
parentContextId: postRecord.message.contextId,
|
|
833
|
+
});
|
|
834
|
+
const commentReply = yield dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
|
|
835
|
+
expect(commentReply.status.code).toBe(202);
|
|
836
|
+
yield Time.minimalSleep();
|
|
837
|
+
// v2: removes the `comment` type
|
|
838
|
+
const protocolDefinitionV2 = {
|
|
839
|
+
protocol: protocolUri,
|
|
840
|
+
published: true,
|
|
841
|
+
types: {
|
|
842
|
+
post: {},
|
|
843
|
+
},
|
|
844
|
+
structure: {
|
|
845
|
+
post: {
|
|
846
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
851
|
+
author: alice,
|
|
852
|
+
protocolDefinition: protocolDefinitionV2,
|
|
853
|
+
});
|
|
854
|
+
const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
|
|
855
|
+
expect(configureV2Reply.status.code).toBe(202);
|
|
856
|
+
// delete the v1 `comment` record — should succeed (governed by v1 definition)
|
|
857
|
+
const deleteComment = yield RecordsDelete.create({
|
|
858
|
+
signer: Jws.createSigner(alice),
|
|
859
|
+
recordId: commentRecord.message.recordId,
|
|
860
|
+
});
|
|
861
|
+
const deleteReply = yield dwn.processMessage(alice.did, deleteComment.message);
|
|
862
|
+
expect(deleteReply.status.code).toBe(202);
|
|
863
|
+
}));
|
|
864
|
+
it('should not retroactively apply v2 action rules to records created under v1', () => __awaiter(this, void 0, void 0, function* () {
|
|
865
|
+
// scenario:
|
|
866
|
+
// 1. Alice installs protocol v1 where anyone can create and update `post` records
|
|
867
|
+
// 2. Bob writes a `post` to Alice's DWN
|
|
868
|
+
// 3. Alice re-configures to v2 that restricts `post` updates to author-only (removes co-update)
|
|
869
|
+
// 4. Bob should still be able to update his own record (governed by v1 definition which had update)
|
|
870
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
871
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
872
|
+
const protocolUri = 'https://example.com/versioned-protocol-4';
|
|
873
|
+
const protocolDefinitionV1 = {
|
|
874
|
+
protocol: protocolUri,
|
|
875
|
+
published: true,
|
|
876
|
+
types: {
|
|
877
|
+
post: {},
|
|
878
|
+
},
|
|
879
|
+
structure: {
|
|
880
|
+
post: {
|
|
881
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read, ProtocolAction.Update] }],
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
886
|
+
author: alice,
|
|
887
|
+
protocolDefinition: protocolDefinitionV1,
|
|
888
|
+
});
|
|
889
|
+
const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
|
|
890
|
+
expect(configureV1Reply.status.code).toBe(202);
|
|
891
|
+
// Bob writes a `post` record to Alice's DWN under v1
|
|
892
|
+
const postRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
893
|
+
author: bob,
|
|
894
|
+
protocol: protocolUri,
|
|
895
|
+
protocolPath: 'post',
|
|
896
|
+
});
|
|
897
|
+
const postReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
|
|
898
|
+
expect(postReply.status.code).toBe(202);
|
|
899
|
+
yield Time.minimalSleep();
|
|
900
|
+
// v2: restricts actions (only create, no update for anyone)
|
|
901
|
+
const protocolDefinitionV2 = {
|
|
902
|
+
protocol: protocolUri,
|
|
903
|
+
published: true,
|
|
904
|
+
types: {
|
|
905
|
+
post: {},
|
|
906
|
+
},
|
|
907
|
+
structure: {
|
|
908
|
+
post: {
|
|
909
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
914
|
+
author: alice,
|
|
915
|
+
protocolDefinition: protocolDefinitionV2,
|
|
916
|
+
});
|
|
917
|
+
const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
|
|
918
|
+
expect(configureV2Reply.status.code).toBe(202);
|
|
919
|
+
// Bob updates his v1 record — should succeed because v1 definition (which governs this record) allowed update
|
|
920
|
+
const updatedData = new TextEncoder().encode('updated-post-data');
|
|
921
|
+
const updatePost = yield RecordsWrite.createFrom({
|
|
922
|
+
recordsWriteMessage: postRecord.message,
|
|
923
|
+
data: updatedData,
|
|
924
|
+
signer: Jws.createSigner(bob),
|
|
925
|
+
});
|
|
926
|
+
const updateReply = yield dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
|
|
927
|
+
expect(updateReply.status.code).toBe(202);
|
|
928
|
+
}));
|
|
929
|
+
it('should handle out-of-order protocol configure processing correctly', () => __awaiter(this, void 0, void 0, function* () {
|
|
930
|
+
var _a;
|
|
931
|
+
// scenario:
|
|
932
|
+
// 1. Create v1 and v2 ProtocolsConfigure messages (v2 has a newer timestamp)
|
|
933
|
+
// 2. Process v2 first, then v1
|
|
934
|
+
// 3. Both should be stored; query should return only v2 (the latest)
|
|
935
|
+
// 4. A record written under v2 schema should succeed
|
|
936
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
937
|
+
const protocolUri = 'https://example.com/versioned-protocol-5';
|
|
938
|
+
const protocolDefinitionV1 = {
|
|
939
|
+
protocol: protocolUri,
|
|
940
|
+
published: true,
|
|
941
|
+
types: {
|
|
942
|
+
post: { schema: 'https://example.com/post-v1', dataFormats: ['application/json'] },
|
|
943
|
+
},
|
|
944
|
+
structure: {
|
|
945
|
+
post: {
|
|
946
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
951
|
+
author: alice,
|
|
952
|
+
protocolDefinition: protocolDefinitionV1,
|
|
953
|
+
});
|
|
954
|
+
yield Time.minimalSleep();
|
|
955
|
+
const protocolDefinitionV2 = {
|
|
956
|
+
protocol: protocolUri,
|
|
957
|
+
published: true,
|
|
958
|
+
types: {
|
|
959
|
+
post: { schema: 'https://example.com/post-v2', dataFormats: ['application/json'] },
|
|
960
|
+
},
|
|
961
|
+
structure: {
|
|
962
|
+
post: {
|
|
963
|
+
$actions: [{ who: 'anyone', can: [ProtocolAction.Create, ProtocolAction.Read] }],
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
|
|
968
|
+
author: alice,
|
|
969
|
+
protocolDefinition: protocolDefinitionV2,
|
|
970
|
+
});
|
|
971
|
+
// process v2 first (out of order)
|
|
972
|
+
const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
|
|
973
|
+
expect(configureV2Reply.status.code).toBe(202);
|
|
974
|
+
// process v1 second (older, arrives later)
|
|
975
|
+
const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
|
|
976
|
+
expect(configureV1Reply.status.code).toBe(202);
|
|
977
|
+
// query should return only v2 (the latest)
|
|
978
|
+
const queryMessageData = yield TestDataGenerator.generateProtocolsQuery({
|
|
979
|
+
author: alice,
|
|
980
|
+
filter: { protocol: protocolUri }
|
|
981
|
+
});
|
|
982
|
+
const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
|
|
983
|
+
expect(queryReply.status.code).toBe(200);
|
|
984
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
|
|
985
|
+
expect(queryReply.entries[0].descriptor.definition.types.post.schema).toBe('https://example.com/post-v2');
|
|
986
|
+
// writing a new record with v2 schema should succeed (latest definition)
|
|
987
|
+
const postV2 = yield TestDataGenerator.generateRecordsWrite({
|
|
988
|
+
author: alice,
|
|
989
|
+
protocol: protocolUri,
|
|
990
|
+
protocolPath: 'post',
|
|
991
|
+
schema: 'https://example.com/post-v2',
|
|
992
|
+
dataFormat: 'application/json',
|
|
993
|
+
});
|
|
994
|
+
const postV2Reply = yield dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
|
|
995
|
+
expect(postV2Reply.status.code).toBe(202);
|
|
603
996
|
}));
|
|
604
997
|
});
|
|
605
998
|
});
|