@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,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type { Blockstore, Pair } from 'interface-blockstore';
|
|
1
|
+
import type { Blockstore, InputPair, Pair } from 'interface-blockstore';
|
|
2
|
+
import type { BlockstoreAbortOptions, BlockstoreInput, BlockstoreSource } from './blockstore-utils.js';
|
|
4
3
|
|
|
4
|
+
import { CID } from 'multiformats';
|
|
5
|
+
import { NotFoundError } from 'interface-store';
|
|
6
|
+
import {
|
|
7
|
+
collectBlockstoreBytes,
|
|
8
|
+
deleteManyBlockstoreItems,
|
|
9
|
+
getManyBlockstoreItems,
|
|
10
|
+
putManyBlockstoreItems,
|
|
11
|
+
yieldBlockstoreBytes,
|
|
12
|
+
} from './blockstore-utils.js';
|
|
5
13
|
import { createLevelDatabase, LevelWrapper } from './level-wrapper.js';
|
|
6
14
|
|
|
7
15
|
// `level` works in Node.js 12+ and Electron 5+ on Linux, Mac OS, Windows and
|
|
@@ -40,63 +48,51 @@ export class BlockstoreLevel implements Blockstore {
|
|
|
40
48
|
return new BlockstoreLevel({ ...this.config, location: '' }, db);
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
async put(key: CID | string, val:
|
|
44
|
-
await
|
|
51
|
+
async put(key: CID | string, val: BlockstoreInput, options?: BlockstoreAbortOptions): Promise<CID> {
|
|
52
|
+
const bytes = await collectBlockstoreBytes(val);
|
|
53
|
+
await this.db.put(String(key), bytes, options);
|
|
45
54
|
return CID.parse(key.toString());
|
|
46
55
|
}
|
|
47
56
|
|
|
48
|
-
async get(key: CID | string, options?:
|
|
57
|
+
async * get(key: CID | string, options?: BlockstoreAbortOptions): AsyncGenerator<Uint8Array> {
|
|
49
58
|
const result = await this.db.get(String(key), options);
|
|
50
|
-
|
|
59
|
+
if (result === undefined) {
|
|
60
|
+
throw new NotFoundError();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
yield result;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
async has(key: CID | string, options?:
|
|
66
|
+
async has(key: CID | string, options?: BlockstoreAbortOptions): Promise<boolean> {
|
|
54
67
|
return this.db.has(String(key), options);
|
|
55
68
|
}
|
|
56
69
|
|
|
57
|
-
async delete(key: CID | string, options?:
|
|
70
|
+
async delete(key: CID | string, options?: BlockstoreAbortOptions): Promise<void> {
|
|
58
71
|
return this.db.delete(String(key), options);
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
async isEmpty(options?:
|
|
74
|
+
async isEmpty(options?: BlockstoreAbortOptions): Promise<boolean> {
|
|
62
75
|
return this.db.isEmpty(options);
|
|
63
76
|
}
|
|
64
77
|
|
|
65
|
-
async * putMany(source:
|
|
66
|
-
|
|
67
|
-
await this.put(entry.cid, entry.block, options);
|
|
68
|
-
|
|
69
|
-
yield entry.cid;
|
|
70
|
-
}
|
|
78
|
+
async * putMany(source: BlockstoreSource<InputPair>, options?: BlockstoreAbortOptions): AsyncGenerator<CID> {
|
|
79
|
+
yield * putManyBlockstoreItems(this, source, options);
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
async * getMany(source:
|
|
74
|
-
|
|
75
|
-
yield {
|
|
76
|
-
cid : key,
|
|
77
|
-
block : await this.get(key, options)
|
|
78
|
-
};
|
|
79
|
-
}
|
|
82
|
+
async * getMany(source: BlockstoreSource<CID>, options?: BlockstoreAbortOptions): AsyncGenerator<Pair> {
|
|
83
|
+
yield * getManyBlockstoreItems(this, source, options);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
async * getAll(options?:
|
|
83
|
-
|
|
84
|
-
const li: AsyncGenerator<[Uint8Array, Uint8Array]> = this.db.iterator({
|
|
85
|
-
keys : true,
|
|
86
|
-
keyEncoding : 'buffer'
|
|
87
|
-
}, options);
|
|
86
|
+
async * getAll(options?: BlockstoreAbortOptions): AsyncGenerator<Pair> {
|
|
87
|
+
const li: AsyncGenerator<[string, Uint8Array]> = this.db.iterator({ keys: true }, options);
|
|
88
88
|
|
|
89
89
|
for await (const [key, value] of li) {
|
|
90
|
-
yield { cid: CID.
|
|
90
|
+
yield { cid: CID.parse(key), bytes: yieldBlockstoreBytes(value) };
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
async * deleteMany(source:
|
|
95
|
-
|
|
96
|
-
await this.delete(key, options);
|
|
97
|
-
|
|
98
|
-
yield key;
|
|
99
|
-
}
|
|
94
|
+
async * deleteMany(source: BlockstoreSource<CID>, options?: BlockstoreAbortOptions): AsyncGenerator<CID> {
|
|
95
|
+
yield * deleteManyBlockstoreItems(this, source, options);
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
/**
|
|
@@ -110,4 +106,4 @@ export class BlockstoreLevel implements Blockstore {
|
|
|
110
106
|
export type BlockstoreLevelConfig = {
|
|
111
107
|
location: string,
|
|
112
108
|
createLevelDatabase?: typeof createLevelDatabase,
|
|
113
|
-
};
|
|
109
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import { CID } from 'multiformats';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { CID } from 'multiformats';
|
|
2
|
+
import type { Blockstore, InputPair, Pair } from 'interface-blockstore';
|
|
3
|
+
import type { BlockstoreAbortOptions, BlockstoreInput, BlockstoreSource } from './blockstore-utils.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
deleteManyBlockstoreItems,
|
|
7
|
+
getManyBlockstoreItems,
|
|
8
|
+
putManyBlockstoreItems,
|
|
9
|
+
} from './blockstore-utils.js';
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* Mock implementation for the Blockstore interface.
|
|
@@ -16,60 +22,40 @@ export class BlockstoreMock implements Blockstore {
|
|
|
16
22
|
async close(): Promise<void> {
|
|
17
23
|
}
|
|
18
24
|
|
|
19
|
-
async put(key: CID, _val:
|
|
25
|
+
async put(key: CID, _val: BlockstoreInput, _options?: BlockstoreAbortOptions): Promise<CID> {
|
|
20
26
|
return key;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
async get(_key: CID, _options?:
|
|
24
|
-
|
|
29
|
+
async * get(_key: CID, _options?: BlockstoreAbortOptions): AsyncGenerator<Uint8Array> {
|
|
30
|
+
yield new Uint8Array();
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
async has(_key: CID, _options?:
|
|
33
|
+
async has(_key: CID, _options?: BlockstoreAbortOptions): Promise<boolean> {
|
|
28
34
|
return false;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
async delete(_key: CID, _options?:
|
|
37
|
+
async delete(_key: CID, _options?: BlockstoreAbortOptions): Promise<void> {
|
|
38
|
+
return;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
async isEmpty(_options?:
|
|
41
|
+
async isEmpty(_options?: BlockstoreAbortOptions): Promise<boolean> {
|
|
35
42
|
return true;
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
async * putMany(source:
|
|
39
|
-
|
|
40
|
-
await this.put(entry.cid, entry.block, options);
|
|
41
|
-
|
|
42
|
-
yield entry.cid;
|
|
43
|
-
}
|
|
45
|
+
async * putMany(source: BlockstoreSource<InputPair>, options?: BlockstoreAbortOptions): AsyncGenerator<CID> {
|
|
46
|
+
yield * putManyBlockstoreItems(this, source, options);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
async * getMany(source:
|
|
47
|
-
|
|
48
|
-
yield {
|
|
49
|
-
cid : key,
|
|
50
|
-
block : await this.get(key, options)
|
|
51
|
-
};
|
|
52
|
-
}
|
|
49
|
+
async * getMany(source: BlockstoreSource<CID>, options?: BlockstoreAbortOptions): AsyncGenerator<Pair> {
|
|
50
|
+
yield * getManyBlockstoreItems(this, source, options);
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
async * getAll(
|
|
56
|
-
|
|
57
|
-
const li: AsyncGenerator<[Uint8Array, Uint8Array]> = this.db.iterator({
|
|
58
|
-
keys : true,
|
|
59
|
-
keyEncoding : 'buffer'
|
|
60
|
-
}, options);
|
|
61
|
-
|
|
62
|
-
for await (const [key, value] of li) {
|
|
63
|
-
yield { cid: CID.decode(key), block: value };
|
|
64
|
-
}
|
|
53
|
+
async * getAll(_options?: BlockstoreAbortOptions): AsyncGenerator<Pair> {
|
|
54
|
+
yield * [];
|
|
65
55
|
}
|
|
66
56
|
|
|
67
|
-
async * deleteMany(source:
|
|
68
|
-
|
|
69
|
-
await this.delete(key, options);
|
|
70
|
-
|
|
71
|
-
yield key;
|
|
72
|
-
}
|
|
57
|
+
async * deleteMany(source: BlockstoreSource<CID>, options?: BlockstoreAbortOptions): AsyncGenerator<CID> {
|
|
58
|
+
yield * deleteManyBlockstoreItems(this, source, options);
|
|
73
59
|
}
|
|
74
60
|
|
|
75
61
|
/**
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { CID } from 'multiformats';
|
|
2
|
+
import type { InputPair, Pair } from 'interface-blockstore';
|
|
3
|
+
|
|
4
|
+
export type BlockstoreAbortOptions = { signal?: AbortSignal };
|
|
5
|
+
export type BlockstoreInput = Uint8Array | Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
6
|
+
export type BlockstoreSource<T> = Iterable<T> | AsyncIterable<T>;
|
|
7
|
+
|
|
8
|
+
type BlockstorePutDelegate = {
|
|
9
|
+
put(key: CID, val: BlockstoreInput, options?: BlockstoreAbortOptions): Promise<CID>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type BlockstoreGetDelegate = {
|
|
13
|
+
get(key: CID, options?: BlockstoreAbortOptions): AsyncGenerator<Uint8Array>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type BlockstoreDeleteDelegate = {
|
|
17
|
+
delete(key: CID, options?: BlockstoreAbortOptions): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function collectBlockstoreBytes(input: BlockstoreInput): Promise<Uint8Array> {
|
|
21
|
+
if (input instanceof Uint8Array) {
|
|
22
|
+
return input;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const chunks: Uint8Array[] = [];
|
|
26
|
+
let byteLength = 0;
|
|
27
|
+
for await (const chunk of input) {
|
|
28
|
+
chunks.push(chunk);
|
|
29
|
+
byteLength += chunk.byteLength;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (chunks.length === 1) {
|
|
33
|
+
return chunks[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const bytes = new Uint8Array(byteLength);
|
|
37
|
+
let offset = 0;
|
|
38
|
+
for (const chunk of chunks) {
|
|
39
|
+
bytes.set(chunk, offset);
|
|
40
|
+
offset += chunk.byteLength;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return bytes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function* yieldBlockstoreBytes(bytes: Uint8Array): AsyncGenerator<Uint8Array> {
|
|
47
|
+
yield bytes;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function* putManyBlockstoreItems(
|
|
51
|
+
blockstore: BlockstorePutDelegate,
|
|
52
|
+
source: BlockstoreSource<InputPair>,
|
|
53
|
+
options?: BlockstoreAbortOptions,
|
|
54
|
+
): AsyncGenerator<CID> {
|
|
55
|
+
for await (const entry of source) {
|
|
56
|
+
await blockstore.put(entry.cid, entry.bytes, options);
|
|
57
|
+
|
|
58
|
+
yield entry.cid;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function* getManyBlockstoreItems(
|
|
63
|
+
blockstore: BlockstoreGetDelegate,
|
|
64
|
+
source: BlockstoreSource<CID>,
|
|
65
|
+
options?: BlockstoreAbortOptions,
|
|
66
|
+
): AsyncGenerator<Pair> {
|
|
67
|
+
for await (const key of source) {
|
|
68
|
+
yield {
|
|
69
|
+
cid : key,
|
|
70
|
+
bytes : blockstore.get(key, options),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function* deleteManyBlockstoreItems(
|
|
76
|
+
blockstore: BlockstoreDeleteDelegate,
|
|
77
|
+
source: BlockstoreSource<CID>,
|
|
78
|
+
options?: BlockstoreAbortOptions,
|
|
79
|
+
): AsyncGenerator<CID> {
|
|
80
|
+
for await (const key of source) {
|
|
81
|
+
await blockstore.delete(key, options);
|
|
82
|
+
|
|
83
|
+
yield key;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export {
|
|
2
|
+
collectBlockstoreBytes,
|
|
3
|
+
deleteManyBlockstoreItems,
|
|
4
|
+
getManyBlockstoreItems,
|
|
5
|
+
putManyBlockstoreItems,
|
|
6
|
+
yieldBlockstoreBytes,
|
|
7
|
+
} from './blockstore-utils.js';
|
|
8
|
+
export type { BlockstoreAbortOptions, BlockstoreInput, BlockstoreSource } from './blockstore-utils.js';
|
|
@@ -118,18 +118,11 @@ export class DataStoreLevel implements DataStore {
|
|
|
118
118
|
|
|
119
119
|
// Data is chunked into DAG-PB UnixFS blocks. Re-inflate the chunks.
|
|
120
120
|
const dataDagRoot = await exporter(dataCid, blocksPartition);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (result.done) {
|
|
127
|
-
controller.close();
|
|
128
|
-
} else {
|
|
129
|
-
controller.enqueue(result.value);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
121
|
+
if (dataDagRoot.type !== 'file' && dataDagRoot.type !== 'raw' && dataDagRoot.type !== 'identity') {
|
|
122
|
+
throw new Error(`DataStoreLevel: Expected UnixFS file content for '${dataCid}', got '${dataDagRoot.type}'.`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const dataStream = DataStream.fromAsyncIterable(dataDagRoot.content());
|
|
133
126
|
|
|
134
127
|
return { dataSize, dataStream };
|
|
135
128
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { BlockstoreLevel } from './blockstore-level.js';
|
|
2
|
+
export type { BlockstoreLevelConfig } from './blockstore-level.js';
|
|
3
|
+
export { DataStoreLevel } from './data-store-level.js';
|
|
4
|
+
export type { DataStoreLevelConfig } from './data-store-level.js';
|
|
5
|
+
export { IndexLevel } from './index-level.js';
|
|
6
|
+
export type { CompoundIndexDefinition, IndexLevelConfig, IndexedItem, IndexLevelOptions } from './index-level.js';
|
|
7
|
+
export { createLevelDatabase, LevelWrapper } from './level-wrapper.js';
|
|
8
|
+
export type {
|
|
9
|
+
CreateLevelDatabaseOptions,
|
|
10
|
+
LevelDatabase,
|
|
11
|
+
LevelWrapperBatchOperation,
|
|
12
|
+
LevelWrapperConfig,
|
|
13
|
+
LevelWrapperIteratorOptions,
|
|
14
|
+
LevelWrapperOptions,
|
|
15
|
+
} from './level-wrapper.js';
|
|
16
|
+
export { MessageStoreLevel } from './message-store-level.js';
|
|
17
|
+
export type { MessageStoreLevelConfig } from './message-store-level.js';
|
|
18
|
+
export { ResumableTaskStoreLevel } from './resumable-task-store-level.js';
|
|
19
|
+
export type { ResumableTaskStoreLevelConfig } from './resumable-task-store-level.js';
|
package/src/types/cache.ts
CHANGED
|
@@ -6,11 +6,11 @@ export interface Cache {
|
|
|
6
6
|
/**
|
|
7
7
|
* Sets a key-value pair. Does not throw error.
|
|
8
8
|
*/
|
|
9
|
-
set(key: string, value:
|
|
9
|
+
set<T = unknown>(key: string, value: T): Promise<void>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Gets the value corresponding to the given key.
|
|
13
13
|
* @returns value stored corresponding to the given key; `undefined` if key is not found or expired
|
|
14
14
|
*/
|
|
15
|
-
get(key: string): Promise<
|
|
16
|
-
}
|
|
15
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
16
|
+
}
|
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import type { KeyDerivationScheme } from '../utils/hd-key.js';
|
|
2
|
-
import type { KeyUnwrapPayload } from '../utils/encryption.js';
|
|
3
|
-
import type { PublicKeyJwk } from './jose-types.js';
|
|
2
|
+
import type { KeyUnwrapPayload, SealKeyWrap } from '../utils/encryption.js';
|
|
3
|
+
import type { PrivateKeyJwk, PublicKeyJwk } from './jose-types.js';
|
|
4
|
+
|
|
5
|
+
export type RoleAudienceTuple = {
|
|
6
|
+
protocol: string;
|
|
7
|
+
rolePath: string;
|
|
8
|
+
contextId: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type RoleAudienceKeyId = RoleAudienceTuple & {
|
|
12
|
+
keyId: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export enum EncryptionControlDeliveryRecipientAuthority {
|
|
16
|
+
RoleHolder = 'roleHolder',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type EncryptionControlDeliveryTags = RoleAudienceKeyId & {
|
|
20
|
+
recipientAuthority: EncryptionControlDeliveryRecipientAuthority | `${EncryptionControlDeliveryRecipientAuthority}`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type EncryptionControlSeal = SealKeyWrap;
|
|
24
|
+
|
|
25
|
+
export type EncryptionControlAudiencePayload = RoleAudienceKeyId & {
|
|
26
|
+
publicKeyJwk: PublicKeyJwk;
|
|
27
|
+
sealedPrivateKey: EncryptionControlSeal;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type RoleAudienceKeyMaterial = {
|
|
31
|
+
algorithm: 'X25519-HKDF-SHA256+A256KW';
|
|
32
|
+
derivationScheme: 'roleAudience';
|
|
33
|
+
keyId: string;
|
|
34
|
+
publicKeyJwk: PublicKeyJwk;
|
|
35
|
+
privateKeyJwk: PrivateKeyJwk;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type EncryptionControlDeliveryPayload = RoleAudienceKeyId & {
|
|
39
|
+
keyMaterial: RoleAudienceKeyMaterial;
|
|
40
|
+
};
|
|
4
41
|
|
|
5
42
|
export type KeyDecrypterDerivationScheme = KeyDerivationScheme | 'roleAudience';
|
|
6
43
|
|
|
@@ -79,15 +79,13 @@ export interface ValidationStateReader {
|
|
|
79
79
|
}): Promise<RecordsWriteMessage[]>;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* Queries accepted audience
|
|
83
|
-
* The optional `keyId` narrows the lookup to one published audience key.
|
|
82
|
+
* Queries accepted source-protocol-native audience control records by role-audience coordinates.
|
|
84
83
|
*/
|
|
85
|
-
|
|
84
|
+
queryAudienceRecords(input: {
|
|
86
85
|
tenant: string;
|
|
87
86
|
protocol: string;
|
|
87
|
+
rolePath: string;
|
|
88
88
|
contextId: string;
|
|
89
|
-
role: string;
|
|
90
|
-
epoch: number;
|
|
91
89
|
keyId?: string;
|
|
92
90
|
}): Promise<RecordsWriteMessage[]>;
|
|
93
91
|
|
package/src/utils/data-stream.ts
CHANGED
|
@@ -76,6 +76,28 @@ export class DataStream {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Adapts an iterable or async iterable of byte chunks into a Web ReadableStream.
|
|
81
|
+
*/
|
|
82
|
+
public static fromAsyncIterable(iterable: AsyncIterable<Uint8Array> | Iterable<Uint8Array>): ReadableStream<Uint8Array> {
|
|
83
|
+
const iterator = DataStream.toAsyncGenerator(iterable);
|
|
84
|
+
|
|
85
|
+
return new ReadableStream<Uint8Array>({
|
|
86
|
+
async pull(controller): Promise<void> {
|
|
87
|
+
const result = await iterator.next();
|
|
88
|
+
if (result.done) {
|
|
89
|
+
controller.close();
|
|
90
|
+
} else {
|
|
91
|
+
controller.enqueue(result.value);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
async cancel(): Promise<void> {
|
|
96
|
+
await iterator.return(undefined);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
79
101
|
/**
|
|
80
102
|
* Creates a readable stream from the object given.
|
|
81
103
|
*/
|
|
@@ -106,6 +128,12 @@ export class DataStream {
|
|
|
106
128
|
}
|
|
107
129
|
}
|
|
108
130
|
|
|
131
|
+
private static async * toAsyncGenerator<T>(iterable: AsyncIterable<T> | Iterable<T>): AsyncGenerator<T> {
|
|
132
|
+
for await (const item of iterable) {
|
|
133
|
+
yield item;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
109
137
|
/**
|
|
110
138
|
* Duplicates the given data stream into the number of streams specified so that multiple handlers can consume the same data stream.
|
|
111
139
|
* Uses the native `ReadableStream.tee()` method for 2 copies, or a custom fan-out for N copies.
|
|
@@ -133,4 +161,4 @@ export class DataStream {
|
|
|
133
161
|
|
|
134
162
|
return streams;
|
|
135
163
|
}
|
|
136
|
-
}
|
|
164
|
+
}
|