@enbox/dwn-sdk-js 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/browser.mjs +19 -78
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +1997 -1517
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +50 -0
- package/dist/esm/src/core/constants.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +28 -11
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/encryption-control.js +785 -0
- package/dist/esm/src/core/encryption-control.js.map +1 -0
- package/dist/esm/src/core/message.js +6 -0
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +36 -5
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +3 -12
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +31 -30
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +6 -0
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/recording-validation-state-reader.js +3 -3
- package/dist/esm/src/core/recording-validation-state-reader.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js +62 -108
- package/dist/esm/src/core/replication-apply.js.map +1 -1
- package/dist/esm/src/core/validation-state-reader.js +5 -6
- package/dist/esm/src/core/validation-state-reader.js.map +1 -1
- package/dist/esm/src/dwn.js +1 -2
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js +11 -11
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js.map +1 -1
- package/dist/esm/src/handlers/messages-query.js +6 -16
- package/dist/esm/src/handlers/messages-query.js.map +1 -1
- package/dist/esm/src/handlers/messages-read.js +4 -3
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +26 -30
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +6 -4
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +85 -10
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +11 -0
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +140 -18
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +20 -4
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +127 -11
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +15 -0
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +7 -10
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +66 -9
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +43 -36
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +5 -5
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/encryption.js +32 -274
- package/dist/esm/src/protocols/encryption.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +14 -23
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +10 -27
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/blockstore-utils.js +45 -0
- package/dist/esm/src/store/blockstore-utils.js.map +1 -0
- package/dist/esm/src/store/blockstore.js +2 -0
- package/dist/esm/src/store/blockstore.js.map +1 -0
- package/dist/esm/src/store/data-store-level.js +4 -12
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/level.js +7 -0
- package/dist/esm/src/store/level.js.map +1 -0
- package/dist/esm/src/types/encryption-types.js +4 -1
- package/dist/esm/src/types/encryption-types.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +25 -0
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +107 -19
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/grant-key-coverage.js +180 -0
- package/dist/esm/src/utils/grant-key-coverage.js.map +1 -0
- package/dist/esm/src/utils/hd-key.js +1 -2
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +7 -1
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +29 -8
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +27 -0
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/record-limit-occupancy.js +23 -3
- package/dist/esm/src/utils/record-limit-occupancy.js.map +1 -1
- package/dist/esm/src/utils/records.js +29 -0
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +12 -11
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +12 -20
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +103 -25
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/tests/core/constants.spec.js +35 -0
- package/dist/esm/tests/core/constants.spec.js.map +1 -0
- package/dist/esm/tests/core/encryption-control.spec.js +100 -0
- package/dist/esm/tests/core/encryption-control.spec.js.map +1 -0
- package/dist/esm/tests/core/message.spec.js +35 -0
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-apply.spec.js +157 -74
- package/dist/esm/tests/core/replication-apply.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js +2 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js +14 -28
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-state-reader.spec.js +19 -23
- package/dist/esm/tests/core/validation-state-reader.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +2 -1
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-wake-publisher.spec.js +51 -0
- package/dist/esm/tests/event-emitter-wake-publisher.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-composition.spec.js +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/encryption.fuzz.spec.js +9 -1
- package/dist/esm/tests/fuzz/encryption.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js +1 -1
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/protocols-utils.fuzz.spec.js +29 -1
- package/dist/esm/tests/fuzz/protocols-utils.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/secp256k1.fuzz.spec.js +2 -2
- package/dist/esm/tests/fuzz/secp256k1.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/time.fuzz.spec.js +7 -1
- package/dist/esm/tests/fuzz/time.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +123 -11
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +95 -0
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +90 -0
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +66 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +370 -0
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +70 -1
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +562 -1
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +140 -2
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +241 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1187 -29
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +290 -2
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +47 -5
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/encryption.spec.js +116 -472
- package/dist/esm/tests/protocols/encryption.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +13 -27
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +33 -10
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +31 -7
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-utils.spec.js +115 -0
- package/dist/esm/tests/store/blockstore-utils.spec.js.map +1 -0
- package/dist/esm/tests/store/index-level.spec.js +3 -3
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/test-stores.js +2 -1
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +15 -0
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +30 -0
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-control-test-utils.js +111 -0
- package/dist/esm/tests/utils/encryption-control-test-utils.js.map +1 -0
- package/dist/esm/tests/utils/encryption.spec.js +198 -5
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/grant-key-coverage.spec.js +262 -0
- package/dist/esm/tests/utils/grant-key-coverage.spec.js.map +1 -0
- package/dist/esm/tests/utils/memory-cache.spec.js +12 -0
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +2 -2
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +2 -1
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/utils/test-validation-state-reader.js +1 -1
- package/dist/esm/tests/utils/test-validation-state-reader.js.map +1 -1
- package/dist/esm/tests/utils/time.spec.js +26 -0
- package/dist/esm/tests/utils/time.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/encryption/audience.spec.js +45 -0
- package/dist/esm/tests/validation/json-schemas/encryption/audience.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/encryption/delivery.spec.js +47 -0
- package/dist/esm/tests/validation/json-schemas/encryption/delivery.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +152 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +46 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +4 -4
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +39 -0
- package/dist/types/src/core/constants.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +28 -11
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/encryption-control.d.ts +128 -0
- package/dist/types/src/core/encryption-control.d.ts.map +1 -0
- package/dist/types/src/core/message.d.ts +4 -0
- package/dist/types/src/core/message.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +11 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/recording-validation-state-reader.d.ts +2 -3
- package/dist/types/src/core/recording-validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +10 -1
- package/dist/types/src/core/replication-apply.d.ts.map +1 -1
- package/dist/types/src/core/validation-state-reader.d.ts +2 -3
- package/dist/types/src/core/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts +1 -1
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +1 -0
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +2 -0
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -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-subscribe.d.ts +2 -0
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +10 -17
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts +13 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +5 -1
- 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/protocols/encryption.d.ts +2 -19
- package/dist/types/src/protocols/encryption.d.ts.map +1 -1
- package/dist/types/src/store/blockstore-level.d.ts +11 -11
- package/dist/types/src/store/blockstore-level.d.ts.map +1 -1
- package/dist/types/src/store/blockstore-mock.d.ts +12 -12
- package/dist/types/src/store/blockstore-mock.d.ts.map +1 -1
- package/dist/types/src/store/blockstore-utils.d.ts +23 -0
- package/dist/types/src/store/blockstore-utils.d.ts.map +1 -0
- package/dist/types/src/store/blockstore.d.ts +3 -0
- package/dist/types/src/store/blockstore.d.ts.map +1 -0
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/level.d.ts +13 -0
- package/dist/types/src/store/level.d.ts.map +1 -0
- package/dist/types/src/types/cache.d.ts +2 -2
- package/dist/types/src/types/cache.d.ts.map +1 -1
- package/dist/types/src/types/encryption-types.d.ts +31 -2
- package/dist/types/src/types/encryption-types.d.ts.map +1 -1
- package/dist/types/src/types/validation-state-reader.d.ts +3 -5
- package/dist/types/src/types/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/utils/data-stream.d.ts +5 -0
- package/dist/types/src/utils/data-stream.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +53 -24
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/grant-key-coverage.d.ts +36 -0
- package/dist/types/src/utils/grant-key-coverage.d.ts.map +1 -0
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/jws.d.ts.map +1 -1
- package/dist/types/src/utils/memory-cache.d.ts +4 -2
- package/dist/types/src/utils/memory-cache.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +11 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/record-limit-occupancy.d.ts +7 -0
- package/dist/types/src/utils/record-limit-occupancy.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +2 -0
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/secp256k1.d.ts.map +1 -1
- package/dist/types/src/utils/secp256r1.d.ts.map +1 -1
- package/dist/types/src/utils/time.d.ts +21 -13
- package/dist/types/src/utils/time.d.ts.map +1 -1
- package/dist/types/tests/core/constants.spec.d.ts +2 -0
- package/dist/types/tests/core/constants.spec.d.ts.map +1 -0
- package/dist/types/tests/core/encryption-control.spec.d.ts +2 -0
- package/dist/types/tests/core/encryption-control.spec.d.ts.map +1 -0
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-wake-publisher.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-wake-publisher.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-query.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/protocols-configure.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- 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/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/store/blockstore-utils.spec.d.ts +2 -0
- package/dist/types/tests/store/blockstore-utils.spec.d.ts.map +1 -0
- package/dist/types/tests/test-stores.d.ts.map +1 -1
- package/dist/types/tests/utils/encryption-control-test-utils.d.ts +46 -0
- package/dist/types/tests/utils/encryption-control-test-utils.d.ts.map +1 -0
- package/dist/types/tests/utils/grant-key-coverage.spec.d.ts +2 -0
- package/dist/types/tests/utils/grant-key-coverage.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/validation/json-schemas/encryption/audience.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/encryption/audience.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts.map +1 -0
- package/package.json +47 -28
- package/src/core/constants.ts +61 -0
- package/src/core/dwn-error.ts +28 -11
- package/src/core/encryption-control.ts +1249 -0
- package/src/core/message.ts +7 -0
- package/src/core/messages-grant-authorization.ts +60 -9
- package/src/core/protocol-authorization-action.ts +3 -13
- package/src/core/protocol-authorization-validation.ts +66 -46
- package/src/core/protocol-authorization.ts +7 -0
- package/src/core/recording-validation-state-reader.ts +4 -5
- package/src/core/replication-apply.ts +77 -133
- package/src/core/validation-state-reader.ts +6 -8
- package/src/dwn.ts +1 -2
- package/src/event-stream/event-emitter-wake-publisher.ts +10 -14
- package/src/handlers/messages-query.ts +6 -22
- package/src/handlers/messages-read.ts +4 -3
- package/src/handlers/messages-subscribe.ts +34 -30
- package/src/handlers/protocols-configure.ts +7 -4
- package/src/handlers/records-count.ts +111 -10
- package/src/handlers/records-delete.ts +15 -0
- package/src/handlers/records-query.ts +176 -20
- package/src/handlers/records-read.ts +19 -6
- package/src/handlers/records-subscribe.ts +158 -8
- package/src/handlers/records-write.ts +19 -0
- package/src/index.ts +48 -21
- package/src/interfaces/protocols-configure.ts +102 -11
- package/src/interfaces/records-write.ts +49 -43
- package/src/jose/algorithms/signing/ed25519.ts +7 -6
- package/src/jose/jws/general/verifier.ts +3 -3
- package/src/protocols/encryption.ts +50 -420
- package/src/store/blockstore-level.ts +33 -37
- package/src/store/blockstore-mock.ts +24 -38
- package/src/store/blockstore-utils.ts +85 -0
- package/src/store/blockstore.ts +8 -0
- package/src/store/data-store-level.ts +5 -12
- package/src/store/level.ts +19 -0
- package/src/types/cache.ts +3 -3
- package/src/types/encryption-types.ts +39 -2
- package/src/types/validation-state-reader.ts +3 -5
- package/src/utils/data-stream.ts +29 -1
- package/src/utils/encryption.ts +190 -60
- package/src/utils/grant-key-coverage.ts +303 -0
- package/src/utils/hd-key.ts +1 -2
- package/src/utils/jws.ts +8 -2
- package/src/utils/memory-cache.ts +42 -11
- package/src/utils/protocols.ts +32 -0
- package/src/utils/record-limit-occupancy.ts +34 -5
- package/src/utils/records.ts +36 -2
- package/src/utils/secp256k1.ts +12 -12
- package/src/utils/secp256r1.ts +12 -22
- package/src/utils/time.ts +145 -27
- package/dist/esm/tests/validation/json-schemas/encryption/audience-key.spec.js +0 -40
- package/dist/esm/tests/validation/json-schemas/encryption/audience-key.spec.js.map +0 -1
- package/dist/types/tests/validation/json-schemas/encryption/audience-key.spec.d.ts +0 -2
- package/dist/types/tests/validation/json-schemas/encryption/audience-key.spec.d.ts.map +0 -1
- package/src/types/mitt.d.ts +0 -28
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EncryptionControlPath } from './constants.js';
|
|
1
2
|
import type { GenericMessage } from '../types/message-types.js';
|
|
2
3
|
import type { ProgressToken } from '../types/subscriptions.js';
|
|
3
4
|
import type { ProtocolDefinition } from '../types/protocols-types.js';
|
|
@@ -9,7 +10,8 @@ import { EncryptionProtocol } from '../protocols/encryption.js';
|
|
|
9
10
|
import { Message } from './message.js';
|
|
10
11
|
import { ROLE_AUDIENCE_DERIVATION_SCHEME } from '../utils/encryption.js';
|
|
11
12
|
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
12
|
-
import {
|
|
13
|
+
import { ENCRYPTION_CONTROL_AUDIENCE_PATH, ENCRYPTION_CONTROL_DELIVERY_PATH } from './constants.js';
|
|
14
|
+
import { getRoleAudienceContextId, getRoleContextPrefix, isCrossProtocolRef, parseCrossProtocolRef } from '../utils/protocols.js';
|
|
13
15
|
|
|
14
16
|
export type ReplicationApplyOptions = {
|
|
15
17
|
dataStream?: ReadableStream<Uint8Array>;
|
|
@@ -42,14 +44,6 @@ export type ReplicationApplyResultContext = {
|
|
|
42
44
|
missingAncestorRecordIds?: string[];
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
type AudienceDependencyTags = {
|
|
46
|
-
protocol: string;
|
|
47
|
-
contextId: string;
|
|
48
|
-
role: string;
|
|
49
|
-
epoch: number;
|
|
50
|
-
keyId: string;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
47
|
export type DependencyRef =
|
|
54
48
|
| { type: 'Protocol'; protocol: string; messageCid?: string; terminal?: boolean }
|
|
55
49
|
| { type: 'InitialWrite'; recordId: string; protocol?: string; messageCid?: string; terminal?: boolean }
|
|
@@ -59,7 +53,16 @@ export type DependencyRef =
|
|
|
59
53
|
| { type: 'Grant'; permissionGrantId: string; messageCid?: string; terminal?: boolean }
|
|
60
54
|
| {
|
|
61
55
|
type: 'EncryptionProtocol';
|
|
62
|
-
protocolPath: '
|
|
56
|
+
protocolPath: 'grantKey';
|
|
57
|
+
tags?: Record<string, string | number>;
|
|
58
|
+
recipient?: string;
|
|
59
|
+
messageCid?: string;
|
|
60
|
+
terminal?: boolean;
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
type: 'EncryptionControl';
|
|
64
|
+
protocol: string;
|
|
65
|
+
protocolPath: EncryptionControlPath;
|
|
63
66
|
tags?: Record<string, string | number>;
|
|
64
67
|
recipient?: string;
|
|
65
68
|
messageCid?: string;
|
|
@@ -197,14 +200,13 @@ function dependencyRefsFromStatus(
|
|
|
197
200
|
case DwnErrorCode.GrantAuthorizationGrantMissing:
|
|
198
201
|
return toRefList(grantDependencyFromMessage(message));
|
|
199
202
|
case DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound:
|
|
200
|
-
case DwnErrorCode.EncryptionProtocolValidateAudienceWriterUnauthorized:
|
|
201
203
|
return toRefList(roleDependencyFromMessage(message, context));
|
|
202
|
-
case DwnErrorCode.
|
|
203
|
-
return
|
|
204
|
-
case DwnErrorCode.
|
|
205
|
-
return toRefList(
|
|
206
|
-
case DwnErrorCode.
|
|
207
|
-
return toRefList(
|
|
204
|
+
case DwnErrorCode.ProtocolAuthorizationEncryptionRoleAudienceMissing:
|
|
205
|
+
return encryptionAudienceDependenciesFromRoleAudienceEntries(message);
|
|
206
|
+
case DwnErrorCode.EncryptionControlValidateDeliveryAudienceMissing:
|
|
207
|
+
return toRefList(encryptionAudienceDependencyFromDelivery(message));
|
|
208
|
+
case DwnErrorCode.EncryptionControlValidateDeliveryRecipientRoleRecordMissing:
|
|
209
|
+
return toRefList(roleDependencyFromEncryptionControlDeliveryRecipient(message));
|
|
208
210
|
case DwnErrorCode.RecordsWriteMissingDataInPrevious:
|
|
209
211
|
case DwnErrorCode.RecordsWriteMissingEncodedDataInPrevious:
|
|
210
212
|
return toRefList(recordDataDependencyFromMessage(message));
|
|
@@ -373,11 +375,6 @@ function recordDataDependencyFromMessage(message: GenericMessage): DependencyRef
|
|
|
373
375
|
}
|
|
374
376
|
|
|
375
377
|
function roleDependencyFromMessage(message: GenericMessage, context: ReplicationApplyResultContext): DependencyRef | undefined {
|
|
376
|
-
const encryptionRoleDependency = roleDependencyFromEncryptionAudienceWriter(message, context);
|
|
377
|
-
if (encryptionRoleDependency !== undefined) {
|
|
378
|
-
return encryptionRoleDependency;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
378
|
const descriptor = message.descriptor as Record<string, unknown>;
|
|
382
379
|
const filter = descriptor.filter as Record<string, unknown> | undefined;
|
|
383
380
|
const protocol = descriptor.protocol ?? filter?.protocol;
|
|
@@ -405,10 +402,7 @@ function roleDependencyFromMessage(message: GenericMessage, context: Replication
|
|
|
405
402
|
} else if (typeof filter?.contextId === 'string') {
|
|
406
403
|
contextId = filter.contextId;
|
|
407
404
|
}
|
|
408
|
-
const
|
|
409
|
-
const contextPrefix = roleSegments > 0 && contextId !== undefined
|
|
410
|
-
? contextId.split('/').slice(0, roleSegments).join('/')
|
|
411
|
-
: undefined;
|
|
405
|
+
const contextPrefix = getRoleContextPrefix(roleProtocolPath, contextId);
|
|
412
406
|
|
|
413
407
|
return {
|
|
414
408
|
type : 'Role',
|
|
@@ -419,20 +413,9 @@ function roleDependencyFromMessage(message: GenericMessage, context: Replication
|
|
|
419
413
|
};
|
|
420
414
|
}
|
|
421
415
|
|
|
422
|
-
function
|
|
423
|
-
message: GenericMessage,
|
|
424
|
-
protocolPath: Extract<DependencyRef, { type: 'EncryptionProtocol' }>['protocolPath'],
|
|
425
|
-
): DependencyRef | undefined {
|
|
426
|
-
const tags = encryptionAudienceTagsFromMessage(message);
|
|
427
|
-
return tags === undefined
|
|
428
|
-
? undefined
|
|
429
|
-
: { type: 'EncryptionProtocol', protocolPath, tags };
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
function encryptionProtocolDependencyFromRoleAudienceEntry(
|
|
416
|
+
function encryptionAudienceDependenciesFromRoleAudienceEntries(
|
|
433
417
|
message: GenericMessage,
|
|
434
|
-
|
|
435
|
-
): DependencyRef | undefined {
|
|
418
|
+
): Extract<DependencyRef, { type: 'EncryptionControl' }>[] {
|
|
436
419
|
const descriptor = message.descriptor as Record<string, unknown>;
|
|
437
420
|
const messageContextId = (message as { contextId?: unknown }).contextId;
|
|
438
421
|
const contextId = typeof messageContextId === 'string' ? messageContextId : descriptor.contextId;
|
|
@@ -442,113 +425,97 @@ function encryptionProtocolDependencyFromRoleAudienceEntry(
|
|
|
442
425
|
};
|
|
443
426
|
}).encryption?.keyEncryption;
|
|
444
427
|
if (typeof contextId !== 'string' || !Array.isArray(keyEncryption)) {
|
|
445
|
-
return
|
|
428
|
+
return [];
|
|
446
429
|
}
|
|
447
430
|
|
|
448
|
-
const
|
|
449
|
-
const
|
|
431
|
+
const refs: Extract<DependencyRef, { type: 'EncryptionControl' }>[] = [];
|
|
432
|
+
const sourceEntries = keyEncryption.filter((candidate): boolean =>
|
|
450
433
|
candidate.derivationScheme === ROLE_AUDIENCE_DERIVATION_SCHEME &&
|
|
451
434
|
typeof candidate.protocol === 'string' &&
|
|
452
|
-
typeof candidate.
|
|
453
|
-
(missingRole === undefined || candidate.role === missingRole) &&
|
|
454
|
-
typeof candidate.epoch === 'number' &&
|
|
435
|
+
typeof candidate.rolePath === 'string' &&
|
|
455
436
|
typeof candidate.keyId === 'string'
|
|
456
437
|
);
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
438
|
+
for (const sourceEntry of sourceEntries) {
|
|
439
|
+
const rolePath = sourceEntry.rolePath as string;
|
|
440
|
+
const audienceContextId = getRoleAudienceContextId(rolePath, contextId);
|
|
441
|
+
if (audienceContextId === undefined) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
460
444
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
445
|
+
refs.push({
|
|
446
|
+
type : 'EncryptionControl',
|
|
447
|
+
protocol : sourceEntry.protocol as string,
|
|
448
|
+
protocolPath : ENCRYPTION_CONTROL_AUDIENCE_PATH,
|
|
449
|
+
tags : {
|
|
450
|
+
protocol : sourceEntry.protocol as string,
|
|
451
|
+
rolePath,
|
|
452
|
+
contextId : audienceContextId,
|
|
453
|
+
keyId : sourceEntry.keyId as string,
|
|
454
|
+
},
|
|
455
|
+
});
|
|
465
456
|
}
|
|
466
457
|
|
|
467
|
-
return
|
|
468
|
-
type : 'EncryptionProtocol',
|
|
469
|
-
protocolPath : EncryptionProtocol.audienceEpochPath,
|
|
470
|
-
tags : {
|
|
471
|
-
protocol : entry.protocol as string,
|
|
472
|
-
contextId : audienceContextId,
|
|
473
|
-
role,
|
|
474
|
-
epoch : entry.epoch as number,
|
|
475
|
-
keyId : entry.keyId as string,
|
|
476
|
-
},
|
|
477
|
-
};
|
|
458
|
+
return refs;
|
|
478
459
|
}
|
|
479
460
|
|
|
480
|
-
function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
461
|
+
function encryptionAudienceDependencyFromDelivery(
|
|
462
|
+
message: GenericMessage,
|
|
463
|
+
): Extract<DependencyRef, { type: 'EncryptionControl' }> | undefined {
|
|
464
|
+
const descriptor = message.descriptor as Record<string, unknown>;
|
|
465
|
+
if (descriptor.protocolPath !== ENCRYPTION_CONTROL_DELIVERY_PATH) {
|
|
484
466
|
return undefined;
|
|
485
467
|
}
|
|
486
468
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
protocol : tags.protocol,
|
|
490
|
-
protocolPath : tags.role,
|
|
491
|
-
recipient,
|
|
492
|
-
...(tags.contextId === '' ? {} : { contextPrefix: tags.contextId }),
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
function roleDependencyFromEncryptionAudienceWriter(
|
|
497
|
-
message: GenericMessage,
|
|
498
|
-
context: ReplicationApplyResultContext,
|
|
499
|
-
): DependencyRef | undefined {
|
|
500
|
-
const tags = encryptionAudienceTagsFromMessage(message);
|
|
501
|
-
const protocolRole = getSignaturePayload(message)?.protocolRole;
|
|
502
|
-
const recipient = Message.getAuthor(message);
|
|
503
|
-
if (tags === undefined || typeof protocolRole !== 'string' || recipient === undefined) {
|
|
469
|
+
const tags = descriptor.tags;
|
|
470
|
+
if (!isRecordObject(tags)) {
|
|
504
471
|
return undefined;
|
|
505
472
|
}
|
|
506
473
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
roleProtocol = referencedProtocol;
|
|
517
|
-
roleProtocolPath = parsed.protocolPath;
|
|
474
|
+
const { protocol, rolePath, contextId, keyId } = tags;
|
|
475
|
+
if (
|
|
476
|
+
typeof protocol !== 'string' ||
|
|
477
|
+
typeof rolePath !== 'string' ||
|
|
478
|
+
typeof contextId !== 'string' ||
|
|
479
|
+
typeof keyId !== 'string'
|
|
480
|
+
) {
|
|
481
|
+
return undefined;
|
|
518
482
|
}
|
|
519
483
|
|
|
520
|
-
const contextPrefix = roleContextPrefix(roleProtocolPath, tags.contextId);
|
|
521
484
|
return {
|
|
522
|
-
type : '
|
|
523
|
-
protocol
|
|
524
|
-
protocolPath :
|
|
525
|
-
|
|
526
|
-
...(contextPrefix === undefined ? {} : { contextPrefix }),
|
|
485
|
+
type : 'EncryptionControl',
|
|
486
|
+
protocol,
|
|
487
|
+
protocolPath : ENCRYPTION_CONTROL_AUDIENCE_PATH,
|
|
488
|
+
tags : { protocol, rolePath, contextId, keyId },
|
|
527
489
|
};
|
|
528
490
|
}
|
|
529
491
|
|
|
530
|
-
function
|
|
531
|
-
|
|
492
|
+
function roleDependencyFromEncryptionControlDeliveryRecipient(message: GenericMessage): DependencyRef | undefined {
|
|
493
|
+
const descriptor = message.descriptor as Record<string, unknown>;
|
|
494
|
+
if (descriptor.protocolPath !== ENCRYPTION_CONTROL_DELIVERY_PATH || typeof descriptor.recipient !== 'string') {
|
|
532
495
|
return undefined;
|
|
533
496
|
}
|
|
534
497
|
|
|
535
|
-
const tags =
|
|
498
|
+
const tags = descriptor.tags;
|
|
536
499
|
if (!isRecordObject(tags)) {
|
|
537
500
|
return undefined;
|
|
538
501
|
}
|
|
539
502
|
|
|
540
|
-
const { protocol,
|
|
503
|
+
const { protocol, rolePath, contextId } = tags;
|
|
541
504
|
if (
|
|
542
505
|
typeof protocol !== 'string' ||
|
|
543
|
-
typeof
|
|
544
|
-
typeof
|
|
545
|
-
typeof epoch !== 'number' ||
|
|
546
|
-
typeof keyId !== 'string'
|
|
506
|
+
typeof rolePath !== 'string' ||
|
|
507
|
+
typeof contextId !== 'string'
|
|
547
508
|
) {
|
|
548
509
|
return undefined;
|
|
549
510
|
}
|
|
550
511
|
|
|
551
|
-
return {
|
|
512
|
+
return {
|
|
513
|
+
type : 'Role',
|
|
514
|
+
protocol,
|
|
515
|
+
protocolPath : rolePath,
|
|
516
|
+
recipient : descriptor.recipient,
|
|
517
|
+
...(contextId === '' ? {} : { contextPrefix: contextId }),
|
|
518
|
+
};
|
|
552
519
|
}
|
|
553
520
|
|
|
554
521
|
function dependencyProtocolFromMessage(message: GenericMessage): string | undefined {
|
|
@@ -570,29 +537,6 @@ function isEncryptionProtocolMessage(message: GenericMessage): boolean {
|
|
|
570
537
|
descriptor.protocol === EncryptionProtocol.uri;
|
|
571
538
|
}
|
|
572
539
|
|
|
573
|
-
function roleContextPrefix(rolePath: string, contextId: string): string | undefined {
|
|
574
|
-
const roleSegments = rolePath.split('/').length - 1;
|
|
575
|
-
if (roleSegments === 0 || contextId === '') {
|
|
576
|
-
return undefined;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
return contextId.split('/').slice(0, roleSegments).join('/');
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
function roleAudienceContextId(rolePath: string, contextId: string): string | undefined {
|
|
583
|
-
const roleSegments = rolePath.split('/').length - 1;
|
|
584
|
-
if (roleSegments === 0) {
|
|
585
|
-
return '';
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
const contextSegments = contextId.split('/');
|
|
589
|
-
if (contextSegments.length < roleSegments) {
|
|
590
|
-
return undefined;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
return contextSegments.slice(0, roleSegments).join('/');
|
|
594
|
-
}
|
|
595
|
-
|
|
596
540
|
function isRecordObject(value: unknown): value is Record<string, unknown> {
|
|
597
541
|
return typeof value === 'object' && value !== null;
|
|
598
542
|
}
|
|
@@ -7,7 +7,7 @@ import type { ValidationStateReader } from '../types/validation-state-reader.js'
|
|
|
7
7
|
import type { DataEncodedRecordsWriteMessage, RecordsWriteMessage } from '../types/records-types.js';
|
|
8
8
|
import type { ProtocolDefinition, ProtocolsConfigureMessage } from '../types/protocols-types.js';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { ENCRYPTION_CONTROL_AUDIENCE_PATH } from './constants.js';
|
|
11
11
|
import { FilterUtility } from '../utils/filter.js';
|
|
12
12
|
import { PermissionGrant } from '../protocols/permission-grant.js';
|
|
13
13
|
import { PermissionsProtocol } from '../protocols/permissions.js';
|
|
@@ -167,24 +167,22 @@ export class StoreValidationStateReader implements ValidationStateReader {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/** @inheritdoc */
|
|
170
|
-
public async
|
|
170
|
+
public async queryAudienceRecords(input: {
|
|
171
171
|
tenant: string;
|
|
172
172
|
protocol: string;
|
|
173
|
+
rolePath: string;
|
|
173
174
|
contextId: string;
|
|
174
|
-
role: string;
|
|
175
|
-
epoch: number;
|
|
176
175
|
keyId?: string;
|
|
177
176
|
}): Promise<RecordsWriteMessage[]> {
|
|
178
177
|
const filter: Filter = {
|
|
179
178
|
interface : DwnInterfaceName.Records,
|
|
180
179
|
method : DwnMethodName.Write,
|
|
181
180
|
isLatestBaseState : true,
|
|
182
|
-
protocol :
|
|
183
|
-
protocolPath :
|
|
181
|
+
protocol : input.protocol,
|
|
182
|
+
protocolPath : ENCRYPTION_CONTROL_AUDIENCE_PATH,
|
|
184
183
|
'tag.protocol' : input.protocol,
|
|
184
|
+
'tag.rolePath' : input.rolePath,
|
|
185
185
|
'tag.contextId' : input.contextId,
|
|
186
|
-
'tag.role' : input.role,
|
|
187
|
-
'tag.epoch' : input.epoch,
|
|
188
186
|
};
|
|
189
187
|
|
|
190
188
|
if (input.keyId !== undefined) {
|
package/src/dwn.ts
CHANGED
|
@@ -495,8 +495,7 @@ export class Dwn {
|
|
|
495
495
|
): Promise<ProtocolDefinition | undefined> {
|
|
496
496
|
const detail = reply.status.detail ?? '';
|
|
497
497
|
if (
|
|
498
|
-
!detail.startsWith(`${DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound}:`)
|
|
499
|
-
!detail.startsWith(`${DwnErrorCode.EncryptionProtocolValidateAudienceWriterUnauthorized}:`)
|
|
498
|
+
!detail.startsWith(`${DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound}:`)
|
|
500
499
|
) {
|
|
501
500
|
return undefined;
|
|
502
501
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { Wake, WakePublisher } from '../types/subscriptions.js';
|
|
2
2
|
|
|
3
|
-
import mitt from 'mitt';
|
|
4
|
-
|
|
5
|
-
const WAKE_CHANNEL = 'wake';
|
|
6
|
-
|
|
7
|
-
type WakeEvents = Record<string, Wake>;
|
|
8
|
-
|
|
9
3
|
export type WakeListener = (wake: Wake) => void;
|
|
10
4
|
|
|
11
5
|
/**
|
|
@@ -13,22 +7,24 @@ export type WakeListener = (wake: Wake) => void;
|
|
|
13
7
|
* failures must not affect the write path that already committed the row.
|
|
14
8
|
*/
|
|
15
9
|
export class EventEmitterWakePublisher implements WakePublisher {
|
|
16
|
-
private readonly
|
|
10
|
+
private readonly listeners = new Set<WakeListener>();
|
|
17
11
|
|
|
18
12
|
public publish(wake: Wake): void {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
for (const listener of Array.from(this.listeners)) {
|
|
14
|
+
try {
|
|
15
|
+
listener(wake);
|
|
16
|
+
} catch {
|
|
17
|
+
// Best-effort by contract.
|
|
18
|
+
}
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
public subscribe(listener: WakeListener): () => void {
|
|
27
|
-
this.
|
|
28
|
-
return (): void => { this.
|
|
23
|
+
this.listeners.add(listener);
|
|
24
|
+
return (): void => { this.listeners.delete(listener); };
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
public clear(): void {
|
|
32
|
-
this.
|
|
28
|
+
this.listeners.clear();
|
|
33
29
|
}
|
|
34
30
|
}
|
|
@@ -79,28 +79,12 @@ export class MessagesQueryHandler implements MethodHandler {
|
|
|
79
79
|
tenant: string,
|
|
80
80
|
messagesQuery: MessagesQuery,
|
|
81
81
|
): Promise<void> {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const permissionGrants = await MessagesGrantAuthorization.fetchPermissionGrants(
|
|
89
|
-
tenant,
|
|
90
|
-
this.deps.validationStateReader,
|
|
91
|
-
permissionGrantIds
|
|
92
|
-
);
|
|
93
|
-
await MessagesGrantAuthorization.authorizeQueryOrSubscribe({
|
|
94
|
-
incomingMessage : messagesQuery.message,
|
|
95
|
-
expectedGrantor : tenant,
|
|
96
|
-
expectedGrantee : messagesQuery.author,
|
|
97
|
-
permissionGrants,
|
|
98
|
-
validationStateReader : this.deps.validationStateReader
|
|
99
|
-
});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
throw new DwnError(DwnErrorCode.MessagesQueryAuthorizationFailed, 'message failed authorization');
|
|
82
|
+
await MessagesGrantAuthorization.authorizeQueryOrSubscribeInvocation({
|
|
83
|
+
tenant : tenant,
|
|
84
|
+
incomingMessage : messagesQuery.message,
|
|
85
|
+
validationStateReader : this.deps.validationStateReader,
|
|
86
|
+
failureCode : DwnErrorCode.MessagesQueryAuthorizationFailed,
|
|
87
|
+
});
|
|
104
88
|
}
|
|
105
89
|
|
|
106
90
|
private static asReplicationFeedReader(candidate: unknown): ReplicationFeedReader | undefined {
|
|
@@ -80,19 +80,20 @@ export class MessagesReadHandler implements MethodHandler {
|
|
|
80
80
|
deps: HandlerDependencies
|
|
81
81
|
): Promise<void> {
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
const requester = Message.getRequester(messagesRead.message);
|
|
84
|
+
if (messagesRead.author === tenant && requester === tenant) {
|
|
84
85
|
// If the author is the tenant, no further authorization is needed
|
|
85
86
|
return;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
const permissionGrantIds = Message.getPermissionGrantIds(messagesRead.signaturePayload!);
|
|
89
|
-
if (
|
|
90
|
+
if (requester !== undefined && permissionGrantIds.length > 0) {
|
|
90
91
|
const permissionGrants = await MessagesGrantAuthorization.fetchPermissionGrants(tenant, deps.validationStateReader, permissionGrantIds);
|
|
91
92
|
await MessagesGrantAuthorization.authorizeMessagesRead({
|
|
92
93
|
messagesReadMessage : messagesRead.message,
|
|
93
94
|
messageToRead : matchedMessage,
|
|
94
95
|
expectedGrantor : tenant,
|
|
95
|
-
expectedGrantee :
|
|
96
|
+
expectedGrantee : requester,
|
|
96
97
|
permissionGrants,
|
|
97
98
|
validationStateReader : deps.validationStateReader
|
|
98
99
|
});
|
|
@@ -63,8 +63,8 @@ export class MessagesSubscribeHandler implements MethodHandler {
|
|
|
63
63
|
|
|
64
64
|
const guardedHandler = MessagesSubscribeHandler.createAuthorizationGuard({
|
|
65
65
|
authorization,
|
|
66
|
+
deps: this.deps,
|
|
66
67
|
messagesSubscribe,
|
|
67
|
-
validationStateReader: this.deps.validationStateReader,
|
|
68
68
|
subscriptionHandler,
|
|
69
69
|
});
|
|
70
70
|
|
|
@@ -100,39 +100,31 @@ export class MessagesSubscribeHandler implements MethodHandler {
|
|
|
100
100
|
messagesSubscribe: MessagesSubscribe,
|
|
101
101
|
deps: HandlerDependencies
|
|
102
102
|
): Promise<MessagesSubscribeAuthorization> {
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
const grantSet = await MessagesGrantAuthorization.authorizeQueryOrSubscribeInvocation({
|
|
104
|
+
tenant : tenant,
|
|
105
|
+
incomingMessage : messagesSubscribe.message,
|
|
106
|
+
validationStateReader : deps.validationStateReader,
|
|
107
|
+
failureCode : DwnErrorCode.MessagesSubscribeAuthorizationFailed,
|
|
108
|
+
});
|
|
109
|
+
if (grantSet === undefined) {
|
|
105
110
|
return { kind: 'owner' };
|
|
106
111
|
}
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
expectedGrantee : messagesSubscribe.author,
|
|
115
|
-
permissionGrants,
|
|
116
|
-
validationStateReader : deps.validationStateReader
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
kind : 'delegate',
|
|
120
|
-
expectedGrantor : tenant,
|
|
121
|
-
expectedGrantee : messagesSubscribe.author,
|
|
122
|
-
permissionGrants,
|
|
123
|
-
};
|
|
124
|
-
} else {
|
|
125
|
-
throw new DwnError(DwnErrorCode.MessagesSubscribeAuthorizationFailed, 'message failed authorization');
|
|
126
|
-
}
|
|
113
|
+
return {
|
|
114
|
+
kind : 'delegate',
|
|
115
|
+
expectedGrantor : tenant,
|
|
116
|
+
expectedGrantee : grantSet.requester,
|
|
117
|
+
permissionGrants : grantSet.permissionGrants,
|
|
118
|
+
};
|
|
127
119
|
}
|
|
128
120
|
|
|
129
121
|
private static createAuthorizationGuard(input: {
|
|
130
122
|
authorization: MessagesSubscribeAuthorization;
|
|
123
|
+
deps: HandlerDependencies;
|
|
131
124
|
messagesSubscribe: MessagesSubscribe;
|
|
132
|
-
validationStateReader: HandlerDependencies['validationStateReader'];
|
|
133
125
|
subscriptionHandler: SubscriptionListener;
|
|
134
126
|
}): GuardedSubscriptionHandler {
|
|
135
|
-
const { authorization,
|
|
127
|
+
const { authorization, deps, messagesSubscribe, subscriptionHandler } = input;
|
|
136
128
|
if (authorization.kind === 'owner') {
|
|
137
129
|
return {
|
|
138
130
|
listener : subscriptionHandler,
|
|
@@ -153,7 +145,7 @@ export class MessagesSubscribeHandler implements MethodHandler {
|
|
|
153
145
|
Promise.resolve(subscription?.close()).catch(() => {});
|
|
154
146
|
};
|
|
155
147
|
|
|
156
|
-
const
|
|
148
|
+
const emitTerminalDeliveryError = (cursor: SubscriptionEvent['cursor'], code: DwnErrorCode, detail: string): void => {
|
|
157
149
|
if (terminalErrorEmitted) {
|
|
158
150
|
return;
|
|
159
151
|
}
|
|
@@ -162,8 +154,8 @@ export class MessagesSubscribeHandler implements MethodHandler {
|
|
|
162
154
|
type : 'error',
|
|
163
155
|
cursor,
|
|
164
156
|
error : {
|
|
165
|
-
code
|
|
166
|
-
detail
|
|
157
|
+
code,
|
|
158
|
+
detail,
|
|
167
159
|
},
|
|
168
160
|
});
|
|
169
161
|
};
|
|
@@ -181,11 +173,23 @@ export class MessagesSubscribeHandler implements MethodHandler {
|
|
|
181
173
|
expectedGrantor : authorization.expectedGrantor,
|
|
182
174
|
expectedGrantee : authorization.expectedGrantee,
|
|
183
175
|
permissionGrants : authorization.permissionGrants,
|
|
184
|
-
validationStateReader,
|
|
176
|
+
validationStateReader : deps.validationStateReader,
|
|
185
177
|
deliveryTimestamp : Time.getCurrentTimestamp(),
|
|
186
178
|
});
|
|
187
|
-
} catch {
|
|
188
|
-
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof DwnError) {
|
|
181
|
+
emitTerminalDeliveryError(
|
|
182
|
+
subMessage.cursor,
|
|
183
|
+
DwnErrorCode.MessagesSubscribeDeliveryAuthorizationFailed,
|
|
184
|
+
'subscription authorization failed during delivery',
|
|
185
|
+
);
|
|
186
|
+
} else {
|
|
187
|
+
emitTerminalDeliveryError(
|
|
188
|
+
subMessage.cursor,
|
|
189
|
+
DwnErrorCode.MessagesSubscribeDeliveryFailed,
|
|
190
|
+
'subscription delivery failed',
|
|
191
|
+
);
|
|
192
|
+
}
|
|
189
193
|
closeSubscription();
|
|
190
194
|
return;
|
|
191
195
|
}
|
|
@@ -126,8 +126,7 @@ export class ProtocolsConfigureHandler implements MethodHandler {
|
|
|
126
126
|
// re-index previously-latest messages as no longer the latest base state.
|
|
127
127
|
for (const existingMessage of existingMessages) {
|
|
128
128
|
if (existingMessage !== newestMessage) {
|
|
129
|
-
const
|
|
130
|
-
const updatedIndexes = ProtocolsConfigureHandler.constructIndexes(existingProtocolsConfigure, false);
|
|
129
|
+
const updatedIndexes = ProtocolsConfigureHandler.constructIndexesFromMessage(existingMessage as ProtocolsConfigureMessage, false);
|
|
131
130
|
const existingCid = await Message.getCid(existingMessage);
|
|
132
131
|
|
|
133
132
|
await this.deps.messageStore.updateIndexes(tenant, existingCid, updatedIndexes);
|
|
@@ -140,9 +139,13 @@ export class ProtocolsConfigureHandler implements MethodHandler {
|
|
|
140
139
|
};
|
|
141
140
|
|
|
142
141
|
static constructIndexes(protocolsConfigure: ProtocolsConfigure, isLatestBaseState: boolean): { [key: string]: string | boolean } {
|
|
142
|
+
return ProtocolsConfigureHandler.constructIndexesFromMessage(protocolsConfigure.message, isLatestBaseState);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private static constructIndexesFromMessage(message: ProtocolsConfigureMessage, isLatestBaseState: boolean): { [key: string]: string | boolean } {
|
|
143
146
|
// strip out `definition` as it is not indexable
|
|
144
|
-
const { definition, ...propertiesToIndex } =
|
|
145
|
-
const
|
|
147
|
+
const { definition, ...propertiesToIndex } = message.descriptor;
|
|
148
|
+
const author = Message.getAuthor(message);
|
|
146
149
|
|
|
147
150
|
const indexes: { [key: string]: string | boolean } = {
|
|
148
151
|
...propertiesToIndex,
|