@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,9 +7,7 @@ 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 chaiAsPromised from 'chai-as-promised';
|
|
11
10
|
import sinon from 'sinon';
|
|
12
|
-
import chai, { expect } from 'chai';
|
|
13
11
|
import { DataStream } from '../../src/utils/data-stream.js';
|
|
14
12
|
import { Dwn } from '../../src/dwn.js';
|
|
15
13
|
import { Jws } from '../../src/utils/jws.js';
|
|
@@ -20,29 +18,29 @@ import { RecordsWrite } from '../../src/interfaces/records-write.js';
|
|
|
20
18
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
21
19
|
import { TestEventStream } from '../test-event-stream.js';
|
|
22
20
|
import { TestStores } from '../test-stores.js';
|
|
21
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
23
22
|
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
24
23
|
import { DwnErrorCode, DwnInterfaceName, DwnMethodName, Encoder, RecordsQuery, Time } from '../../src/index.js';
|
|
25
|
-
chai.use(chaiAsPromised);
|
|
26
24
|
export function testPermissions() {
|
|
27
|
-
describe('permissions', () =>
|
|
25
|
+
describe('permissions', () => {
|
|
28
26
|
let didResolver;
|
|
29
27
|
let messageStore;
|
|
30
28
|
let dataStore;
|
|
31
29
|
let resumableTaskStore;
|
|
32
|
-
let
|
|
30
|
+
let stateIndex;
|
|
33
31
|
let eventStream;
|
|
34
32
|
let dwn;
|
|
35
33
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
36
34
|
// so that different test suites can reuse the same backend store for testing
|
|
37
|
-
|
|
35
|
+
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
38
36
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
39
37
|
const stores = TestStores.get();
|
|
40
38
|
messageStore = stores.messageStore;
|
|
41
39
|
dataStore = stores.dataStore;
|
|
42
40
|
resumableTaskStore = stores.resumableTaskStore;
|
|
43
|
-
|
|
41
|
+
stateIndex = stores.stateIndex;
|
|
44
42
|
eventStream = TestEventStream.get();
|
|
45
|
-
dwn = yield Dwn.create({ didResolver, messageStore, dataStore,
|
|
43
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
46
44
|
}));
|
|
47
45
|
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
48
46
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
@@ -50,9 +48,9 @@ export function testPermissions() {
|
|
|
50
48
|
yield messageStore.clear();
|
|
51
49
|
yield dataStore.clear();
|
|
52
50
|
yield resumableTaskStore.clear();
|
|
53
|
-
yield
|
|
51
|
+
yield stateIndex.clear();
|
|
54
52
|
}));
|
|
55
|
-
|
|
53
|
+
afterAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
56
54
|
sinon.restore();
|
|
57
55
|
yield dwn.close();
|
|
58
56
|
}));
|
|
@@ -70,7 +68,7 @@ export function testPermissions() {
|
|
|
70
68
|
protocol: testProtocol,
|
|
71
69
|
}
|
|
72
70
|
});
|
|
73
|
-
expect(requestWrite.recordsWrite.message.descriptor.tags).
|
|
71
|
+
expect(requestWrite.recordsWrite.message.descriptor.tags).toEqual({ protocol: testProtocol });
|
|
74
72
|
// createGrant with a protocol
|
|
75
73
|
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
76
74
|
signer: Jws.createSigner(alice),
|
|
@@ -83,14 +81,14 @@ export function testPermissions() {
|
|
|
83
81
|
protocol: testProtocol,
|
|
84
82
|
}
|
|
85
83
|
});
|
|
86
|
-
expect(grantWrite.recordsWrite.message.descriptor.tags).
|
|
84
|
+
expect(grantWrite.recordsWrite.message.descriptor.tags).toEqual({ protocol: testProtocol });
|
|
87
85
|
// createRevocation with a protocol derived from the grant
|
|
88
86
|
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
89
87
|
signer: Jws.createSigner(alice),
|
|
90
88
|
grant: yield PermissionGrant.parse(grantWrite.dataEncodedMessage),
|
|
91
89
|
dateRevoked: Time.getCurrentTimestamp()
|
|
92
90
|
});
|
|
93
|
-
expect(revokeWrite.recordsWrite.message.descriptor.tags).
|
|
91
|
+
expect(revokeWrite.recordsWrite.message.descriptor.tags).toEqual({ protocol: testProtocol });
|
|
94
92
|
}));
|
|
95
93
|
it('should normalize the protocol URL in the scope of a Request, Grant, and Revocation', () => __awaiter(this, void 0, void 0, function* () {
|
|
96
94
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -106,7 +104,7 @@ export function testPermissions() {
|
|
|
106
104
|
protocol: 'any-protocol' // URL will normalize to `http://any-protocol`
|
|
107
105
|
}
|
|
108
106
|
});
|
|
109
|
-
expect(requestWrite.recordsWrite.message.descriptor.tags).
|
|
107
|
+
expect(requestWrite.recordsWrite.message.descriptor.tags).toEqual({ protocol: 'http://any-protocol' });
|
|
110
108
|
// createRequest with a protocol that is already normalized to `https://any-protocol`
|
|
111
109
|
const requestWrite2 = yield PermissionsProtocol.createRequest({
|
|
112
110
|
signer: Jws.createSigner(bob),
|
|
@@ -118,7 +116,7 @@ export function testPermissions() {
|
|
|
118
116
|
protocol: 'https://any-protocol'
|
|
119
117
|
}
|
|
120
118
|
});
|
|
121
|
-
expect(requestWrite2.recordsWrite.message.descriptor.tags).
|
|
119
|
+
expect(requestWrite2.recordsWrite.message.descriptor.tags).toEqual({ protocol: 'https://any-protocol' });
|
|
122
120
|
// createGrant with a protocol that will be normalized to `http://any-protocol`
|
|
123
121
|
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
124
122
|
signer: Jws.createSigner(alice),
|
|
@@ -131,7 +129,7 @@ export function testPermissions() {
|
|
|
131
129
|
protocol: 'any-protocol' // URL will normalize to `http://any-protocol`
|
|
132
130
|
}
|
|
133
131
|
});
|
|
134
|
-
expect(grantWrite.recordsWrite.message.descriptor.tags).
|
|
132
|
+
expect(grantWrite.recordsWrite.message.descriptor.tags).toEqual({ protocol: 'http://any-protocol' });
|
|
135
133
|
// createGrant with a protocol that is already normalized to `https://any-protocol`
|
|
136
134
|
const grantWrite2 = yield PermissionsProtocol.createGrant({
|
|
137
135
|
signer: Jws.createSigner(alice),
|
|
@@ -144,7 +142,7 @@ export function testPermissions() {
|
|
|
144
142
|
protocol: 'https://any-protocol'
|
|
145
143
|
}
|
|
146
144
|
});
|
|
147
|
-
expect(grantWrite2.recordsWrite.message.descriptor.tags).
|
|
145
|
+
expect(grantWrite2.recordsWrite.message.descriptor.tags).toEqual({ protocol: 'https://any-protocol' });
|
|
148
146
|
}));
|
|
149
147
|
it('should derive the grantId and protocol from the grant record when creating a revocation', () => __awaiter(this, void 0, void 0, function* () {
|
|
150
148
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -165,7 +163,7 @@ export function testPermissions() {
|
|
|
165
163
|
const grantWriteReply = yield dwn.processMessage(alice.did, grantWrite.recordsWrite.message, {
|
|
166
164
|
dataStream: DataStream.fromBytes(grantWrite.permissionGrantBytes)
|
|
167
165
|
});
|
|
168
|
-
expect(grantWriteReply.status.code).
|
|
166
|
+
expect(grantWriteReply.status.code).toBe(202);
|
|
169
167
|
// derive the grantId and protocol from the grant record
|
|
170
168
|
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
171
169
|
signer: Jws.createSigner(alice),
|
|
@@ -173,9 +171,9 @@ export function testPermissions() {
|
|
|
173
171
|
dateRevoked: Time.getCurrentTimestamp()
|
|
174
172
|
});
|
|
175
173
|
// check that the protocol is in the revocation record's tags
|
|
176
|
-
expect(revokeWrite.recordsWrite.message.descriptor.tags).
|
|
174
|
+
expect(revokeWrite.recordsWrite.message.descriptor.tags).toEqual({ protocol: grantProtocol });
|
|
177
175
|
// check that the revocation's parentId is the grant's recordId
|
|
178
|
-
expect(revokeWrite.recordsWrite.message.descriptor.parentId).
|
|
176
|
+
expect(revokeWrite.recordsWrite.message.descriptor.parentId).toBe(grantWrite.recordsWrite.message.recordId);
|
|
179
177
|
}));
|
|
180
178
|
it('should support permission management through use of Request, Grants, and Revocations', () => __awaiter(this, void 0, void 0, function* () {
|
|
181
179
|
// scenario:
|
|
@@ -204,7 +202,7 @@ export function testPermissions() {
|
|
|
204
202
|
scope: permissionScope
|
|
205
203
|
});
|
|
206
204
|
const requestWriteReply = yield dwn.processMessage(alice.did, requestToAlice.recordsWrite.message, { dataStream: DataStream.fromBytes(requestToAlice.permissionRequestBytes) });
|
|
207
|
-
expect(requestWriteReply.status.code).
|
|
205
|
+
expect(requestWriteReply.status.code).toBe(202);
|
|
208
206
|
// 2. Alice queries her DWN for new permission requests
|
|
209
207
|
const requestQuery = yield RecordsQuery.create({
|
|
210
208
|
signer: Jws.createSigner(alice),
|
|
@@ -216,9 +214,9 @@ export function testPermissions() {
|
|
|
216
214
|
});
|
|
217
215
|
const requestQueryReply = yield dwn.processMessage(alice.did, requestQuery.message);
|
|
218
216
|
const requestFromBob = (_a = requestQueryReply.entries) === null || _a === void 0 ? void 0 : _a[0];
|
|
219
|
-
expect(requestQueryReply.status.code).
|
|
220
|
-
expect((_b = requestQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).
|
|
221
|
-
expect(requestFromBob.recordId).
|
|
217
|
+
expect(requestQueryReply.status.code).toBe(200);
|
|
218
|
+
expect((_b = requestQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
|
|
219
|
+
expect(requestFromBob.recordId).toBe(requestToAlice.recordsWrite.message.recordId);
|
|
222
220
|
// 3. Verify a non-owner cannot create a grant for Bob in Alice's DWN
|
|
223
221
|
const decodedRequest = PermissionsProtocol.parseRequest(requestFromBob.encodedData);
|
|
224
222
|
const unauthorizedGrantWrite = yield PermissionsProtocol.createGrant({
|
|
@@ -229,8 +227,8 @@ export function testPermissions() {
|
|
|
229
227
|
scope: decodedRequest.scope
|
|
230
228
|
});
|
|
231
229
|
const unauthorizedGrantWriteReply = yield dwn.processMessage(alice.did, unauthorizedGrantWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(unauthorizedGrantWrite.permissionGrantBytes) });
|
|
232
|
-
expect(unauthorizedGrantWriteReply.status.code).
|
|
233
|
-
expect(unauthorizedGrantWriteReply.status.detail).
|
|
230
|
+
expect(unauthorizedGrantWriteReply.status.code).toBe(401);
|
|
231
|
+
expect(unauthorizedGrantWriteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
234
232
|
// 4. Alice creates a permission grant for Bob in her DWN
|
|
235
233
|
const grantWrite = yield PermissionsProtocol.createGrant({
|
|
236
234
|
signer: Jws.createSigner(alice),
|
|
@@ -240,7 +238,7 @@ export function testPermissions() {
|
|
|
240
238
|
scope: decodedRequest.scope
|
|
241
239
|
});
|
|
242
240
|
const grantWriteReply = yield dwn.processMessage(alice.did, grantWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(grantWrite.permissionGrantBytes) });
|
|
243
|
-
expect(grantWriteReply.status.code).
|
|
241
|
+
expect(grantWriteReply.status.code).toBe(202);
|
|
244
242
|
// 5. Verify that Bob can query the permission grant from Alice's DWN (even though Alice can also send it directly to Bob)
|
|
245
243
|
const grantQuery = yield RecordsQuery.create({
|
|
246
244
|
signer: Jws.createSigner(bob),
|
|
@@ -252,9 +250,9 @@ export function testPermissions() {
|
|
|
252
250
|
});
|
|
253
251
|
const grantQueryReply = yield dwn.processMessage(alice.did, grantQuery.message);
|
|
254
252
|
const grantFromBob = (_c = grantQueryReply.entries) === null || _c === void 0 ? void 0 : _c[0];
|
|
255
|
-
expect(grantQueryReply.status.code).
|
|
256
|
-
expect((_d = grantQueryReply.entries) === null || _d === void 0 ? void 0 : _d.length).
|
|
257
|
-
expect(grantFromBob.recordId).
|
|
253
|
+
expect(grantQueryReply.status.code).toBe(200);
|
|
254
|
+
expect((_d = grantQueryReply.entries) === null || _d === void 0 ? void 0 : _d.length).toBe(1);
|
|
255
|
+
expect(grantFromBob.recordId).toBe(grantWrite.recordsWrite.message.recordId);
|
|
258
256
|
// 6. Verify that any third-party can fetch revocation of the grant and find it is still active (not revoked)
|
|
259
257
|
const revocationRead = yield RecordsRead.create({
|
|
260
258
|
signer: Jws.createSigner(bob),
|
|
@@ -264,7 +262,7 @@ export function testPermissions() {
|
|
|
264
262
|
}
|
|
265
263
|
});
|
|
266
264
|
const revocationReadReply = yield dwn.processMessage(alice.did, revocationRead.message);
|
|
267
|
-
expect(revocationReadReply.status.code).
|
|
265
|
+
expect(revocationReadReply.status.code).toBe(404);
|
|
268
266
|
// 7. Verify that non-owner cannot revoke the grant
|
|
269
267
|
const unauthorizedRevokeWrite = yield PermissionsProtocol.createRevocation({
|
|
270
268
|
signer: Jws.createSigner(bob),
|
|
@@ -272,8 +270,8 @@ export function testPermissions() {
|
|
|
272
270
|
dateRevoked: Time.getCurrentTimestamp(),
|
|
273
271
|
});
|
|
274
272
|
const unauthorizedRevokeWriteReply = yield dwn.processMessage(alice.did, unauthorizedRevokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(unauthorizedRevokeWrite.permissionRevocationBytes) });
|
|
275
|
-
expect(unauthorizedRevokeWriteReply.status.code).
|
|
276
|
-
expect(unauthorizedGrantWriteReply.status.detail).
|
|
273
|
+
expect(unauthorizedRevokeWriteReply.status.code).toBe(401);
|
|
274
|
+
expect(unauthorizedGrantWriteReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationActionNotAllowed);
|
|
277
275
|
// 8. Alice revokes the permission grant for Bob
|
|
278
276
|
const revokeWrite = yield PermissionsProtocol.createRevocation({
|
|
279
277
|
signer: Jws.createSigner(alice),
|
|
@@ -281,11 +279,11 @@ export function testPermissions() {
|
|
|
281
279
|
dateRevoked: Time.getCurrentTimestamp(),
|
|
282
280
|
});
|
|
283
281
|
const revokeWriteReply = yield dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
|
|
284
|
-
expect(revokeWriteReply.status.code).
|
|
282
|
+
expect(revokeWriteReply.status.code).toBe(202);
|
|
285
283
|
// 9. Verify that any third-party can fetch the revocation status of the permission grant
|
|
286
284
|
const revocationReadReply2 = yield dwn.processMessage(alice.did, revocationRead.message);
|
|
287
|
-
expect(revocationReadReply2.status.code).
|
|
288
|
-
expect((_e = revocationReadReply2.entry.recordsWrite) === null || _e === void 0 ? void 0 : _e.recordId).
|
|
285
|
+
expect(revocationReadReply2.status.code).toBe(200);
|
|
286
|
+
expect((_e = revocationReadReply2.entry.recordsWrite) === null || _e === void 0 ? void 0 : _e.recordId).toBe(revokeWrite.recordsWrite.message.recordId);
|
|
289
287
|
}));
|
|
290
288
|
it('should fail if a RecordsPermissionScope in a Request or Grant record is created without a protocol', () => __awaiter(this, void 0, void 0, function* () {
|
|
291
289
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -300,7 +298,7 @@ export function testPermissions() {
|
|
|
300
298
|
delegated: false,
|
|
301
299
|
scope: permissionScope // explicity as any to test the validation
|
|
302
300
|
});
|
|
303
|
-
yield expect(requestWrite).
|
|
301
|
+
yield expect(requestWrite).rejects.toThrow(DwnErrorCode.PermissionsProtocolCreateRequestRecordsScopeMissingProtocol);
|
|
304
302
|
const grantWrite = PermissionsProtocol.createGrant({
|
|
305
303
|
signer: Jws.createSigner(alice),
|
|
306
304
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
@@ -308,7 +306,7 @@ export function testPermissions() {
|
|
|
308
306
|
grantedTo: bob.did,
|
|
309
307
|
scope: permissionScope // explicity as any to test the validation
|
|
310
308
|
});
|
|
311
|
-
yield expect(grantWrite).
|
|
309
|
+
yield expect(grantWrite).rejects.toThrow(DwnErrorCode.PermissionsProtocolCreateGrantRecordsScopeMissingProtocol);
|
|
312
310
|
}));
|
|
313
311
|
it('should fail if an invalid protocolPath is used during Permissions schema validation', () => __awaiter(this, void 0, void 0, function* () {
|
|
314
312
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -318,7 +316,7 @@ export function testPermissions() {
|
|
|
318
316
|
protocolPath: 'invalid/path',
|
|
319
317
|
data: Encoder.stringToBytes(JSON.stringify({}))
|
|
320
318
|
});
|
|
321
|
-
expect(() => PermissionsProtocol.validateSchema(message, dataBytes)).
|
|
319
|
+
expect(() => PermissionsProtocol.validateSchema(message, dataBytes)).toThrow(DwnErrorCode.PermissionsProtocolValidateSchemaUnexpectedRecord);
|
|
322
320
|
}));
|
|
323
321
|
it('performs additional validation to the tagged protocol in a Revocation message ensuring it matches the Grant it is revoking', () => __awaiter(this, void 0, void 0, function* () {
|
|
324
322
|
// scenario:
|
|
@@ -345,7 +343,7 @@ export function testPermissions() {
|
|
|
345
343
|
const grantWriteReply = yield dwn.processMessage(alice.did, grantWrite.recordsWrite.message, {
|
|
346
344
|
dataStream: DataStream.fromBytes(grantWrite.permissionGrantBytes)
|
|
347
345
|
});
|
|
348
|
-
expect(grantWriteReply.status.code).
|
|
346
|
+
expect(grantWriteReply.status.code).toBe(202);
|
|
349
347
|
// attempt to revoke the grant without a protocol set
|
|
350
348
|
const permissionRevocationBytes = Encoder.objectToBytes({ description: 'Revoking the grant' });
|
|
351
349
|
const revokeWithoutProtocolRecordsWrite = yield RecordsWrite.create({
|
|
@@ -359,9 +357,9 @@ export function testPermissions() {
|
|
|
359
357
|
const revokeWriteWithoutProtocolReply = yield dwn.processMessage(alice.did, revokeWithoutProtocolRecordsWrite.message, {
|
|
360
358
|
dataStream: DataStream.fromBytes(permissionRevocationBytes)
|
|
361
359
|
});
|
|
362
|
-
expect(revokeWriteWithoutProtocolReply.status.code).
|
|
363
|
-
expect(revokeWriteWithoutProtocolReply.status.detail).
|
|
364
|
-
expect(revokeWriteWithoutProtocolReply.status.detail).
|
|
360
|
+
expect(revokeWriteWithoutProtocolReply.status.code).toBe(400);
|
|
361
|
+
expect(revokeWriteWithoutProtocolReply.status.detail).toContain(DwnErrorCode.PermissionsProtocolValidateRevocationProtocolTagMismatch);
|
|
362
|
+
expect(revokeWriteWithoutProtocolReply.status.detail).toContain(`Revocation protocol undefined does not match grant protocol ${grantProtocol}`);
|
|
365
363
|
// revoke the grant with an invalid protocol
|
|
366
364
|
const revokeWriteWithMissMatchedProtocol = yield RecordsWrite.create({
|
|
367
365
|
signer: Jws.createSigner(alice),
|
|
@@ -375,9 +373,9 @@ export function testPermissions() {
|
|
|
375
373
|
const revokeWriteWithMissMatchedProtocolReply = yield dwn.processMessage(alice.did, revokeWriteWithMissMatchedProtocol.message, {
|
|
376
374
|
dataStream: DataStream.fromBytes(permissionRevocationBytes)
|
|
377
375
|
});
|
|
378
|
-
expect(revokeWriteWithMissMatchedProtocolReply.status.code).
|
|
379
|
-
expect(revokeWriteWithMissMatchedProtocolReply.status.detail).
|
|
380
|
-
expect(revokeWriteWithMissMatchedProtocolReply.status.detail).
|
|
376
|
+
expect(revokeWriteWithMissMatchedProtocolReply.status.code).toBe(400);
|
|
377
|
+
expect(revokeWriteWithMissMatchedProtocolReply.status.detail).toContain(DwnErrorCode.PermissionsProtocolValidateRevocationProtocolTagMismatch);
|
|
378
|
+
expect(revokeWriteWithMissMatchedProtocolReply.status.detail).toContain(`Revocation protocol ${invalidProtocol} does not match grant protocol ${grantProtocol}`);
|
|
381
379
|
// revoke the grant with a valid protocol
|
|
382
380
|
const revokeWrite = yield RecordsWrite.create({
|
|
383
381
|
signer: Jws.createSigner(alice),
|
|
@@ -391,30 +389,10 @@ export function testPermissions() {
|
|
|
391
389
|
const revokeWriteReply = yield dwn.processMessage(alice.did, revokeWrite.message, {
|
|
392
390
|
dataStream: DataStream.fromBytes(permissionRevocationBytes)
|
|
393
391
|
});
|
|
394
|
-
expect(revokeWriteReply.status.code).
|
|
392
|
+
expect(revokeWriteReply.status.code).toBe(202);
|
|
395
393
|
}));
|
|
396
394
|
// These set of tets are primarily to ensure SchemaValidation passes for the various permission request and grant messages and their scopes
|
|
397
395
|
describe('ensure loaded scope properties for permission requests are processed', () => {
|
|
398
|
-
it('MessagesQuery', () => __awaiter(this, void 0, void 0, function* () {
|
|
399
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
400
|
-
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
401
|
-
// create a permission grant with protocol
|
|
402
|
-
const messagesQueryPermissions = yield PermissionsProtocol.createGrant({
|
|
403
|
-
signer: Jws.createSigner(alice),
|
|
404
|
-
grantedTo: bob.did,
|
|
405
|
-
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
406
|
-
description: 'Requesting to query from Alice test-context',
|
|
407
|
-
scope: {
|
|
408
|
-
interface: DwnInterfaceName.Messages,
|
|
409
|
-
method: DwnMethodName.Query,
|
|
410
|
-
protocol: 'https://example.com/protocol/test',
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
const messagesQueryPermissionsReply = yield dwn.processMessage(alice.did, messagesQueryPermissions.recordsWrite.message, {
|
|
414
|
-
dataStream: DataStream.fromBytes(messagesQueryPermissions.permissionGrantBytes)
|
|
415
|
-
});
|
|
416
|
-
expect(messagesQueryPermissionsReply.status.code).to.equal(202);
|
|
417
|
-
}));
|
|
418
396
|
it('MessagesRead', () => __awaiter(this, void 0, void 0, function* () {
|
|
419
397
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
420
398
|
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -433,7 +411,7 @@ export function testPermissions() {
|
|
|
433
411
|
const messagesReadPermissionsReply = yield dwn.processMessage(alice.did, messagesReadPermissions.recordsWrite.message, {
|
|
434
412
|
dataStream: DataStream.fromBytes(messagesReadPermissions.permissionGrantBytes)
|
|
435
413
|
});
|
|
436
|
-
expect(messagesReadPermissionsReply.status.code).
|
|
414
|
+
expect(messagesReadPermissionsReply.status.code).toBe(202);
|
|
437
415
|
}));
|
|
438
416
|
it('MessagesSubscribe', () => __awaiter(this, void 0, void 0, function* () {
|
|
439
417
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -453,7 +431,7 @@ export function testPermissions() {
|
|
|
453
431
|
const messagesSubscribePermissionsReply = yield dwn.processMessage(alice.did, messagesSubscribePermissions.recordsWrite.message, {
|
|
454
432
|
dataStream: DataStream.fromBytes(messagesSubscribePermissions.permissionGrantBytes)
|
|
455
433
|
});
|
|
456
|
-
expect(messagesSubscribePermissionsReply.status.code).
|
|
434
|
+
expect(messagesSubscribePermissionsReply.status.code).toBe(202);
|
|
457
435
|
}));
|
|
458
436
|
it('RecordsDelete', () => __awaiter(this, void 0, void 0, function* () {
|
|
459
437
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -474,7 +452,7 @@ export function testPermissions() {
|
|
|
474
452
|
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
475
453
|
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
476
454
|
});
|
|
477
|
-
expect(withContextIdReply.status.code).
|
|
455
|
+
expect(withContextIdReply.status.code).toBe(202);
|
|
478
456
|
// create a permission request with protocol and protocolPath
|
|
479
457
|
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
480
458
|
signer: Jws.createSigner(alice),
|
|
@@ -491,7 +469,7 @@ export function testPermissions() {
|
|
|
491
469
|
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
492
470
|
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
493
471
|
});
|
|
494
|
-
expect(withProtocolPathReply.status.code).
|
|
472
|
+
expect(withProtocolPathReply.status.code).toBe(202);
|
|
495
473
|
}));
|
|
496
474
|
it('RecordsQuery', () => __awaiter(this, void 0, void 0, function* () {
|
|
497
475
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -513,7 +491,7 @@ export function testPermissions() {
|
|
|
513
491
|
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
514
492
|
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
515
493
|
});
|
|
516
|
-
expect(withContextIdReply.status.code).
|
|
494
|
+
expect(withContextIdReply.status.code).toBe(202);
|
|
517
495
|
// create a permission request with protocol and protocolPath scope
|
|
518
496
|
const withProtocolPath = yield PermissionsProtocol.createRequest({
|
|
519
497
|
signer: Jws.createSigner(bob),
|
|
@@ -529,7 +507,7 @@ export function testPermissions() {
|
|
|
529
507
|
const withProtocolPathReply = yield dwn.processMessage(bob.did, withProtocolPath.recordsWrite.message, {
|
|
530
508
|
dataStream: DataStream.fromBytes(withProtocolPath.permissionRequestBytes)
|
|
531
509
|
});
|
|
532
|
-
expect(withProtocolPathReply.status.code).
|
|
510
|
+
expect(withProtocolPathReply.status.code).toBe(202);
|
|
533
511
|
}));
|
|
534
512
|
it('RecordsRead', () => __awaiter(this, void 0, void 0, function* () {
|
|
535
513
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -551,7 +529,7 @@ export function testPermissions() {
|
|
|
551
529
|
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
552
530
|
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
553
531
|
});
|
|
554
|
-
expect(withContextIdReply.status.code).
|
|
532
|
+
expect(withContextIdReply.status.code).toBe(202);
|
|
555
533
|
// create a permission request with protocol and protocolPath scope
|
|
556
534
|
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
557
535
|
signer: Jws.createSigner(alice),
|
|
@@ -569,7 +547,7 @@ export function testPermissions() {
|
|
|
569
547
|
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
570
548
|
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
571
549
|
});
|
|
572
|
-
expect(withProtocolPathReply.status.code).
|
|
550
|
+
expect(withProtocolPathReply.status.code).toBe(202);
|
|
573
551
|
}));
|
|
574
552
|
it('RecordsSubscribe', () => __awaiter(this, void 0, void 0, function* () {
|
|
575
553
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -591,7 +569,7 @@ export function testPermissions() {
|
|
|
591
569
|
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
592
570
|
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
593
571
|
});
|
|
594
|
-
expect(withContextIdReply.status.code).
|
|
572
|
+
expect(withContextIdReply.status.code).toBe(202);
|
|
595
573
|
// create a permission request with protocol and protocolPath scope
|
|
596
574
|
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
597
575
|
signer: Jws.createSigner(alice),
|
|
@@ -609,7 +587,7 @@ export function testPermissions() {
|
|
|
609
587
|
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
610
588
|
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
611
589
|
});
|
|
612
|
-
expect(withProtocolPathReply.status.code).
|
|
590
|
+
expect(withProtocolPathReply.status.code).toBe(202);
|
|
613
591
|
}));
|
|
614
592
|
it('RecordsWrite', () => __awaiter(this, void 0, void 0, function* () {
|
|
615
593
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -631,7 +609,7 @@ export function testPermissions() {
|
|
|
631
609
|
const withContextIdReply = yield dwn.processMessage(alice.did, withContextId.recordsWrite.message, {
|
|
632
610
|
dataStream: DataStream.fromBytes(withContextId.permissionGrantBytes)
|
|
633
611
|
});
|
|
634
|
-
expect(withContextIdReply.status.code).
|
|
612
|
+
expect(withContextIdReply.status.code).toBe(202);
|
|
635
613
|
// create a permission request with protocol and protocolPath scope
|
|
636
614
|
const withProtocolPath = yield PermissionsProtocol.createGrant({
|
|
637
615
|
signer: Jws.createSigner(alice),
|
|
@@ -649,7 +627,7 @@ export function testPermissions() {
|
|
|
649
627
|
const withProtocolPathReply = yield dwn.processMessage(alice.did, withProtocolPath.recordsWrite.message, {
|
|
650
628
|
dataStream: DataStream.fromBytes(withProtocolPath.permissionGrantBytes)
|
|
651
629
|
});
|
|
652
|
-
expect(withProtocolPathReply.status.code).
|
|
630
|
+
expect(withProtocolPathReply.status.code).toBe(202);
|
|
653
631
|
}));
|
|
654
632
|
it('ProtocolsQuery', () => __awaiter(this, void 0, void 0, function* () {
|
|
655
633
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -668,10 +646,10 @@ export function testPermissions() {
|
|
|
668
646
|
const protocolQueryPermissionsReply = yield dwn.processMessage(alice.did, protocolQueryPermissions.recordsWrite.message, {
|
|
669
647
|
dataStream: DataStream.fromBytes(protocolQueryPermissions.permissionGrantBytes)
|
|
670
648
|
});
|
|
671
|
-
expect(protocolQueryPermissionsReply.status.code).
|
|
649
|
+
expect(protocolQueryPermissionsReply.status.code).toBe(202);
|
|
672
650
|
}));
|
|
673
651
|
});
|
|
674
|
-
describe('validateScopeAndTags', () =>
|
|
652
|
+
describe('validateScopeAndTags', () => {
|
|
675
653
|
it('should be called for a Request or Grant record', () => __awaiter(this, void 0, void 0, function* () {
|
|
676
654
|
// spy on `validateScope`
|
|
677
655
|
const validateScopeSpy = sinon.spy(PermissionsProtocol, 'validateScopeAndTags');
|
|
@@ -690,8 +668,8 @@ export function testPermissions() {
|
|
|
690
668
|
scope: permissionScope
|
|
691
669
|
});
|
|
692
670
|
const requestToAliceReply = yield dwn.processMessage(alice.did, requestToAlice.recordsWrite.message, { dataStream: DataStream.fromBytes(requestToAlice.permissionRequestBytes) });
|
|
693
|
-
expect(requestToAliceReply.status.code).
|
|
694
|
-
expect(validateScopeSpy.calledOnce).
|
|
671
|
+
expect(requestToAliceReply.status.code).toBe(202);
|
|
672
|
+
expect(validateScopeSpy.calledOnce).toBe(true);
|
|
695
673
|
// create a grant
|
|
696
674
|
const grantedToBob = yield PermissionsProtocol.createGrant({
|
|
697
675
|
signer: Jws.createSigner(alice),
|
|
@@ -701,8 +679,8 @@ export function testPermissions() {
|
|
|
701
679
|
scope: permissionScope
|
|
702
680
|
});
|
|
703
681
|
const grantWriteReply = yield dwn.processMessage(alice.did, grantedToBob.recordsWrite.message, { dataStream: DataStream.fromBytes(grantedToBob.permissionGrantBytes) });
|
|
704
|
-
expect(grantWriteReply.status.code).
|
|
705
|
-
expect(validateScopeSpy.calledTwice).
|
|
682
|
+
expect(grantWriteReply.status.code).toBe(202);
|
|
683
|
+
expect(validateScopeSpy.calledTwice).toBe(true); // called twice, once for the request and once for the grant
|
|
706
684
|
}));
|
|
707
685
|
it('should throw if the scope is a RecordsPermissionScope and a protocol tag is not defined on the Request and Grant record', () => __awaiter(this, void 0, void 0, function* () {
|
|
708
686
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -719,7 +697,7 @@ export function testPermissions() {
|
|
|
719
697
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
720
698
|
tags: { someTag: 'someValue' } // not a protocol tag
|
|
721
699
|
});
|
|
722
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).
|
|
700
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
723
701
|
// create a permission grant without a protocol tag
|
|
724
702
|
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
725
703
|
author: alice,
|
|
@@ -728,7 +706,7 @@ export function testPermissions() {
|
|
|
728
706
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
729
707
|
tags: { someTag: 'someValue' } // not a protocol tag
|
|
730
708
|
});
|
|
731
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).
|
|
709
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
732
710
|
}));
|
|
733
711
|
it('should throw if the scope is a RecordsPermissionScope and the Request and Grant record has no tags', () => __awaiter(this, void 0, void 0, function* () {
|
|
734
712
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -744,7 +722,7 @@ export function testPermissions() {
|
|
|
744
722
|
protocolPath: PermissionsProtocol.requestPath,
|
|
745
723
|
data: Encoder.stringToBytes(JSON.stringify({}))
|
|
746
724
|
});
|
|
747
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).
|
|
725
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
748
726
|
// create a permission grant without a protocol tag
|
|
749
727
|
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
750
728
|
author: alice,
|
|
@@ -752,7 +730,7 @@ export function testPermissions() {
|
|
|
752
730
|
protocolPath: PermissionsProtocol.grantPath,
|
|
753
731
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
754
732
|
});
|
|
755
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).
|
|
733
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeMissingProtocolTag);
|
|
756
734
|
}));
|
|
757
735
|
it('should throw if the protocol tag in the Request and Grant record does not match the protocol defined in the scope', () => __awaiter(this, void 0, void 0, function* () {
|
|
758
736
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -770,7 +748,7 @@ export function testPermissions() {
|
|
|
770
748
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
771
749
|
tags: { protocol: 'https://example.com/protocol/invalid' }
|
|
772
750
|
});
|
|
773
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).
|
|
751
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeProtocolMismatch);
|
|
774
752
|
// create a permission grant with a protocol tag that does not match the scope
|
|
775
753
|
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
776
754
|
author: alice,
|
|
@@ -779,7 +757,7 @@ export function testPermissions() {
|
|
|
779
757
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
780
758
|
tags: { protocol: 'https://example.com/protocol/invalid' }
|
|
781
759
|
});
|
|
782
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).
|
|
760
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeProtocolMismatch);
|
|
783
761
|
}));
|
|
784
762
|
it('should throw if protocolPath and contextId are both defined in the scope for a Request and Grant record', () => __awaiter(this, void 0, void 0, function* () {
|
|
785
763
|
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
@@ -798,7 +776,7 @@ export function testPermissions() {
|
|
|
798
776
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
799
777
|
tags: { protocol: 'https://example.com/protocol/test' }
|
|
800
778
|
});
|
|
801
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestRecordsWrite.message)).
|
|
779
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, requestRecordsWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeContextIdProhibitedProperties);
|
|
802
780
|
// create a permission grant with a scope that has both protocolPath and contextId
|
|
803
781
|
const grantRecordsWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
804
782
|
author: alice,
|
|
@@ -807,9 +785,9 @@ export function testPermissions() {
|
|
|
807
785
|
data: Encoder.stringToBytes(JSON.stringify({})),
|
|
808
786
|
tags: { protocol: 'https://example.com/protocol/test' }
|
|
809
787
|
});
|
|
810
|
-
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).
|
|
788
|
+
expect(() => PermissionsProtocol['validateScopeAndTags'](permissionScope, grantRecordsWrite.message)).toThrow(DwnErrorCode.PermissionsProtocolValidateScopeContextIdProhibitedProperties);
|
|
811
789
|
}));
|
|
812
|
-
})
|
|
813
|
-
})
|
|
790
|
+
});
|
|
791
|
+
});
|
|
814
792
|
}
|
|
815
793
|
//# sourceMappingURL=permissions.spec.js.map
|