@enbox/dwn-sdk-js 0.4.6 → 0.4.8
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 +2324 -1525
- 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 +29 -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 +8 -11
- 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 +60 -270
- 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 +187 -452
- 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/encryption/wrapped-grant-key-envelope.spec.js +43 -0
- package/dist/esm/tests/validation/json-schemas/encryption/wrapped-grant-key-envelope.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 +20 -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 +29 -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 +12 -18
- 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 +15 -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/dist/types/tests/validation/json-schemas/encryption/wrapped-grant-key-envelope.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/encryption/wrapped-grant-key-envelope.spec.d.ts.map +1 -0
- package/package.json +47 -28
- package/src/core/constants.ts +61 -0
- package/src/core/dwn-error.ts +29 -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 +50 -22
- 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 +94 -411
- 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,6 +1,6 @@
|
|
|
1
1
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
2
2
|
import { describe, expect, it } from 'bun:test';
|
|
3
|
-
import {
|
|
3
|
+
import { DwnConstant, DwnErrorCode, DwnInterfaceName, DwnMethodName, Encoder, Encryption, EncryptionProtocol, Jws, KeyAgreementAlgorithm, KeyDerivationScheme, RecordsWrite, Time, WRAPPED_GRANT_KEY_FORMAT, } from '../../src/index.js';
|
|
4
4
|
describe('EncryptionProtocol', () => {
|
|
5
5
|
it('should expose the encryption protocol uri and definition', () => {
|
|
6
6
|
const encryptionProtocol = new EncryptionProtocol();
|
|
@@ -20,388 +20,175 @@ describe('EncryptionProtocol', () => {
|
|
|
20
20
|
const encryptionProtocol = new EncryptionProtocol();
|
|
21
21
|
await encryptionProtocol.preProcessWrite(alice.did, recordsWrite.message, createValidationStateReader({}));
|
|
22
22
|
});
|
|
23
|
-
it('should accept
|
|
24
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
25
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
26
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
27
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey);
|
|
28
|
-
const message = await createAudienceEpochMessage({
|
|
29
|
-
protocol,
|
|
30
|
-
role: 'chat/member',
|
|
31
|
-
contextId: 'chat1',
|
|
32
|
-
epoch: 1,
|
|
33
|
-
publicKeyJwk: rolePublicKey,
|
|
34
|
-
signer: Jws.createSigner(alice),
|
|
35
|
-
});
|
|
36
|
-
const encryptionProtocol = new EncryptionProtocol();
|
|
37
|
-
await encryptionProtocol.preProcessWrite(alice.did, message, createValidationStateReader({ protocolDefinition }));
|
|
38
|
-
});
|
|
39
|
-
it('should reject audienceEpoch records that are encrypted', async () => {
|
|
40
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
41
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
42
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
43
|
-
const message = await createAudienceEpochMessage({
|
|
44
|
-
protocol,
|
|
45
|
-
role: 'chat/member',
|
|
46
|
-
contextId: 'chat1',
|
|
47
|
-
epoch: 1,
|
|
48
|
-
publicKeyJwk: rolePublicKey,
|
|
49
|
-
signer: Jws.createSigner(alice),
|
|
50
|
-
});
|
|
51
|
-
message.encryption = createTestEncryptionProperty();
|
|
52
|
-
const encryptionProtocol = new EncryptionProtocol();
|
|
53
|
-
await expect(encryptionProtocol.preProcessWrite(alice.did, message, createValidationStateReader({}))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateAudienceEpochEncrypted);
|
|
54
|
-
});
|
|
55
|
-
it('should reject audienceEpoch records with missing required tags', async () => {
|
|
23
|
+
it('should accept grantKey records covered by an ancestor protocolPath read grant', async () => {
|
|
56
24
|
const alice = await TestDataGenerator.generatePersona();
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
25
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
26
|
+
const protocol = 'https://example.com/protocol';
|
|
27
|
+
const grant = createGrant({
|
|
28
|
+
grantor: alice.did,
|
|
29
|
+
grantee: bob.did,
|
|
30
|
+
id: 'grant1',
|
|
60
31
|
protocol,
|
|
61
|
-
|
|
62
|
-
contextId: 'chat1',
|
|
63
|
-
epoch: 1,
|
|
64
|
-
publicKeyJwk: rolePublicKey,
|
|
65
|
-
signer: Jws.createSigner(alice),
|
|
32
|
+
protocolPath: 'message',
|
|
66
33
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
await expect(encryptionProtocol.preProcessWrite(alice.did, message, createValidationStateReader({}))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateAudienceMissingRequiredTag);
|
|
70
|
-
});
|
|
71
|
-
it('should reject audienceEpoch records with malformed integer tags', async () => {
|
|
72
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
73
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
74
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
75
|
-
const message = await createAudienceEpochMessage({
|
|
34
|
+
const message = await createGrantKeyMessage({
|
|
35
|
+
grant,
|
|
76
36
|
protocol,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
epoch: 1,
|
|
80
|
-
publicKeyJwk: rolePublicKey,
|
|
37
|
+
protocolPath: 'message/reply',
|
|
38
|
+
recipient: bob.did,
|
|
81
39
|
signer: Jws.createSigner(alice),
|
|
82
40
|
});
|
|
83
|
-
message.descriptor.tags.epoch = '1';
|
|
84
41
|
const encryptionProtocol = new EncryptionProtocol();
|
|
85
|
-
await
|
|
42
|
+
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }));
|
|
86
43
|
});
|
|
87
|
-
it('should reject
|
|
44
|
+
it('should reject plaintext grantKey records whose data cannot be inline validated', async () => {
|
|
88
45
|
const alice = await TestDataGenerator.generatePersona();
|
|
46
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
89
47
|
const protocol = 'https://example.com/protocol/chat';
|
|
90
|
-
const
|
|
91
|
-
|
|
48
|
+
const grant = createGrant({
|
|
49
|
+
grantor: alice.did,
|
|
50
|
+
grantee: bob.did,
|
|
51
|
+
id: 'grant1',
|
|
92
52
|
protocol,
|
|
93
|
-
role: 'chat/member',
|
|
94
|
-
contextId: '',
|
|
95
|
-
epoch: 1,
|
|
96
|
-
publicKeyJwk: rolePublicKey,
|
|
97
|
-
signer: Jws.createSigner(alice),
|
|
98
|
-
});
|
|
99
|
-
const encryptionProtocol = new EncryptionProtocol();
|
|
100
|
-
await expect(encryptionProtocol.preProcessWrite(alice.did, message, createValidationStateReader({}))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateRoleAudienceContextInvalid);
|
|
101
|
-
});
|
|
102
|
-
it('should accept same-coordinate audienceEpoch records with different keyIds', async () => {
|
|
103
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
104
|
-
const other = await TestDataGenerator.generatePersona();
|
|
105
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
106
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
107
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey);
|
|
108
|
-
const conflictingEpoch = await createAudienceEpochMessage({
|
|
109
|
-
protocol,
|
|
110
|
-
role: 'chat/member',
|
|
111
|
-
contextId: 'chat1',
|
|
112
|
-
epoch: 1,
|
|
113
|
-
publicKeyJwk: other.encryptionKeyPair.publicJwk,
|
|
114
|
-
signer: Jws.createSigner(other),
|
|
115
|
-
});
|
|
116
|
-
const message = await createAudienceEpochMessage({
|
|
117
|
-
protocol,
|
|
118
|
-
role: 'chat/member',
|
|
119
|
-
contextId: 'chat1',
|
|
120
|
-
epoch: 1,
|
|
121
|
-
publicKeyJwk: rolePublicKey,
|
|
122
|
-
signer: Jws.createSigner(alice),
|
|
123
|
-
});
|
|
124
|
-
const encryptionProtocol = new EncryptionProtocol();
|
|
125
|
-
await encryptionProtocol.preProcessWrite(alice.did, message, createValidationStateReader({
|
|
126
|
-
audienceEpochs: [conflictingEpoch],
|
|
127
|
-
protocolDefinition,
|
|
128
|
-
}));
|
|
129
|
-
});
|
|
130
|
-
it('should reject audienceEpoch records authored by DIDs that cannot create the role', async () => {
|
|
131
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
132
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
133
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
134
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey, { memberActions: [] });
|
|
135
|
-
const message = await createAudienceEpochMessage({
|
|
136
|
-
protocol,
|
|
137
|
-
role: 'chat/member',
|
|
138
|
-
contextId: 'chat1',
|
|
139
|
-
epoch: 1,
|
|
140
|
-
publicKeyJwk: rolePublicKey,
|
|
141
|
-
signer: Jws.createSigner(alice),
|
|
142
53
|
});
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
it('should accept audienceEpoch records authored through an active local role', async () => {
|
|
147
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
148
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
149
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
150
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey, {
|
|
151
|
-
memberActions: [{ can: ['create'], role: 'chat/admin' }],
|
|
152
|
-
});
|
|
153
|
-
const message = await createAudienceEpochMessage({
|
|
54
|
+
const message = await createGrantKeyMessage({
|
|
55
|
+
encrypted: false,
|
|
56
|
+
grant,
|
|
154
57
|
protocol,
|
|
155
|
-
|
|
156
|
-
contextId: 'chat1',
|
|
157
|
-
epoch: 1,
|
|
158
|
-
publicKeyJwk: rolePublicKey,
|
|
58
|
+
recipient: bob.did,
|
|
159
59
|
signer: Jws.createSigner(alice),
|
|
160
|
-
protocolRole: 'chat/admin',
|
|
161
60
|
});
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
input.recipient === alice.did &&
|
|
168
|
-
input.contextIdPrefix === 'chat1';
|
|
61
|
+
const largePlaintextMessage = {
|
|
62
|
+
...message,
|
|
63
|
+
descriptor: {
|
|
64
|
+
...message.descriptor,
|
|
65
|
+
dataSize: DwnConstant.maxDataSizeAllowedToBeEncoded + 1,
|
|
169
66
|
},
|
|
170
|
-
|
|
171
|
-
}));
|
|
172
|
-
});
|
|
173
|
-
it('should reject audienceEpoch records when the invoked role does not match the create rule', async () => {
|
|
174
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
175
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
176
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
177
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey, {
|
|
178
|
-
memberActions: [{ can: ['create'], role: 'chat/admin' }],
|
|
179
|
-
});
|
|
180
|
-
const message = await createAudienceEpochMessage({
|
|
181
|
-
protocol,
|
|
182
|
-
role: 'chat/member',
|
|
183
|
-
contextId: 'chat1',
|
|
184
|
-
epoch: 1,
|
|
185
|
-
publicKeyJwk: rolePublicKey,
|
|
186
|
-
signer: Jws.createSigner(alice),
|
|
187
|
-
protocolRole: 'chat/moderator',
|
|
188
|
-
});
|
|
67
|
+
};
|
|
189
68
|
const encryptionProtocol = new EncryptionProtocol();
|
|
190
|
-
await expect(encryptionProtocol.preProcessWrite('did:example:tenant',
|
|
69
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', largePlaintextMessage, createValidationStateReader({ grant }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateEncryptedDeliveryMissingEncryption);
|
|
191
70
|
});
|
|
192
|
-
it('should accept
|
|
71
|
+
it('should accept read-grant grantKey records for referenced role paths outside the read subtree', async () => {
|
|
193
72
|
const alice = await TestDataGenerator.generatePersona();
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
const protocolDefinition =
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
protocol,
|
|
203
|
-
role: 'chat/member',
|
|
204
|
-
contextId: 'chat1',
|
|
205
|
-
epoch: 1,
|
|
206
|
-
publicKeyJwk: rolePublicKey,
|
|
207
|
-
signer: Jws.createSigner(alice),
|
|
208
|
-
protocolRole: 'roles:admin',
|
|
209
|
-
});
|
|
210
|
-
const encryptionProtocol = new EncryptionProtocol();
|
|
211
|
-
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({
|
|
212
|
-
hasMatchingRoleRecord: (input) => {
|
|
213
|
-
return input.protocol === roleProtocol &&
|
|
214
|
-
input.protocolPath === 'admin' &&
|
|
215
|
-
input.recipient === alice.did &&
|
|
216
|
-
input.contextIdPrefix === undefined;
|
|
217
|
-
},
|
|
218
|
-
protocolDefinition,
|
|
219
|
-
}));
|
|
220
|
-
});
|
|
221
|
-
it('should reject audienceEpoch records that invoke a cross-protocol role with an unknown alias', async () => {
|
|
222
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
223
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
224
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
225
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey, {
|
|
226
|
-
memberActions: [{ can: ['create'], role: 'roles:admin' }],
|
|
227
|
-
});
|
|
228
|
-
const message = await createAudienceEpochMessage({
|
|
73
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
74
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
75
|
+
const protocol = 'https://example.com/protocol';
|
|
76
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey);
|
|
77
|
+
const grant = createGrant({
|
|
78
|
+
grantor: alice.did,
|
|
79
|
+
grantee: bob.did,
|
|
80
|
+
id: 'grant1',
|
|
229
81
|
protocol,
|
|
230
|
-
|
|
231
|
-
contextId: 'chat1',
|
|
232
|
-
epoch: 1,
|
|
233
|
-
publicKeyJwk: rolePublicKey,
|
|
234
|
-
signer: Jws.createSigner(alice),
|
|
235
|
-
protocolRole: 'roles:admin',
|
|
82
|
+
protocolPath: 'chat/message',
|
|
236
83
|
});
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
242
|
-
const bob = await TestDataGenerator.generatePersona();
|
|
243
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
244
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
245
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey);
|
|
246
|
-
const message = await createAudienceKeyMessage({
|
|
247
|
-
protocol,
|
|
248
|
-
role: 'chat/member',
|
|
249
|
-
contextId: 'chat1',
|
|
250
|
-
epoch: 1,
|
|
251
|
-
publicKeyJwk: rolePublicKey,
|
|
84
|
+
const message = await createGrantKeyMessage({
|
|
85
|
+
grant,
|
|
86
|
+
protocol,
|
|
87
|
+
protocolPath: 'chat/member',
|
|
252
88
|
recipient: bob.did,
|
|
253
89
|
signer: Jws.createSigner(alice),
|
|
254
90
|
});
|
|
255
91
|
const encryptionProtocol = new EncryptionProtocol();
|
|
256
|
-
await
|
|
257
|
-
audienceEpochs: [],
|
|
258
|
-
hasMatchingRole: true,
|
|
259
|
-
protocolDefinition,
|
|
260
|
-
}))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateAudienceEpochMissing);
|
|
261
|
-
});
|
|
262
|
-
it('should reject audienceEpoch records for role paths without key agreement', async () => {
|
|
263
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
264
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
265
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
266
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey, { keyAgreement: false });
|
|
267
|
-
const message = await createAudienceEpochMessage({
|
|
268
|
-
protocol,
|
|
269
|
-
role: 'chat/member',
|
|
270
|
-
contextId: 'chat1',
|
|
271
|
-
epoch: 1,
|
|
272
|
-
publicKeyJwk: rolePublicKey,
|
|
273
|
-
signer: Jws.createSigner(alice),
|
|
274
|
-
});
|
|
275
|
-
const encryptionProtocol = new EncryptionProtocol();
|
|
276
|
-
await expect(encryptionProtocol.preProcessWrite(alice.did, message, createValidationStateReader({ protocolDefinition }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateRoleAudienceInvalid);
|
|
92
|
+
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }));
|
|
277
93
|
});
|
|
278
|
-
it('should
|
|
94
|
+
it('should reject read-grant grantKey records for unreferenced role paths outside the read subtree', async () => {
|
|
279
95
|
const alice = await TestDataGenerator.generatePersona();
|
|
280
96
|
const bob = await TestDataGenerator.generatePersona();
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
const protocolDefinition =
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
signer: Jws.createSigner(alice),
|
|
97
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
98
|
+
const protocol = 'https://example.com/protocol';
|
|
99
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey);
|
|
100
|
+
const grant = createGrant({
|
|
101
|
+
grantor: alice.did,
|
|
102
|
+
grantee: bob.did,
|
|
103
|
+
id: 'grant1',
|
|
104
|
+
protocol,
|
|
105
|
+
protocolPath: 'chat/message',
|
|
291
106
|
});
|
|
292
|
-
const message = await
|
|
107
|
+
const message = await createGrantKeyMessage({
|
|
108
|
+
grant,
|
|
293
109
|
protocol,
|
|
294
|
-
|
|
295
|
-
contextId: 'chat1',
|
|
296
|
-
epoch: 1,
|
|
297
|
-
publicKeyJwk: rolePublicKey,
|
|
110
|
+
protocolPath: 'chat/admin',
|
|
298
111
|
recipient: bob.did,
|
|
299
112
|
signer: Jws.createSigner(alice),
|
|
300
113
|
});
|
|
301
114
|
const encryptionProtocol = new EncryptionProtocol();
|
|
302
|
-
await encryptionProtocol.preProcessWrite(
|
|
303
|
-
audienceEpochs: [audienceEpoch],
|
|
304
|
-
hasMatchingRole: true,
|
|
305
|
-
protocolDefinition,
|
|
306
|
-
}));
|
|
115
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
307
116
|
});
|
|
308
|
-
it('should reject
|
|
117
|
+
it('should reject read-grant grantKey records for cross-protocol role references', async () => {
|
|
309
118
|
const alice = await TestDataGenerator.generatePersona();
|
|
310
119
|
const bob = await TestDataGenerator.generatePersona();
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
contextId: 'chat1',
|
|
317
|
-
epoch: 1,
|
|
318
|
-
publicKeyJwk: rolePublicKey,
|
|
319
|
-
recipient: bob.did,
|
|
320
|
-
signer: Jws.createSigner(alice),
|
|
321
|
-
encrypted: false,
|
|
120
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
121
|
+
const protocol = 'https://example.com/protocol';
|
|
122
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey, {
|
|
123
|
+
messageRole: 'contacts:member',
|
|
124
|
+
uses: { contacts: 'https://example.com/contacts' },
|
|
322
125
|
});
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const rolePublicKey = alice.encryptionKeyPair.publicJwk;
|
|
330
|
-
const protocolDefinition = createRoleProtocolDefinition(protocol, rolePublicKey);
|
|
331
|
-
const audienceEpoch = await createAudienceEpochMessage({
|
|
332
|
-
protocol,
|
|
333
|
-
role: 'chat/member',
|
|
334
|
-
contextId: 'chat1',
|
|
335
|
-
epoch: 1,
|
|
336
|
-
publicKeyJwk: rolePublicKey,
|
|
337
|
-
signer: Jws.createSigner(alice),
|
|
126
|
+
const grant = createGrant({
|
|
127
|
+
grantor: alice.did,
|
|
128
|
+
grantee: bob.did,
|
|
129
|
+
id: 'grant1',
|
|
130
|
+
protocol,
|
|
131
|
+
protocolPath: 'chat/message',
|
|
338
132
|
});
|
|
339
|
-
const message = await
|
|
133
|
+
const message = await createGrantKeyMessage({
|
|
134
|
+
grant,
|
|
340
135
|
protocol,
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
epoch: 1,
|
|
344
|
-
publicKeyJwk: rolePublicKey,
|
|
136
|
+
protocolPath: 'chat/member',
|
|
137
|
+
recipient: bob.did,
|
|
345
138
|
signer: Jws.createSigner(alice),
|
|
346
139
|
});
|
|
347
140
|
const encryptionProtocol = new EncryptionProtocol();
|
|
348
|
-
await expect(encryptionProtocol.preProcessWrite(
|
|
349
|
-
audienceEpochs: [audienceEpoch],
|
|
350
|
-
protocolDefinition,
|
|
351
|
-
}))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateAudienceKeyRecipientMissing);
|
|
141
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
352
142
|
});
|
|
353
|
-
it('should
|
|
143
|
+
it('should accept write-grant grantKey records for covered role paths', async () => {
|
|
354
144
|
const alice = await TestDataGenerator.generatePersona();
|
|
355
145
|
const bob = await TestDataGenerator.generatePersona();
|
|
356
|
-
const
|
|
357
|
-
const
|
|
358
|
-
const protocolDefinition =
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
146
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
147
|
+
const protocol = 'https://example.com/protocol';
|
|
148
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey);
|
|
149
|
+
const grant = createGrant({
|
|
150
|
+
grantor: alice.did,
|
|
151
|
+
grantee: bob.did,
|
|
152
|
+
id: 'grant1',
|
|
153
|
+
method: DwnMethodName.Write,
|
|
154
|
+
protocol,
|
|
155
|
+
protocolPath: 'chat',
|
|
366
156
|
});
|
|
367
|
-
const message = await
|
|
157
|
+
const message = await createGrantKeyMessage({
|
|
158
|
+
grant,
|
|
368
159
|
protocol,
|
|
369
|
-
|
|
370
|
-
contextId: 'chat1',
|
|
371
|
-
epoch: 1,
|
|
372
|
-
publicKeyJwk: rolePublicKey,
|
|
160
|
+
protocolPath: 'chat/member',
|
|
373
161
|
recipient: bob.did,
|
|
374
162
|
signer: Jws.createSigner(alice),
|
|
375
163
|
});
|
|
376
164
|
const encryptionProtocol = new EncryptionProtocol();
|
|
377
|
-
await
|
|
378
|
-
audienceEpochs: [audienceEpoch],
|
|
379
|
-
hasMatchingRole: false,
|
|
380
|
-
protocolDefinition,
|
|
381
|
-
}))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateAudienceKeyRoleRecordMissing);
|
|
165
|
+
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }));
|
|
382
166
|
});
|
|
383
|
-
it('should
|
|
167
|
+
it('should reject write-grant grantKey records for covered non-role paths', async () => {
|
|
384
168
|
const alice = await TestDataGenerator.generatePersona();
|
|
385
169
|
const bob = await TestDataGenerator.generatePersona();
|
|
170
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
386
171
|
const protocol = 'https://example.com/protocol';
|
|
172
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey);
|
|
387
173
|
const grant = createGrant({
|
|
388
174
|
grantor: alice.did,
|
|
389
175
|
grantee: bob.did,
|
|
390
176
|
id: 'grant1',
|
|
177
|
+
method: DwnMethodName.Write,
|
|
391
178
|
protocol,
|
|
392
|
-
protocolPath: '
|
|
179
|
+
protocolPath: 'chat',
|
|
393
180
|
});
|
|
394
181
|
const message = await createGrantKeyMessage({
|
|
395
182
|
grant,
|
|
396
183
|
protocol,
|
|
397
|
-
protocolPath: 'message
|
|
184
|
+
protocolPath: 'chat/message',
|
|
398
185
|
recipient: bob.did,
|
|
399
186
|
signer: Jws.createSigner(alice),
|
|
400
187
|
});
|
|
401
188
|
const encryptionProtocol = new EncryptionProtocol();
|
|
402
|
-
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }));
|
|
189
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
403
190
|
});
|
|
404
|
-
it('should
|
|
191
|
+
it('should reject grantKey records covered only by a Messages read grant', async () => {
|
|
405
192
|
const alice = await TestDataGenerator.generatePersona();
|
|
406
193
|
const bob = await TestDataGenerator.generatePersona();
|
|
407
194
|
const protocol = 'https://example.com/protocol';
|
|
@@ -419,12 +206,14 @@ describe('EncryptionProtocol', () => {
|
|
|
419
206
|
signer: Jws.createSigner(alice),
|
|
420
207
|
});
|
|
421
208
|
const encryptionProtocol = new EncryptionProtocol();
|
|
422
|
-
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }));
|
|
209
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
423
210
|
});
|
|
424
211
|
it('should reject protocol-scoped grantKey records for protocolPath-scoped read grants', async () => {
|
|
425
212
|
const alice = await TestDataGenerator.generatePersona();
|
|
426
213
|
const bob = await TestDataGenerator.generatePersona();
|
|
214
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
427
215
|
const protocol = 'https://example.com/protocol';
|
|
216
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey);
|
|
428
217
|
const grant = createGrant({
|
|
429
218
|
grantor: alice.did,
|
|
430
219
|
grantee: bob.did,
|
|
@@ -439,7 +228,7 @@ describe('EncryptionProtocol', () => {
|
|
|
439
228
|
signer: Jws.createSigner(alice),
|
|
440
229
|
});
|
|
441
230
|
const encryptionProtocol = new EncryptionProtocol();
|
|
442
|
-
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
231
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
443
232
|
});
|
|
444
233
|
it('should reject grantKey records outside the grant protocol', async () => {
|
|
445
234
|
const alice = await TestDataGenerator.generatePersona();
|
|
@@ -462,7 +251,9 @@ describe('EncryptionProtocol', () => {
|
|
|
462
251
|
it('should reject grantKey records outside the grant protocolPath subtree', async () => {
|
|
463
252
|
const alice = await TestDataGenerator.generatePersona();
|
|
464
253
|
const bob = await TestDataGenerator.generatePersona();
|
|
254
|
+
const rolePublicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
465
255
|
const protocol = 'https://example.com/protocol';
|
|
256
|
+
const protocolDefinition = createGrantKeyCoverageProtocolDefinition(protocol, rolePublicKey);
|
|
466
257
|
const grant = createGrant({
|
|
467
258
|
grantor: alice.did,
|
|
468
259
|
grantee: bob.did,
|
|
@@ -478,7 +269,7 @@ describe('EncryptionProtocol', () => {
|
|
|
478
269
|
signer: Jws.createSigner(alice),
|
|
479
270
|
});
|
|
480
271
|
const encryptionProtocol = new EncryptionProtocol();
|
|
481
|
-
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
272
|
+
await expect(encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant, protocolDefinition }))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch);
|
|
482
273
|
});
|
|
483
274
|
it('should reject grantKey records whose recipient is not the grant grantee', async () => {
|
|
484
275
|
const alice = await TestDataGenerator.generatePersona();
|
|
@@ -606,7 +397,7 @@ describe('EncryptionProtocol', () => {
|
|
|
606
397
|
},
|
|
607
398
|
}))).rejects.toThrow(DwnErrorCode.GrantAuthorizationGrantRevoked);
|
|
608
399
|
});
|
|
609
|
-
it('should
|
|
400
|
+
it('should accept grantKey metadata before wrapped envelope data validation', async () => {
|
|
610
401
|
const alice = await TestDataGenerator.generatePersona();
|
|
611
402
|
const bob = await TestDataGenerator.generatePersona();
|
|
612
403
|
const protocol = 'https://example.com/protocol';
|
|
@@ -624,17 +415,17 @@ describe('EncryptionProtocol', () => {
|
|
|
624
415
|
signer: Jws.createSigner(alice),
|
|
625
416
|
});
|
|
626
417
|
const encryptionProtocol = new EncryptionProtocol();
|
|
627
|
-
await
|
|
418
|
+
await encryptionProtocol.preProcessWrite('did:example:tenant', message, createValidationStateReader({ grant }));
|
|
628
419
|
});
|
|
629
|
-
it('should reject grantKey records for
|
|
420
|
+
it('should reject grantKey records for context-scoped permission grants', async () => {
|
|
630
421
|
const alice = await TestDataGenerator.generatePersona();
|
|
631
422
|
const bob = await TestDataGenerator.generatePersona();
|
|
632
423
|
const protocol = 'https://example.com/protocol';
|
|
633
424
|
const grant = createGrant({
|
|
425
|
+
contextId: 'context1',
|
|
634
426
|
grantor: alice.did,
|
|
635
427
|
grantee: bob.did,
|
|
636
428
|
id: 'grant1',
|
|
637
|
-
method: DwnMethodName.Write,
|
|
638
429
|
protocol,
|
|
639
430
|
});
|
|
640
431
|
const message = await createGrantKeyMessage({
|
|
@@ -660,83 +451,75 @@ describe('EncryptionProtocol', () => {
|
|
|
660
451
|
const encryptionProtocol = new EncryptionProtocol();
|
|
661
452
|
await expect(encryptionProtocol.validateRecord(recordsWrite.message, TestDataGenerator.randomBytes(32))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateSchemaUnexpectedRecord);
|
|
662
453
|
});
|
|
663
|
-
it('should reject
|
|
454
|
+
it('should reject unencrypted grantKey records', async () => {
|
|
664
455
|
const alice = await TestDataGenerator.generatePersona();
|
|
665
|
-
const
|
|
456
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
666
457
|
const protocol = 'https://example.com/protocol/chat';
|
|
667
|
-
const
|
|
458
|
+
const grant = createGrant({
|
|
459
|
+
grantor: alice.did,
|
|
460
|
+
grantee: bob.did,
|
|
461
|
+
id: 'grant1',
|
|
668
462
|
protocol,
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
463
|
+
});
|
|
464
|
+
const message = await createGrantKeyMessage({
|
|
465
|
+
encrypted: false,
|
|
466
|
+
grant,
|
|
467
|
+
protocol,
|
|
468
|
+
recipient: bob.did,
|
|
674
469
|
signer: Jws.createSigner(alice),
|
|
675
470
|
});
|
|
676
471
|
const encryptionProtocol = new EncryptionProtocol();
|
|
677
|
-
await expect(encryptionProtocol.validateRecord(message,
|
|
472
|
+
await expect(encryptionProtocol.validateRecord(message, TestDataGenerator.randomBytes(32))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateEncryptedDeliveryMissingEncryption);
|
|
678
473
|
});
|
|
679
|
-
it('should
|
|
474
|
+
it('should accept wrapped grantKey envelope records without Records encryption', async () => {
|
|
680
475
|
const alice = await TestDataGenerator.generatePersona();
|
|
476
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
681
477
|
const protocol = 'https://example.com/protocol/chat';
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
contextId: 'chat1',
|
|
687
|
-
epoch: 1,
|
|
688
|
-
publicKeyJwk: alice.encryptionKeyPair.publicJwk,
|
|
689
|
-
keyId,
|
|
690
|
-
signer: Jws.createSigner(alice),
|
|
691
|
-
});
|
|
692
|
-
const mismatchingPayload = Encoder.objectToBytes({
|
|
478
|
+
const grant = createGrant({
|
|
479
|
+
grantor: alice.did,
|
|
480
|
+
grantee: bob.did,
|
|
481
|
+
id: 'grant1',
|
|
693
482
|
protocol,
|
|
694
|
-
contextId: 'chat2',
|
|
695
|
-
role: 'chat/member',
|
|
696
|
-
epoch: 1,
|
|
697
|
-
keyId,
|
|
698
|
-
publicKeyJwk: alice.encryptionKeyPair.publicJwk,
|
|
699
483
|
});
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
it('should reject encrypted audienceEpoch records', async () => {
|
|
704
|
-
const alice = await TestDataGenerator.generatePersona();
|
|
705
|
-
const protocol = 'https://example.com/protocol/chat';
|
|
706
|
-
const message = await createAudienceEpochMessage({
|
|
484
|
+
const message = await createGrantKeyMessage({
|
|
485
|
+
encrypted: false,
|
|
486
|
+
grant,
|
|
707
487
|
protocol,
|
|
708
|
-
|
|
709
|
-
contextId: 'chat1',
|
|
710
|
-
epoch: 1,
|
|
711
|
-
publicKeyJwk: alice.encryptionKeyPair.publicJwk,
|
|
488
|
+
recipient: bob.did,
|
|
712
489
|
signer: Jws.createSigner(alice),
|
|
713
490
|
});
|
|
714
|
-
message.encryption = createTestEncryptionProperty();
|
|
715
491
|
const encryptionProtocol = new EncryptionProtocol();
|
|
716
|
-
|
|
492
|
+
const keyId = message.descriptor.tags.keyId;
|
|
493
|
+
expect(typeof keyId).toBe('string');
|
|
494
|
+
await encryptionProtocol.validateRecord(message, createWrappedGrantKeyEnvelopeBytes(keyId));
|
|
717
495
|
});
|
|
718
|
-
it('should reject
|
|
496
|
+
it('should reject malformed wrapped grantKey envelopes', async () => {
|
|
719
497
|
const alice = await TestDataGenerator.generatePersona();
|
|
720
498
|
const bob = await TestDataGenerator.generatePersona();
|
|
721
499
|
const protocol = 'https://example.com/protocol/chat';
|
|
722
|
-
const
|
|
500
|
+
const grant = createGrant({
|
|
501
|
+
grantor: alice.did,
|
|
502
|
+
grantee: bob.did,
|
|
503
|
+
id: 'grant1',
|
|
504
|
+
protocol,
|
|
505
|
+
});
|
|
506
|
+
const message = await createGrantKeyMessage({
|
|
507
|
+
encrypted: false,
|
|
508
|
+
grant,
|
|
723
509
|
protocol,
|
|
724
|
-
role: 'chat/member',
|
|
725
|
-
contextId: 'chat1',
|
|
726
|
-
epoch: 1,
|
|
727
|
-
publicKeyJwk: alice.encryptionKeyPair.publicJwk,
|
|
728
510
|
recipient: bob.did,
|
|
729
511
|
signer: Jws.createSigner(alice),
|
|
730
|
-
encrypted: false,
|
|
731
512
|
});
|
|
513
|
+
const envelope = Encoder.bytesToObject(createWrappedGrantKeyEnvelopeBytes(message.descriptor.tags.keyId));
|
|
514
|
+
envelope.keyEncryption.ephemeralPublicKey.x = '';
|
|
732
515
|
const encryptionProtocol = new EncryptionProtocol();
|
|
733
|
-
await expect(encryptionProtocol.validateRecord(message,
|
|
516
|
+
await expect(encryptionProtocol.validateRecord(message, Encoder.objectToBytes(envelope))).rejects.toThrow(DwnErrorCode.EncryptionProtocolValidateGrantKeyWrappedDeliveryInvalid);
|
|
734
517
|
});
|
|
735
518
|
});
|
|
736
519
|
describe('mapErrorToStatusCode()', () => {
|
|
737
520
|
it('should map encryption validation errors to bad request', () => {
|
|
738
521
|
const encryptionProtocol = new EncryptionProtocol();
|
|
739
|
-
expect(encryptionProtocol.mapErrorToStatusCode(DwnErrorCode.
|
|
522
|
+
expect(encryptionProtocol.mapErrorToStatusCode(DwnErrorCode.EncryptionProtocolValidateGrantKeyGrantScopeMismatch)).toBe(400);
|
|
740
523
|
expect(encryptionProtocol.mapErrorToStatusCode(DwnErrorCode.GrantAuthorizationGrantExpired)).toBeUndefined();
|
|
741
524
|
});
|
|
742
525
|
});
|
|
@@ -770,6 +553,7 @@ function createGrant(input) {
|
|
|
770
553
|
interface: input.interface ?? DwnInterfaceName.Records,
|
|
771
554
|
method: input.method ?? DwnMethodName.Read,
|
|
772
555
|
protocol: input.protocol,
|
|
556
|
+
contextId: input.contextId,
|
|
773
557
|
protocolPath: input.protocolPath,
|
|
774
558
|
},
|
|
775
559
|
};
|
|
@@ -780,25 +564,29 @@ function createValidationStateReader(input) {
|
|
|
780
564
|
fetchGrant: async () => input.grant,
|
|
781
565
|
fetchOldestGrantRevocation: async () => input.revocation,
|
|
782
566
|
fetchProtocolDefinition: async () => input.protocolDefinition,
|
|
783
|
-
hasMatchingRoleRecord: async (roleInput) => {
|
|
784
|
-
return input.hasMatchingRoleRecord?.(roleInput) ?? input.hasMatchingRole ?? true;
|
|
785
|
-
},
|
|
786
|
-
queryAudienceEpochs: async () => input.audienceEpochs ?? [],
|
|
787
567
|
};
|
|
788
568
|
}
|
|
789
|
-
function
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
569
|
+
function createWrappedGrantKeyEnvelopeBytes(keyId) {
|
|
570
|
+
return Encoder.objectToBytes({
|
|
571
|
+
format: WRAPPED_GRANT_KEY_FORMAT,
|
|
572
|
+
keyEncryption: {
|
|
573
|
+
algorithm: KeyAgreementAlgorithm.X25519HkdfSha256A256Kw,
|
|
574
|
+
encryptedKey: Encoder.bytesToBase64Url(TestDataGenerator.randomBytes(40)),
|
|
575
|
+
ephemeralPublicKey: {
|
|
576
|
+
crv: 'X25519',
|
|
577
|
+
kty: 'OKP',
|
|
578
|
+
x: Encoder.bytesToBase64Url(TestDataGenerator.randomBytes(32)),
|
|
579
|
+
},
|
|
580
|
+
keyId,
|
|
581
|
+
},
|
|
582
|
+
contentEncryption: {
|
|
583
|
+
algorithm: 'A256CTR',
|
|
584
|
+
initializationVector: Encoder.bytesToBase64Url(TestDataGenerator.randomBytes(16)),
|
|
585
|
+
},
|
|
586
|
+
ciphertext: Encoder.bytesToBase64Url(TestDataGenerator.randomBytes(32)),
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
function createGrantKeyCoverageProtocolDefinition(protocol, publicKeyJwk, options = {}) {
|
|
802
590
|
return {
|
|
803
591
|
published: true,
|
|
804
592
|
protocol,
|
|
@@ -807,73 +595,26 @@ function createRoleProtocolDefinition(protocol, publicKeyJwk, options = {}) {
|
|
|
807
595
|
admin: { dataFormats: ['application/json'] },
|
|
808
596
|
chat: { dataFormats: ['application/json'] },
|
|
809
597
|
member: { dataFormats: ['application/json'] },
|
|
598
|
+
message: { dataFormats: ['application/json'], encryptionRequired: true },
|
|
810
599
|
},
|
|
811
600
|
structure: {
|
|
812
601
|
chat: {
|
|
813
|
-
admin:
|
|
814
|
-
|
|
602
|
+
admin: {
|
|
603
|
+
$keyAgreement: { publicKeyJwk },
|
|
604
|
+
$role: true,
|
|
605
|
+
},
|
|
606
|
+
member: {
|
|
607
|
+
$keyAgreement: { publicKeyJwk },
|
|
608
|
+
$role: true,
|
|
609
|
+
},
|
|
610
|
+
message: {
|
|
611
|
+
$actions: [{ can: ['read'], role: options.messageRole ?? 'chat/member' }],
|
|
612
|
+
$keyAgreement: { publicKeyJwk },
|
|
613
|
+
},
|
|
815
614
|
},
|
|
816
615
|
},
|
|
817
616
|
};
|
|
818
617
|
}
|
|
819
|
-
async function createAudienceEpochMessage(input) {
|
|
820
|
-
const keyId = input.keyId ?? await Encryption.getKeyId(input.publicKeyJwk);
|
|
821
|
-
const data = Encoder.objectToBytes({
|
|
822
|
-
protocol: input.protocol,
|
|
823
|
-
contextId: input.contextId,
|
|
824
|
-
role: input.role,
|
|
825
|
-
epoch: input.epoch,
|
|
826
|
-
keyId,
|
|
827
|
-
publicKeyJwk: input.publicKeyJwk,
|
|
828
|
-
});
|
|
829
|
-
const recordsWrite = await RecordsWrite.create({
|
|
830
|
-
data,
|
|
831
|
-
dataFormat: 'application/json',
|
|
832
|
-
protocol: EncryptionProtocol.uri,
|
|
833
|
-
protocolPath: EncryptionProtocol.audienceEpochPath,
|
|
834
|
-
protocolRole: input.protocolRole,
|
|
835
|
-
signer: input.signer,
|
|
836
|
-
tags: {
|
|
837
|
-
protocol: input.protocol,
|
|
838
|
-
contextId: input.contextId,
|
|
839
|
-
role: input.role,
|
|
840
|
-
epoch: input.epoch,
|
|
841
|
-
keyId,
|
|
842
|
-
},
|
|
843
|
-
});
|
|
844
|
-
return {
|
|
845
|
-
...recordsWrite.message,
|
|
846
|
-
encodedData: Encoder.bytesToBase64Url(data),
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
async function createAudienceKeyMessage(input) {
|
|
850
|
-
const keyId = await Encryption.getKeyId(input.publicKeyJwk);
|
|
851
|
-
const recordsWrite = await RecordsWrite.create({
|
|
852
|
-
data: TestDataGenerator.randomBytes(32),
|
|
853
|
-
dataFormat: 'application/json',
|
|
854
|
-
encryptionInput: input.encrypted === false ? undefined : {
|
|
855
|
-
initializationVector: TestDataGenerator.randomBytes(16),
|
|
856
|
-
key: TestDataGenerator.randomBytes(32),
|
|
857
|
-
keyEncryptionInputs: [{
|
|
858
|
-
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
859
|
-
keyId,
|
|
860
|
-
publicKey: input.publicKeyJwk,
|
|
861
|
-
}],
|
|
862
|
-
},
|
|
863
|
-
protocol: EncryptionProtocol.uri,
|
|
864
|
-
protocolPath: EncryptionProtocol.audienceKeyPath,
|
|
865
|
-
recipient: input.recipient,
|
|
866
|
-
signer: input.signer,
|
|
867
|
-
tags: {
|
|
868
|
-
protocol: input.protocol,
|
|
869
|
-
contextId: input.contextId,
|
|
870
|
-
role: input.role,
|
|
871
|
-
epoch: input.epoch,
|
|
872
|
-
keyId,
|
|
873
|
-
},
|
|
874
|
-
});
|
|
875
|
-
return recordsWrite.message;
|
|
876
|
-
}
|
|
877
618
|
async function createGrantKeyMessage(input) {
|
|
878
619
|
const publicKey = (await TestDataGenerator.generatePersona()).encryptionKeyPair.publicJwk;
|
|
879
620
|
const tags = {
|
|
@@ -891,6 +632,7 @@ async function createGrantKeyMessage(input) {
|
|
|
891
632
|
initializationVector: TestDataGenerator.randomBytes(16),
|
|
892
633
|
key: TestDataGenerator.randomBytes(32),
|
|
893
634
|
keyEncryptionInputs: [{
|
|
635
|
+
algorithm: KeyAgreementAlgorithm.X25519HkdfSha256A256Kw,
|
|
894
636
|
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
895
637
|
keyId: await Encryption.getKeyId(publicKey),
|
|
896
638
|
publicKey,
|
|
@@ -904,11 +646,4 @@ async function createGrantKeyMessage(input) {
|
|
|
904
646
|
});
|
|
905
647
|
return recordsWrite.message;
|
|
906
648
|
}
|
|
907
|
-
function createTestEncryptionProperty() {
|
|
908
|
-
return {
|
|
909
|
-
algorithm: ContentEncryptionAlgorithm.A256CTR,
|
|
910
|
-
initializationVector: Encoder.bytesToBase64Url(TestDataGenerator.randomBytes(16)),
|
|
911
|
-
keyEncryption: [],
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
649
|
//# sourceMappingURL=encryption.spec.js.map
|