@enbox/dwn-sdk-js 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/browser.mjs +19 -78
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +4465 -3861
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +50 -0
- package/dist/esm/src/core/constants.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +28 -11
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/encryption-control.js +785 -0
- package/dist/esm/src/core/encryption-control.js.map +1 -0
- package/dist/esm/src/core/message.js +6 -0
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +36 -5
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +3 -12
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +31 -30
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +6 -0
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/recording-validation-state-reader.js +3 -3
- package/dist/esm/src/core/recording-validation-state-reader.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js +62 -108
- package/dist/esm/src/core/replication-apply.js.map +1 -1
- package/dist/esm/src/core/validation-state-reader.js +5 -6
- package/dist/esm/src/core/validation-state-reader.js.map +1 -1
- package/dist/esm/src/dwn.js +1 -2
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js +11 -11
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js.map +1 -1
- package/dist/esm/src/handlers/messages-query.js +6 -16
- package/dist/esm/src/handlers/messages-query.js.map +1 -1
- package/dist/esm/src/handlers/messages-read.js +4 -3
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +26 -30
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +6 -4
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +85 -10
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +11 -0
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +140 -18
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +20 -4
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +127 -11
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +15 -0
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +7 -10
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +66 -9
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +43 -36
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +5 -5
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/encryption.js +32 -274
- package/dist/esm/src/protocols/encryption.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +14 -23
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +10 -27
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/blockstore-utils.js +45 -0
- package/dist/esm/src/store/blockstore-utils.js.map +1 -0
- package/dist/esm/src/store/blockstore.js +2 -0
- package/dist/esm/src/store/blockstore.js.map +1 -0
- package/dist/esm/src/store/data-store-level.js +4 -12
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/level.js +7 -0
- package/dist/esm/src/store/level.js.map +1 -0
- package/dist/esm/src/types/encryption-types.js +4 -1
- package/dist/esm/src/types/encryption-types.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +25 -0
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +142 -34
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/grant-key-coverage.js +180 -0
- package/dist/esm/src/utils/grant-key-coverage.js.map +1 -0
- package/dist/esm/src/utils/hd-key.js +1 -2
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +7 -1
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +29 -8
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +27 -0
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/record-limit-occupancy.js +23 -3
- package/dist/esm/src/utils/record-limit-occupancy.js.map +1 -1
- package/dist/esm/src/utils/records.js +29 -0
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +12 -11
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +12 -20
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +103 -25
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/tests/core/constants.spec.js +35 -0
- package/dist/esm/tests/core/constants.spec.js.map +1 -0
- package/dist/esm/tests/core/encryption-control.spec.js +100 -0
- package/dist/esm/tests/core/encryption-control.spec.js.map +1 -0
- package/dist/esm/tests/core/message.spec.js +35 -0
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-apply.spec.js +157 -74
- package/dist/esm/tests/core/replication-apply.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js +2 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js +14 -28
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-state-reader.spec.js +19 -23
- package/dist/esm/tests/core/validation-state-reader.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +2 -1
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-wake-publisher.spec.js +51 -0
- package/dist/esm/tests/event-emitter-wake-publisher.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-composition.spec.js +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/encryption.fuzz.spec.js +9 -1
- package/dist/esm/tests/fuzz/encryption.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js +1 -1
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/protocols-utils.fuzz.spec.js +29 -1
- package/dist/esm/tests/fuzz/protocols-utils.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/secp256k1.fuzz.spec.js +2 -2
- package/dist/esm/tests/fuzz/secp256k1.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/time.fuzz.spec.js +7 -1
- package/dist/esm/tests/fuzz/time.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +123 -11
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +95 -0
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +90 -0
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +66 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +370 -0
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +70 -1
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +562 -1
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +140 -2
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +241 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1187 -29
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +290 -2
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +47 -5
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/encryption.spec.js +116 -472
- package/dist/esm/tests/protocols/encryption.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +13 -27
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +33 -10
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +31 -7
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-utils.spec.js +115 -0
- package/dist/esm/tests/store/blockstore-utils.spec.js.map +1 -0
- package/dist/esm/tests/store/index-level.spec.js +3 -3
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/test-stores.js +2 -1
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +15 -0
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +30 -0
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-control-test-utils.js +111 -0
- package/dist/esm/tests/utils/encryption-control-test-utils.js.map +1 -0
- package/dist/esm/tests/utils/encryption.spec.js +240 -67
- 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/grant-key.spec.js +25 -16
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +152 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +46 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +4 -4
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +39 -0
- package/dist/types/src/core/constants.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +28 -11
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/encryption-control.d.ts +128 -0
- package/dist/types/src/core/encryption-control.d.ts.map +1 -0
- package/dist/types/src/core/message.d.ts +4 -0
- package/dist/types/src/core/message.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +11 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/recording-validation-state-reader.d.ts +2 -3
- package/dist/types/src/core/recording-validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +10 -1
- package/dist/types/src/core/replication-apply.d.ts.map +1 -1
- package/dist/types/src/core/validation-state-reader.d.ts +2 -3
- package/dist/types/src/core/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts +1 -1
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +1 -0
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +2 -0
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -0
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +2 -0
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +10 -17
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts +13 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +5 -1
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts.map +1 -1
- package/dist/types/src/protocols/encryption.d.ts +2 -19
- package/dist/types/src/protocols/encryption.d.ts.map +1 -1
- package/dist/types/src/store/blockstore-level.d.ts +11 -11
- package/dist/types/src/store/blockstore-level.d.ts.map +1 -1
- package/dist/types/src/store/blockstore-mock.d.ts +12 -12
- package/dist/types/src/store/blockstore-mock.d.ts.map +1 -1
- package/dist/types/src/store/blockstore-utils.d.ts +23 -0
- package/dist/types/src/store/blockstore-utils.d.ts.map +1 -0
- package/dist/types/src/store/blockstore.d.ts +3 -0
- package/dist/types/src/store/blockstore.d.ts.map +1 -0
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/level.d.ts +13 -0
- package/dist/types/src/store/level.d.ts.map +1 -0
- package/dist/types/src/types/cache.d.ts +2 -2
- package/dist/types/src/types/cache.d.ts.map +1 -1
- package/dist/types/src/types/encryption-types.d.ts +31 -2
- package/dist/types/src/types/encryption-types.d.ts.map +1 -1
- package/dist/types/src/types/validation-state-reader.d.ts +3 -5
- package/dist/types/src/types/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/utils/data-stream.d.ts +5 -0
- package/dist/types/src/utils/data-stream.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +58 -22
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/grant-key-coverage.d.ts +36 -0
- package/dist/types/src/utils/grant-key-coverage.d.ts.map +1 -0
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/jws.d.ts.map +1 -1
- package/dist/types/src/utils/memory-cache.d.ts +4 -2
- package/dist/types/src/utils/memory-cache.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +11 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/record-limit-occupancy.d.ts +7 -0
- package/dist/types/src/utils/record-limit-occupancy.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +2 -0
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/secp256k1.d.ts.map +1 -1
- package/dist/types/src/utils/secp256r1.d.ts.map +1 -1
- package/dist/types/src/utils/time.d.ts +21 -13
- package/dist/types/src/utils/time.d.ts.map +1 -1
- package/dist/types/tests/core/constants.spec.d.ts +2 -0
- package/dist/types/tests/core/constants.spec.d.ts.map +1 -0
- package/dist/types/tests/core/encryption-control.spec.d.ts +2 -0
- package/dist/types/tests/core/encryption-control.spec.d.ts.map +1 -0
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-wake-publisher.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-wake-publisher.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/store/blockstore-utils.spec.d.ts +2 -0
- package/dist/types/tests/store/blockstore-utils.spec.d.ts.map +1 -0
- package/dist/types/tests/test-stores.d.ts.map +1 -1
- package/dist/types/tests/utils/encryption-control-test-utils.d.ts +46 -0
- package/dist/types/tests/utils/encryption-control-test-utils.d.ts.map +1 -0
- package/dist/types/tests/utils/grant-key-coverage.spec.d.ts +2 -0
- package/dist/types/tests/utils/grant-key-coverage.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/validation/json-schemas/encryption/audience.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/encryption/audience.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts.map +1 -0
- package/package.json +47 -28
- package/src/core/constants.ts +61 -0
- package/src/core/dwn-error.ts +28 -11
- package/src/core/encryption-control.ts +1249 -0
- package/src/core/message.ts +7 -0
- package/src/core/messages-grant-authorization.ts +60 -9
- package/src/core/protocol-authorization-action.ts +3 -13
- package/src/core/protocol-authorization-validation.ts +66 -46
- package/src/core/protocol-authorization.ts +7 -0
- package/src/core/recording-validation-state-reader.ts +4 -5
- package/src/core/replication-apply.ts +77 -133
- package/src/core/validation-state-reader.ts +6 -8
- package/src/dwn.ts +1 -2
- package/src/event-stream/event-emitter-wake-publisher.ts +10 -14
- package/src/handlers/messages-query.ts +6 -22
- package/src/handlers/messages-read.ts +4 -3
- package/src/handlers/messages-subscribe.ts +34 -30
- package/src/handlers/protocols-configure.ts +7 -4
- package/src/handlers/records-count.ts +111 -10
- package/src/handlers/records-delete.ts +15 -0
- package/src/handlers/records-query.ts +176 -20
- package/src/handlers/records-read.ts +19 -6
- package/src/handlers/records-subscribe.ts +158 -8
- package/src/handlers/records-write.ts +19 -0
- package/src/index.ts +48 -21
- package/src/interfaces/protocols-configure.ts +102 -11
- package/src/interfaces/records-write.ts +49 -43
- package/src/jose/algorithms/signing/ed25519.ts +7 -6
- package/src/jose/jws/general/verifier.ts +3 -3
- package/src/protocols/encryption.ts +50 -420
- package/src/store/blockstore-level.ts +33 -37
- package/src/store/blockstore-mock.ts +24 -38
- package/src/store/blockstore-utils.ts +85 -0
- package/src/store/blockstore.ts +8 -0
- package/src/store/data-store-level.ts +5 -12
- package/src/store/level.ts +19 -0
- package/src/types/cache.ts +3 -3
- package/src/types/encryption-types.ts +39 -2
- package/src/types/validation-state-reader.ts +3 -5
- package/src/utils/data-stream.ts +29 -1
- package/src/utils/encryption.ts +247 -69
- 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/src/types/mitt.d.ts +0 -28
package/src/utils/secp256r1.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { JwkParamsEcPrivate, JwkParamsEcPublic } from '@enbox/crypto';
|
|
2
2
|
import type { PrivateKeyJwk, PublicKeyJwk } from '../types/jose-types.js';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { bytesToNumberBE } from '@noble/curves/utils.js';
|
|
5
|
+
import { p256 } from '@noble/curves/nist.js';
|
|
5
6
|
|
|
6
7
|
import { Encoder } from './encoder.js';
|
|
7
8
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
8
9
|
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
9
|
-
import { fromString, toString } from 'uint8arrays';
|
|
10
|
-
|
|
11
|
-
const u8a = { toString, fromString };
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Class containing SECP256R1 related utility methods.
|
|
@@ -37,8 +35,8 @@ export class Secp256r1 {
|
|
|
37
35
|
let uncompressedPublicKeyBytes;
|
|
38
36
|
if (publicKeyBytes.byteLength === 33) {
|
|
39
37
|
// this means given key is compressed
|
|
40
|
-
const curvePoints = p256.
|
|
41
|
-
uncompressedPublicKeyBytes = curvePoints.
|
|
38
|
+
const curvePoints = p256.Point.fromBytes(publicKeyBytes);
|
|
39
|
+
uncompressedPublicKeyBytes = curvePoints.toBytes(false); // isCompressed = false
|
|
42
40
|
} else {
|
|
43
41
|
uncompressedPublicKeyBytes = publicKeyBytes;
|
|
44
42
|
}
|
|
@@ -87,9 +85,7 @@ export class Secp256r1 {
|
|
|
87
85
|
const hashedContent = await sha256.encode(content);
|
|
88
86
|
const privateKeyBytes = Secp256r1.privateJwkToBytes(privateJwk);
|
|
89
87
|
|
|
90
|
-
return Promise.resolve(
|
|
91
|
-
p256.sign(hashedContent, privateKeyBytes).toCompactRawBytes()
|
|
92
|
-
);
|
|
88
|
+
return Promise.resolve(p256.sign(hashedContent, privateKeyBytes, { prehash: false }));
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
/**
|
|
@@ -104,21 +100,15 @@ export class Secp256r1 {
|
|
|
104
100
|
): Promise<boolean> {
|
|
105
101
|
Secp256r1.validateKey(publicJwk);
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
let sig;
|
|
109
|
-
if (signature.length === 64) {
|
|
110
|
-
sig = p256.Signature.fromCompact(signature);
|
|
111
|
-
} else {
|
|
112
|
-
sig = p256.Signature.fromDER(signature);
|
|
113
|
-
}
|
|
103
|
+
const signatureFormat = signature.length === 64 ? 'compact' : 'der';
|
|
114
104
|
const hashedContent = await sha256.encode(content);
|
|
115
105
|
const ecJwk = publicJwk as JwkParamsEcPublic;
|
|
116
|
-
const keyBytes = p256.
|
|
106
|
+
const keyBytes = p256.Point.fromAffine({
|
|
117
107
|
x : Secp256r1.bytesToBigInt(Encoder.base64UrlToBytes(ecJwk.x)),
|
|
118
108
|
y : Secp256r1.bytesToBigInt(Encoder.base64UrlToBytes(ecJwk.y!)),
|
|
119
|
-
}).
|
|
109
|
+
}).toBytes(false);
|
|
120
110
|
|
|
121
|
-
return p256.verify(
|
|
111
|
+
return p256.verify(signature, hashedContent, keyBytes, { format: signatureFormat, lowS: false, prehash: false });
|
|
122
112
|
}
|
|
123
113
|
|
|
124
114
|
/**
|
|
@@ -128,8 +118,8 @@ export class Secp256r1 {
|
|
|
128
118
|
publicJwk: PublicKeyJwk;
|
|
129
119
|
privateJwk: PrivateKeyJwk;
|
|
130
120
|
}> {
|
|
131
|
-
const privateKeyBytes = p256.utils.
|
|
132
|
-
const publicKeyBytes =
|
|
121
|
+
const privateKeyBytes = p256.utils.randomSecretKey();
|
|
122
|
+
const publicKeyBytes = p256.getPublicKey(privateKeyBytes, false); // `false` = uncompressed
|
|
133
123
|
|
|
134
124
|
const d = Encoder.bytesToBase64Url(privateKeyBytes);
|
|
135
125
|
const publicJwk: PublicKeyJwk = await Secp256r1.publicKeyToJwk(publicKeyBytes);
|
|
@@ -139,6 +129,6 @@ export class Secp256r1 {
|
|
|
139
129
|
}
|
|
140
130
|
|
|
141
131
|
public static bytesToBigInt(b: Uint8Array): bigint {
|
|
142
|
-
return
|
|
132
|
+
return bytesToNumberBE(b);
|
|
143
133
|
}
|
|
144
134
|
}
|
package/src/utils/time.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { sleep } from '@enbox/common';
|
|
2
|
-
import { Temporal } from '@js-temporal/polyfill';
|
|
3
2
|
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
4
3
|
|
|
4
|
+
type ParsedTimestamp = {
|
|
5
|
+
epochMilliseconds: number;
|
|
6
|
+
microsecond: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type TimestampOptions = {
|
|
10
|
+
year?: number;
|
|
11
|
+
month?: number;
|
|
12
|
+
day?: number;
|
|
13
|
+
hour?: number;
|
|
14
|
+
minute?: number;
|
|
15
|
+
second?: number;
|
|
16
|
+
millisecond?: number;
|
|
17
|
+
microsecond?: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const timestampRegex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{6})Z$/;
|
|
21
|
+
|
|
5
22
|
/**
|
|
6
23
|
* Time related utilities.
|
|
7
24
|
*/
|
|
@@ -19,10 +36,9 @@ export class Time {
|
|
|
19
36
|
|
|
20
37
|
/**
|
|
21
38
|
* Returns an UTC ISO-8601 timestamp with microsecond precision accepted by DWN.
|
|
22
|
-
* using @js-temporal/polyfill
|
|
23
39
|
*/
|
|
24
40
|
public static getCurrentTimestamp(): string {
|
|
25
|
-
return
|
|
41
|
+
return Time.formatUtcTimestamp(Date.now(), 0);
|
|
26
42
|
}
|
|
27
43
|
|
|
28
44
|
/**
|
|
@@ -30,21 +46,21 @@ export class Time {
|
|
|
30
46
|
* @param options - Options for creating the timestamp.
|
|
31
47
|
* @returns string
|
|
32
48
|
*/
|
|
33
|
-
public static createTimestamp(options: {
|
|
34
|
-
year
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
public static createTimestamp(options: TimestampOptions): string {
|
|
50
|
+
const year = Time.constrainInteger(Time.requireTimestampField(options.year, 'year'), 0, 9999);
|
|
51
|
+
const month = Time.constrainInteger(Time.requireTimestampField(options.month, 'month'), 1, 12);
|
|
52
|
+
const day = Time.constrainInteger(Time.requireTimestampField(options.day, 'day'), 1, Time.daysInUtcMonth(year, month));
|
|
53
|
+
const hour = Time.constrainInteger(options.hour ?? 0, 0, 23);
|
|
54
|
+
const minute = Time.constrainInteger(options.minute ?? 0, 0, 59);
|
|
55
|
+
const second = Time.constrainInteger(options.second ?? 0, 0, 59);
|
|
56
|
+
const millisecond = Time.constrainInteger(options.millisecond ?? 0, 0, 999);
|
|
57
|
+
const microsecond = Time.constrainInteger(options.microsecond ?? 0, 0, 999);
|
|
58
|
+
const date = new Date(0);
|
|
59
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
60
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
61
|
+
date.setUTCHours(hour, minute, second, millisecond);
|
|
62
|
+
|
|
63
|
+
return Time.formatUtcTimestamp(date.getTime(), microsecond);
|
|
48
64
|
}
|
|
49
65
|
|
|
50
66
|
/**
|
|
@@ -52,22 +68,124 @@ export class Time {
|
|
|
52
68
|
* @param offset Negative number means offset into the past.
|
|
53
69
|
*/
|
|
54
70
|
public static createOffsetTimestamp(offset: { seconds: number }, timestamp?: string): string {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
71
|
+
const parsedTimestamp = timestamp === undefined ? { epochMilliseconds: Date.now(), microsecond: 0 } : Time.parseTimestamp(timestamp);
|
|
72
|
+
if (parsedTimestamp === undefined) {
|
|
73
|
+
throw new DwnError(DwnErrorCode.TimestampInvalid, `Invalid timestamp: ${timestamp}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const offsetSeconds = Time.requireWholeNumber(offset.seconds, 'seconds');
|
|
77
|
+
return Time.formatUtcTimestamp(parsedTimestamp.epochMilliseconds + (offsetSeconds * 1000), parsedTimestamp.microsecond);
|
|
59
78
|
}
|
|
60
79
|
|
|
61
80
|
/**
|
|
62
|
-
* Validates that the provided timestamp is a
|
|
81
|
+
* Validates that the provided timestamp is a DWN-compatible UTC timestamp.
|
|
63
82
|
* @param timestamp the timestamp to validate
|
|
64
|
-
* @throws DwnError if timestamp is
|
|
83
|
+
* @throws DwnError if timestamp is invalid
|
|
65
84
|
*/
|
|
66
85
|
public static validateTimestamp(timestamp: string): void {
|
|
67
|
-
|
|
68
|
-
Temporal.Instant.from(timestamp);
|
|
69
|
-
} catch {
|
|
86
|
+
if (Time.parseTimestamp(timestamp) === undefined) {
|
|
70
87
|
throw new DwnError(DwnErrorCode.TimestampInvalid, `Invalid timestamp: ${timestamp}`);
|
|
71
88
|
}
|
|
72
89
|
}
|
|
90
|
+
|
|
91
|
+
private static constrainInteger(value: number, min: number, max: number): number {
|
|
92
|
+
if (!Number.isFinite(value)) {
|
|
93
|
+
throw new RangeError('timestamp field must be finite');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const integer = Math.trunc(value);
|
|
97
|
+
return Math.min(Math.max(integer, min), max);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private static daysInUtcMonth(year: number, month: number): number {
|
|
101
|
+
const date = new Date(0);
|
|
102
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
103
|
+
date.setUTCFullYear(year, month, 0);
|
|
104
|
+
|
|
105
|
+
return date.getUTCDate();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private static formatUtcTimestamp(epochMilliseconds: number, microsecond: number): string {
|
|
109
|
+
if (!Number.isFinite(epochMilliseconds)) {
|
|
110
|
+
throw new RangeError('timestamp is outside the supported Date range');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const date = new Date(epochMilliseconds);
|
|
114
|
+
const year = date.getUTCFullYear();
|
|
115
|
+
if (year < 0 || year > 9999) {
|
|
116
|
+
throw new RangeError('timestamp year must be between 0000 and 9999');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const fraction = String((date.getUTCMilliseconds() * 1000) + microsecond).padStart(6, '0');
|
|
120
|
+
return `${Time.pad(year, 4)}-${Time.pad(date.getUTCMonth() + 1, 2)}-${Time.pad(date.getUTCDate(), 2)}` +
|
|
121
|
+
`T${Time.pad(date.getUTCHours(), 2)}:${Time.pad(date.getUTCMinutes(), 2)}:${Time.pad(date.getUTCSeconds(), 2)}.${fraction}Z`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private static pad(value: number, length: number): string {
|
|
125
|
+
return String(value).padStart(length, '0');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private static parseTimestamp(timestamp: string): ParsedTimestamp | undefined {
|
|
129
|
+
const match = timestampRegex.exec(timestamp);
|
|
130
|
+
if (match === null) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const year = Number(match[1]);
|
|
135
|
+
const month = Number(match[2]);
|
|
136
|
+
const day = Number(match[3]);
|
|
137
|
+
const hour = Number(match[4]);
|
|
138
|
+
const minute = Number(match[5]);
|
|
139
|
+
const second = Number(match[6]);
|
|
140
|
+
const fraction = match[7];
|
|
141
|
+
const millisecond = Number(fraction.slice(0, 3));
|
|
142
|
+
const microsecond = Number(fraction.slice(3));
|
|
143
|
+
const isLeapSecond = hour === 23 && minute === 59 && second === 60;
|
|
144
|
+
|
|
145
|
+
if (
|
|
146
|
+
month < 1 ||
|
|
147
|
+
month > 12 ||
|
|
148
|
+
day < 1 ||
|
|
149
|
+
day > Time.daysInUtcMonth(year, month) ||
|
|
150
|
+
hour > 23 ||
|
|
151
|
+
minute > 59 ||
|
|
152
|
+
(second > 59 && !isLeapSecond)
|
|
153
|
+
) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const date = new Date(0);
|
|
158
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
159
|
+
date.setUTCFullYear(year, month - 1, day);
|
|
160
|
+
date.setUTCHours(hour, minute, isLeapSecond ? 59 : second, millisecond);
|
|
161
|
+
|
|
162
|
+
if (
|
|
163
|
+
date.getUTCFullYear() !== year ||
|
|
164
|
+
date.getUTCMonth() !== month - 1 ||
|
|
165
|
+
date.getUTCDate() !== day ||
|
|
166
|
+
date.getUTCHours() !== hour ||
|
|
167
|
+
date.getUTCMinutes() !== minute ||
|
|
168
|
+
date.getUTCSeconds() !== (isLeapSecond ? 59 : second)
|
|
169
|
+
) {
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return { epochMilliseconds: date.getTime(), microsecond };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private static requireTimestampField(value: number | undefined, fieldName: string): number {
|
|
177
|
+
if (value === undefined) {
|
|
178
|
+
throw new TypeError(`required property '${fieldName}' missing or undefined`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private static requireWholeNumber(value: number, fieldName: string): number {
|
|
185
|
+
if (!Number.isFinite(value) || !Number.isInteger(value)) {
|
|
186
|
+
throw new RangeError(`${fieldName} must be a finite integer`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
73
191
|
}
|
package/src/types/mitt.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// mitt v3 does not include `"type": "module"` in its package.json, so under
|
|
2
|
-
// TypeScript's `NodeNext` module resolution the `export default function` in
|
|
3
|
-
// mitt's own typings is treated as a CJS namespace rather than a callable.
|
|
4
|
-
// This ambient module declaration re-exports the factory as a proper ESM
|
|
5
|
-
// default so `import mitt from 'mitt'` type-checks correctly.
|
|
6
|
-
declare module 'mitt' {
|
|
7
|
-
type EventType = string | symbol;
|
|
8
|
-
type Handler<T = unknown> = (event: T) => void;
|
|
9
|
-
type EventHandlerList<T = unknown> = Array<Handler<T>>;
|
|
10
|
-
type WildCardEventHandlerList<T = Record<string, unknown>> = Array<
|
|
11
|
-
(type: keyof T, event: T[keyof T]) => void
|
|
12
|
-
>;
|
|
13
|
-
type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<
|
|
14
|
-
keyof Events | '*',
|
|
15
|
-
EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>
|
|
16
|
-
>;
|
|
17
|
-
|
|
18
|
-
interface Emitter<Events extends Record<EventType, unknown>> {
|
|
19
|
-
all: EventHandlerMap<Events>;
|
|
20
|
-
on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;
|
|
21
|
-
off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): void;
|
|
22
|
-
emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default function mitt<Events extends Record<EventType, unknown>>(
|
|
26
|
-
all?: EventHandlerMap<Events>
|
|
27
|
-
): Emitter<Events>;
|
|
28
|
-
}
|