@enbox/dwn-sdk-js 0.4.0 → 0.4.1
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 +4 -4
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +799 -885
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/dwn-constant.js +5 -0
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +12 -4
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +9 -18
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message-reply.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +28 -45
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +25 -27
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +30 -68
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization.js +44 -118
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +5 -5
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/recording-validation-state-reader.js +84 -0
- package/dist/esm/src/core/recording-validation-state-reader.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +11 -11
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js +123 -28
- package/dist/esm/src/core/replication-apply.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +5 -4
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/validation-state-reader.js +237 -0
- package/dist/esm/src/core/validation-state-reader.js.map +1 -0
- package/dist/esm/src/dwn.js +165 -132
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/enums/dwn-interface-method.js +0 -1
- package/dist/esm/src/enums/dwn-interface-method.js.map +1 -1
- package/dist/esm/src/event-stream/durable-event-log.js +365 -0
- package/dist/esm/src/event-stream/durable-event-log.js.map +1 -0
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js +25 -0
- package/dist/esm/src/event-stream/event-emitter-wake-publisher.js.map +1 -0
- package/dist/esm/src/handlers/messages-query.js +159 -0
- package/dist/esm/src/handlers/messages-query.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +5 -5
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +8 -8
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +30 -49
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +1 -1
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +20 -11
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +20 -16
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +35 -11
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +52 -42
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +107 -11
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +62 -116
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +6 -7
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/{messages-sync.js → messages-query.js} +21 -15
- package/dist/esm/src/interfaces/messages-query.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-configure.js +7 -3
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +3 -4
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +4 -3
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +21 -4
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +4 -3
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +3 -3
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +4 -3
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +27 -13
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +27 -34
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/store/index-level.js +24 -9
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +7 -0
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +536 -42
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +58 -49
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/message-types.js.map +1 -1
- package/dist/esm/src/types/validation-state-reader.js +2 -0
- package/dist/esm/src/types/validation-state-reader.js.map +1 -0
- package/dist/esm/src/utils/messages.js +17 -0
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/record-limit-occupancy.js +244 -0
- package/dist/esm/src/utils/record-limit-occupancy.js.map +1 -0
- package/dist/esm/src/utils/records.js +50 -14
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/replication.js +85 -0
- package/dist/esm/src/utils/replication.js.map +1 -0
- package/dist/esm/tests/core/grant-authorization.spec.js +4 -4
- package/dist/esm/tests/core/grant-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/process-message-parity.spec.js +222 -0
- package/dist/esm/tests/core/process-message-parity.spec.js.map +1 -0
- package/dist/esm/tests/core/protocol-authorization.spec.js +5 -2
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/records-grant-authorization.spec.js +5 -5
- package/dist/esm/tests/core/records-grant-authorization.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-apply.spec.js +55 -1
- package/dist/esm/tests/core/replication-apply.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js +350 -0
- package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -0
- package/dist/esm/tests/core/validation-read-closure.spec.js +469 -0
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -0
- package/dist/esm/tests/core/validation-state-reader.spec.js +716 -0
- package/dist/esm/tests/core/validation-state-reader.spec.js.map +1 -0
- package/dist/esm/tests/durable-event-log.spec.js +373 -0
- package/dist/esm/tests/durable-event-log.spec.js.map +1 -0
- package/dist/esm/tests/dwn.spec.js +504 -35
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/features/author-delegated-grant.spec.js +9 -6
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +1 -4
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +1 -4
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +165 -4
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +8 -11
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +1 -4
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +3 -5
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +3 -6
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-delivery.spec.js +1 -4
- package/dist/esm/tests/features/records-delivery.spec.js.map +1 -1
- package/dist/esm/tests/features/records-immutable.spec.js +1 -4
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -1
- package/dist/esm/tests/features/records-nested-query-scope.spec.js +281 -0
- package/dist/esm/tests/features/records-nested-query-scope.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune-cross-protocol.spec.js +3 -7
- package/dist/esm/tests/features/records-prune-cross-protocol.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +11 -22
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +441 -231
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
- package/dist/esm/tests/features/records-squash.spec.js +6 -4
- package/dist/esm/tests/features/records-squash.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +1 -4
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +3 -5
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/message-store.fuzz.spec.js +1 -2
- package/dist/esm/tests/fuzz/message-store.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js +2 -4
- package/dist/esm/tests/fuzz/process-message.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/schema-validation.fuzz.spec.js +1 -1
- package/dist/esm/tests/fuzz/schema-validation.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +246 -0
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-read.spec.js +2 -5
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +3 -14
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +27 -26
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +1 -4
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +1 -4
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +312 -30
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +32 -9
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +4 -4
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +33 -14
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +82 -36
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +69 -2
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +4 -3
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +55 -6
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +1 -4
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +1 -4
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +1 -4
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +1 -4
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +1 -4
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +361 -5
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +60 -0
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +7 -3
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +19 -9
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +4 -2
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +25 -0
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/utils/test-stub-generator.js.map +1 -1
- package/dist/esm/tests/utils/test-validation-state-reader.js +16 -0
- package/dist/esm/tests/utils/test-validation-state-reader.js.map +1 -0
- package/dist/types/generated/precompiled-validators.d.ts +6 -6
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/core-protocol.d.ts +3 -3
- package/dist/types/src/core/core-protocol.d.ts.map +1 -1
- package/dist/types/src/core/dwn-constant.d.ts +5 -0
- package/dist/types/src/core/dwn-constant.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +12 -4
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +5 -5
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/message-reply.d.ts +5 -4
- package/dist/types/src/core/message-reply.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +12 -14
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +4 -5
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts +13 -16
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization.d.ts +8 -33
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocols-grant-authorization.d.ts +4 -4
- package/dist/types/src/core/protocols-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/recording-validation-state-reader.d.ts +75 -0
- package/dist/types/src/core/recording-validation-state-reader.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts +8 -8
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +36 -0
- package/dist/types/src/core/replication-apply.d.ts.map +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts +1 -1
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
- package/dist/types/src/core/validation-state-reader.d.ts +79 -0
- package/dist/types/src/core/validation-state-reader.d.ts.map +1 -0
- package/dist/types/src/dwn.d.ts +33 -20
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/enums/dwn-interface-method.d.ts +0 -1
- package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -1
- package/dist/types/src/event-stream/durable-event-log.d.ts +69 -0
- package/dist/types/src/event-stream/durable-event-log.d.ts.map +1 -0
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts +13 -0
- package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-query.d.ts +20 -0
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +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 +0 -5
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +2 -1
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +2 -2
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +1 -1
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +2 -1
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +4 -5
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +3 -11
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +14 -16
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-query.d.ts +23 -0
- package/dist/types/src/interfaces/messages-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts +3 -3
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-query.d.ts +2 -2
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-count.d.ts +3 -3
- package/dist/types/src/interfaces/records-count.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-delete.d.ts +11 -3
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-query.d.ts +3 -3
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-read.d.ts +3 -3
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +3 -3
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +15 -7
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +9 -12
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/store/index-level.d.ts +10 -1
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/level-wrapper.d.ts +5 -0
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -1
- package/dist/types/src/store/message-store-level.d.ts +94 -14
- package/dist/types/src/store/message-store-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +17 -14
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-store.d.ts +29 -1
- package/dist/types/src/types/message-store.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +2 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +21 -37
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +2 -2
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +1 -1
- package/dist/types/src/types/subscriptions.d.ts +50 -39
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/types/validation-state-reader.d.ts +116 -0
- package/dist/types/src/types/validation-state-reader.d.ts.map +1 -0
- package/dist/types/src/utils/messages.d.ts +10 -0
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/record-limit-occupancy.d.ts +40 -0
- package/dist/types/src/utils/record-limit-occupancy.d.ts.map +1 -0
- package/dist/types/src/utils/records.d.ts +25 -3
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/replication.d.ts +22 -0
- package/dist/types/src/utils/replication.d.ts.map +1 -0
- package/dist/types/tests/core/process-message-parity.spec.d.ts +2 -0
- package/dist/types/tests/core/process-message-parity.spec.d.ts.map +1 -0
- package/dist/types/tests/core/replication-replay-property.spec.d.ts +2 -0
- package/dist/types/tests/core/replication-replay-property.spec.d.ts.map +1 -0
- package/dist/types/tests/core/validation-read-closure.spec.d.ts +2 -0
- package/dist/types/tests/core/validation-read-closure.spec.d.ts.map +1 -0
- package/dist/types/tests/core/validation-state-reader.spec.d.ts +2 -0
- package/dist/types/tests/core/validation-state-reader.spec.d.ts.map +1 -0
- package/dist/types/tests/durable-event-log.spec.d.ts +2 -0
- package/dist/types/tests/durable-event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-nested-query-scope.spec.d.ts +2 -0
- package/dist/types/tests/features/records-nested-query-scope.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-prune-cross-protocol.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-squash.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -0
- 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/protocols-query.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/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +1 -1
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-stores.d.ts +5 -4
- package/dist/types/tests/test-stores.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +1 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +20 -1
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/utils/test-validation-state-reader.d.ts +15 -0
- package/dist/types/tests/utils/test-validation-state-reader.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/core/core-protocol.ts +3 -3
- package/src/core/dwn-constant.ts +7 -1
- package/src/core/dwn-error.ts +12 -4
- package/src/core/grant-authorization.ts +11 -20
- package/src/core/message-reply.ts +6 -5
- package/src/core/messages-grant-authorization.ts +37 -70
- package/src/core/protocol-authorization-action.ts +29 -38
- package/src/core/protocol-authorization-validation.ts +39 -96
- package/src/core/protocol-authorization.ts +56 -202
- package/src/core/protocols-grant-authorization.ts +9 -9
- package/src/core/recording-validation-state-reader.ts +130 -0
- package/src/core/records-grant-authorization.ts +16 -16
- package/src/core/replication-apply.ts +172 -32
- package/src/core/resumable-task-manager.ts +10 -8
- package/src/core/validation-state-reader.ts +350 -0
- package/src/dwn.ts +285 -192
- package/src/enums/dwn-interface-method.ts +0 -1
- package/src/event-stream/durable-event-log.ts +509 -0
- package/src/event-stream/event-emitter-wake-publisher.ts +34 -0
- package/src/handlers/messages-query.ts +203 -0
- package/src/handlers/messages-read.ts +9 -10
- package/src/handlers/messages-subscribe.ts +12 -13
- package/src/handlers/protocols-configure.ts +37 -58
- package/src/handlers/protocols-query.ts +1 -1
- package/src/handlers/records-count.ts +24 -17
- package/src/handlers/records-delete.ts +29 -27
- package/src/handlers/records-query.ts +38 -17
- package/src/handlers/records-read.ts +63 -50
- package/src/handlers/records-subscribe.ts +132 -19
- package/src/handlers/records-write.ts +77 -168
- package/src/index.ts +14 -17
- package/src/interfaces/messages-query.ts +70 -0
- package/src/interfaces/protocols-configure.ts +12 -4
- package/src/interfaces/protocols-query.ts +4 -5
- package/src/interfaces/records-count.ts +9 -4
- package/src/interfaces/records-delete.ts +25 -5
- package/src/interfaces/records-query.ts +9 -4
- package/src/interfaces/records-read.ts +4 -4
- package/src/interfaces/records-subscribe.ts +9 -4
- package/src/interfaces/records-write.ts +41 -13
- package/src/protocols/permissions.ts +32 -52
- package/src/store/index-level.ts +30 -9
- package/src/store/level-wrapper.ts +9 -1
- package/src/store/message-store-level.ts +757 -47
- package/src/store/storage-controller.ts +74 -63
- package/src/types/message-store.ts +45 -2
- package/src/types/message-types.ts +3 -1
- package/src/types/messages-types.ts +26 -45
- package/src/types/method-handler.ts +3 -3
- package/src/types/permission-types.ts +1 -1
- package/src/types/subscriptions.ts +53 -42
- package/src/types/validation-state-reader.ts +127 -0
- package/src/utils/messages.ts +25 -1
- package/src/utils/record-limit-occupancy.ts +377 -0
- package/src/utils/records.ts +69 -13
- package/src/utils/replication.ts +122 -0
- package/dist/esm/src/core/record-chain.js +0 -64
- package/dist/esm/src/core/record-chain.js.map +0 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +0 -334
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +0 -1
- package/dist/esm/src/handlers/messages-sync.js +0 -278
- package/dist/esm/src/handlers/messages-sync.js.map +0 -1
- package/dist/esm/src/interfaces/messages-sync.js.map +0 -1
- package/dist/esm/src/smt/smt-store-level.js +0 -103
- package/dist/esm/src/smt/smt-store-level.js.map +0 -1
- package/dist/esm/src/smt/smt-store-memory.js +0 -41
- package/dist/esm/src/smt/smt-store-memory.js.map +0 -1
- package/dist/esm/src/smt/smt-utils.js +0 -129
- package/dist/esm/src/smt/smt-utils.js.map +0 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +0 -577
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +0 -1
- package/dist/esm/src/state-index/state-index-level.js +0 -191
- package/dist/esm/src/state-index/state-index-level.js.map +0 -1
- package/dist/esm/src/types/smt-types.js +0 -5
- package/dist/esm/src/types/smt-types.js.map +0 -1
- package/dist/esm/src/types/state-index.js +0 -2
- package/dist/esm/src/types/state-index.js.map +0 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +0 -499
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +0 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +0 -1088
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +0 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +0 -132
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +0 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +0 -732
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +0 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +0 -245
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +0 -1
- package/dist/types/src/core/record-chain.d.ts +0 -24
- package/dist/types/src/core/record-chain.d.ts.map +0 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +0 -80
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +0 -1
- package/dist/types/src/handlers/messages-sync.d.ts +0 -39
- package/dist/types/src/handlers/messages-sync.d.ts.map +0 -1
- package/dist/types/src/interfaces/messages-sync.d.ts +0 -20
- package/dist/types/src/interfaces/messages-sync.d.ts.map +0 -1
- package/dist/types/src/smt/smt-store-level.d.ts +0 -32
- package/dist/types/src/smt/smt-store-level.d.ts.map +0 -1
- package/dist/types/src/smt/smt-store-memory.d.ts +0 -22
- package/dist/types/src/smt/smt-store-memory.d.ts.map +0 -1
- package/dist/types/src/smt/smt-utils.d.ts +0 -58
- package/dist/types/src/smt/smt-utils.d.ts.map +0 -1
- package/dist/types/src/smt/sparse-merkle-tree.d.ts +0 -124
- package/dist/types/src/smt/sparse-merkle-tree.d.ts.map +0 -1
- package/dist/types/src/state-index/state-index-level.d.ts +0 -83
- package/dist/types/src/state-index/state-index-level.d.ts.map +0 -1
- package/dist/types/src/types/smt-types.d.ts +0 -81
- package/dist/types/src/types/smt-types.d.ts.map +0 -1
- package/dist/types/src/types/state-index.d.ts +0 -90
- package/dist/types/src/types/state-index.d.ts.map +0 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +0 -2
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +0 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts +0 -2
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +0 -1
- package/dist/types/tests/smt/smt-store-level.spec.d.ts +0 -2
- package/dist/types/tests/smt/smt-store-level.spec.d.ts.map +0 -1
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts +0 -2
- package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts.map +0 -1
- package/dist/types/tests/state-index/state-index-level.spec.d.ts +0 -2
- package/dist/types/tests/state-index/state-index-level.spec.d.ts.map +0 -1
- package/src/core/record-chain.ts +0 -99
- package/src/event-stream/event-emitter-event-log.ts +0 -430
- package/src/handlers/messages-sync.ts +0 -403
- package/src/interfaces/messages-sync.ts +0 -69
- package/src/smt/smt-store-level.ts +0 -143
- package/src/smt/smt-store-memory.ts +0 -53
- package/src/smt/smt-utils.ts +0 -149
- package/src/smt/sparse-merkle-tree.ts +0 -698
- package/src/state-index/state-index-level.ts +0 -239
- package/src/types/smt-types.ts +0 -95
- package/src/types/state-index.ts +0 -100
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LevelDB-backed implementation of the StateIndex interface.
|
|
3
|
-
*
|
|
4
|
-
* Manages per-tenant Sparse Merkle Trees (global + per-protocol sub-trees).
|
|
5
|
-
*
|
|
6
|
-
* All data lives within a single LevelDB instance, partitioned by sublevels:
|
|
7
|
-
* {tenant}/global/ -> SMT nodes + root for the tenant's global tree
|
|
8
|
-
* {tenant}/proto/{proto}/ -> SMT nodes + root for a protocol-scoped tree
|
|
9
|
-
* {tenant}/meta/{cid} -> JSON(indexes) for reverse lookup during deletion
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { Hash } from '../types/smt-types.js';
|
|
13
|
-
import type { KeyValues } from '../types/query-types.js';
|
|
14
|
-
import type { StateIndex } from '../types/state-index.js';
|
|
15
|
-
|
|
16
|
-
import { initDefaultHashes } from '../smt/smt-utils.js';
|
|
17
|
-
import { SMTStoreLevel } from '../smt/smt-store-level.js';
|
|
18
|
-
import { SparseMerkleTree } from '../smt/sparse-merkle-tree.js';
|
|
19
|
-
import { createLevelDatabase, LevelWrapper } from '../store/level-wrapper.js';
|
|
20
|
-
|
|
21
|
-
export type StateIndexLevelConfig = {
|
|
22
|
-
/**
|
|
23
|
-
* Must be a directory path (relative or absolute) where LevelDB will store its files,
|
|
24
|
-
* or in browsers, the name of the IDBDatabase to be opened.
|
|
25
|
-
*/
|
|
26
|
-
location? : string;
|
|
27
|
-
createLevelDatabase? : typeof createLevelDatabase;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class StateIndexLevel implements StateIndex {
|
|
31
|
-
private readonly config: StateIndexLevelConfig;
|
|
32
|
-
private db!: LevelWrapper<string>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Cache of per-tenant global SMTs. Lazily populated on first access.
|
|
36
|
-
* Stores promises to avoid race conditions when multiple concurrent operations
|
|
37
|
-
* trigger lazy initialization of the same tenant's SMT.
|
|
38
|
-
*/
|
|
39
|
-
private readonly globalTrees: Map<string, Promise<SparseMerkleTree>> = new Map();
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Cache of per-tenant, per-protocol SMTs. Key format: `{tenant}\x00{protocol}`
|
|
43
|
-
* Stores promises to avoid race conditions (same reason as globalTrees).
|
|
44
|
-
*/
|
|
45
|
-
private readonly protocolTrees: Map<string, Promise<SparseMerkleTree>> = new Map();
|
|
46
|
-
|
|
47
|
-
constructor(config?: StateIndexLevelConfig) {
|
|
48
|
-
this.config = {
|
|
49
|
-
location : 'STATEINDEX',
|
|
50
|
-
createLevelDatabase : createLevelDatabase,
|
|
51
|
-
...config,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async open(): Promise<void> {
|
|
56
|
-
this.db = new LevelWrapper<string>({
|
|
57
|
-
location : this.config.location!,
|
|
58
|
-
createLevelDatabase : this.config.createLevelDatabase,
|
|
59
|
-
keyEncoding : 'utf8',
|
|
60
|
-
});
|
|
61
|
-
await this.db.open();
|
|
62
|
-
|
|
63
|
-
// Ensure default hashes are initialized
|
|
64
|
-
await initDefaultHashes();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async close(): Promise<void> {
|
|
68
|
-
this.globalTrees.clear();
|
|
69
|
-
this.protocolTrees.clear();
|
|
70
|
-
|
|
71
|
-
await this.db.close();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async clear(): Promise<void> {
|
|
75
|
-
this.globalTrees.clear();
|
|
76
|
-
this.protocolTrees.clear();
|
|
77
|
-
|
|
78
|
-
await this.db.clear();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async insert(tenant: string, messageCid: string, indexes: KeyValues): Promise<void> {
|
|
82
|
-
// Insert into the global tree
|
|
83
|
-
const globalSmt = await this.getGlobalTree(tenant);
|
|
84
|
-
await globalSmt.insert(messageCid);
|
|
85
|
-
|
|
86
|
-
// Insert into the protocol-scoped tree if the message has a protocol (e.g. RecordsWrite).
|
|
87
|
-
// Non-record messages like ProtocolsConfigure do not have a protocol.
|
|
88
|
-
const protocol = indexes.protocol as string | undefined;
|
|
89
|
-
if (protocol !== undefined) {
|
|
90
|
-
const protoSmt = await this.getProtocolTree(tenant, protocol);
|
|
91
|
-
await protoSmt.insert(messageCid);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Store the reverse lookup so we know the protocol during deletion
|
|
95
|
-
await this.storeIndexes(tenant, messageCid, indexes);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async delete(tenant: string, messageCids: string[]): Promise<void> {
|
|
99
|
-
const globalSmt = await this.getGlobalTree(tenant);
|
|
100
|
-
|
|
101
|
-
for (const messageCid of messageCids) {
|
|
102
|
-
// Look up stored indexes to find the protocol
|
|
103
|
-
const indexes = await this.getStoredIndexes(tenant, messageCid);
|
|
104
|
-
|
|
105
|
-
// Delete from global tree
|
|
106
|
-
await globalSmt.delete(messageCid);
|
|
107
|
-
|
|
108
|
-
// Delete from protocol tree if the message had a protocol
|
|
109
|
-
if (indexes !== undefined) {
|
|
110
|
-
const protocol = indexes.protocol as string | undefined;
|
|
111
|
-
if (protocol !== undefined) {
|
|
112
|
-
const protoSmt = await this.getProtocolTree(tenant, protocol);
|
|
113
|
-
await protoSmt.delete(messageCid);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Remove the reverse lookup
|
|
118
|
-
await this.deleteStoredIndexes(tenant, messageCid);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async getRoot(tenant: string): Promise<Hash> {
|
|
123
|
-
const smt = await this.getGlobalTree(tenant);
|
|
124
|
-
return smt.getRoot();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async getProtocolRoot(tenant: string, protocol: string): Promise<Hash> {
|
|
128
|
-
const smt = await this.getProtocolTree(tenant, protocol);
|
|
129
|
-
return smt.getRoot();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async getSubtreeHash(tenant: string, prefix: boolean[]): Promise<Hash> {
|
|
133
|
-
const smt = await this.getGlobalTree(tenant);
|
|
134
|
-
return smt.getSubtreeHash(prefix);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async getProtocolSubtreeHash(tenant: string, protocol: string, prefix: boolean[]): Promise<Hash> {
|
|
138
|
-
const smt = await this.getProtocolTree(tenant, protocol);
|
|
139
|
-
return smt.getSubtreeHash(prefix);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async getLeaves(tenant: string, prefix: boolean[]): Promise<string[]> {
|
|
143
|
-
const smt = await this.getGlobalTree(tenant);
|
|
144
|
-
return smt.getLeaves(prefix);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async getProtocolLeaves(tenant: string, protocol: string, prefix: boolean[]): Promise<string[]> {
|
|
148
|
-
const smt = await this.getProtocolTree(tenant, protocol);
|
|
149
|
-
return smt.getLeaves(prefix);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ─── Private helpers ────────────────────────────────────────────────────
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Get or create the global SMT for a tenant.
|
|
156
|
-
* Uses a promise-based cache to prevent concurrent callers from racing to
|
|
157
|
-
* initialize the same tenant's SMT twice.
|
|
158
|
-
*/
|
|
159
|
-
private getGlobalTree(tenant: string): Promise<SparseMerkleTree> {
|
|
160
|
-
let smtPromise = this.globalTrees.get(tenant);
|
|
161
|
-
if (smtPromise !== undefined) {
|
|
162
|
-
return smtPromise;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
smtPromise = this.createTree(this.db, [tenant, 'global']);
|
|
166
|
-
this.globalTrees.set(tenant, smtPromise);
|
|
167
|
-
return smtPromise;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Get or create a protocol-scoped SMT for a tenant.
|
|
172
|
-
* Uses a promise-based cache to prevent concurrent callers from racing to
|
|
173
|
-
* initialize the same tenant's SMT twice.
|
|
174
|
-
*/
|
|
175
|
-
private getProtocolTree(tenant: string, protocol: string): Promise<SparseMerkleTree> {
|
|
176
|
-
const cacheKey = `${tenant}\x00${protocol}`;
|
|
177
|
-
let smtPromise = this.protocolTrees.get(cacheKey);
|
|
178
|
-
if (smtPromise !== undefined) {
|
|
179
|
-
return smtPromise;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
smtPromise = this.createTree(this.db, [tenant, 'proto', protocol]);
|
|
183
|
-
this.protocolTrees.set(cacheKey, smtPromise);
|
|
184
|
-
return smtPromise;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Create and initialize a new SparseMerkleTree backed by a sublevel chain
|
|
189
|
-
* within the single LevelDB instance.
|
|
190
|
-
*/
|
|
191
|
-
private async createTree(db: LevelWrapper<string>, sublevels: string[]): Promise<SparseMerkleTree> {
|
|
192
|
-
let partition = db;
|
|
193
|
-
for (const name of sublevels) {
|
|
194
|
-
partition = await partition.partition(name);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const store = new SMTStoreLevel(partition);
|
|
198
|
-
const smt = new SparseMerkleTree(store);
|
|
199
|
-
await smt.initialize();
|
|
200
|
-
return smt;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Store the indexes for a messageCid so we can look up the protocol during deletion.
|
|
205
|
-
*/
|
|
206
|
-
private async storeIndexes(tenant: string, messageCid: string, indexes: KeyValues): Promise<void> {
|
|
207
|
-
const metaPartition = await this.getMetaPartition(tenant);
|
|
208
|
-
// Store the protocol index needed for deletion
|
|
209
|
-
const minimalIndexes: KeyValues = { protocol: indexes.protocol };
|
|
210
|
-
await metaPartition.put(messageCid, JSON.stringify(minimalIndexes));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Get the stored indexes for a messageCid.
|
|
215
|
-
*/
|
|
216
|
-
private async getStoredIndexes(tenant: string, messageCid: string): Promise<KeyValues | undefined> {
|
|
217
|
-
const metaPartition = await this.getMetaPartition(tenant);
|
|
218
|
-
const value = await metaPartition.get(messageCid);
|
|
219
|
-
if (value === undefined) {
|
|
220
|
-
return undefined;
|
|
221
|
-
}
|
|
222
|
-
return JSON.parse(value) as KeyValues;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Delete the stored indexes for a messageCid.
|
|
227
|
-
*/
|
|
228
|
-
private async deleteStoredIndexes(tenant: string, messageCid: string): Promise<void> {
|
|
229
|
-
const metaPartition = await this.getMetaPartition(tenant);
|
|
230
|
-
await metaPartition.delete(messageCid);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Get the metadata partition for a tenant.
|
|
235
|
-
*/
|
|
236
|
-
private async getMetaPartition(tenant: string): Promise<LevelWrapper<string>> {
|
|
237
|
-
return (await this.db.partition(tenant)).partition('meta');
|
|
238
|
-
}
|
|
239
|
-
}
|
package/src/types/smt-types.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the Sparse Merkle Tree implementation.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A 32-byte hash (SHA-256 output).
|
|
7
|
-
*/
|
|
8
|
-
export type Hash = Uint8Array;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents the path through the tree as a sequence of bits derived from the key hash.
|
|
12
|
-
* Each bit determines whether to go left (0) or right (1) at each depth level.
|
|
13
|
-
*/
|
|
14
|
-
export type BitPath = boolean[];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A node in the Sparse Merkle Tree.
|
|
18
|
-
*
|
|
19
|
-
* - `internal`: has left and right child hashes but no leaf data
|
|
20
|
-
* - `leaf`: has a key hash and value (the messageCid) but no children
|
|
21
|
-
* - empty subtrees are represented implicitly via precomputed default hashes
|
|
22
|
-
*/
|
|
23
|
-
export type SMTNode =
|
|
24
|
-
| SMTInternalNode
|
|
25
|
-
| SMTLeafNode;
|
|
26
|
-
|
|
27
|
-
export type SMTInternalNode = {
|
|
28
|
-
type : 'internal';
|
|
29
|
-
leftHash : Hash;
|
|
30
|
-
rightHash : Hash;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type SMTLeafNode = {
|
|
34
|
-
type : 'leaf';
|
|
35
|
-
keyHash : Hash;
|
|
36
|
-
valueCid : string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* An inclusion or non-inclusion proof for a key in the SMT.
|
|
41
|
-
*
|
|
42
|
-
* - `siblings`: the sibling hashes along the path from leaf to root
|
|
43
|
-
* - `leafNode`: the leaf node at the path (undefined if non-inclusion proof for an empty slot)
|
|
44
|
-
* - `depth`: the depth at which the proof terminates
|
|
45
|
-
*/
|
|
46
|
-
export type SMTProof = {
|
|
47
|
-
siblings : Hash[];
|
|
48
|
-
leafNode : SMTLeafNode | undefined;
|
|
49
|
-
depth : number;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Result of diffing two SMT roots.
|
|
54
|
-
*/
|
|
55
|
-
export type SMTDiffResult = {
|
|
56
|
-
/** messageCids present in the local tree but not the remote tree */
|
|
57
|
-
onlyLocal : string[];
|
|
58
|
-
/** messageCids present in the remote tree but not the local tree */
|
|
59
|
-
onlyRemote : string[];
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Interface for persisting SMT nodes. Implementations can use LevelDB, SQL, or in-memory maps.
|
|
64
|
-
* Nodes are keyed by their hash. The root hash is stored separately.
|
|
65
|
-
*/
|
|
66
|
-
export interface SMTNodeStore {
|
|
67
|
-
open(): Promise<void>;
|
|
68
|
-
close(): Promise<void>;
|
|
69
|
-
clear(): Promise<void>;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Get a node by its hash. Returns undefined if not found.
|
|
73
|
-
*/
|
|
74
|
-
getNode(hash: Hash): Promise<SMTNode | undefined>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Store a node, keyed by its hash.
|
|
78
|
-
*/
|
|
79
|
-
putNode(hash: Hash, node: SMTNode): Promise<void>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Delete a node by its hash.
|
|
83
|
-
*/
|
|
84
|
-
deleteNode(hash: Hash): Promise<void>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Get the current root hash. Returns undefined if no root has been set.
|
|
88
|
-
*/
|
|
89
|
-
getRoot(): Promise<Hash | undefined>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Set the root hash.
|
|
93
|
-
*/
|
|
94
|
-
setRoot(hash: Hash): Promise<void>;
|
|
95
|
-
}
|
package/src/types/state-index.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Hash } from './smt-types.js';
|
|
2
|
-
import type { KeyValues } from './query-types.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A Sparse Merkle Tree-backed state index that tracks the set of messageCids
|
|
6
|
-
* for each tenant. Replaces the EventLog as the mechanism for sync state tracking.
|
|
7
|
-
*
|
|
8
|
-
* Key differences from EventLog:
|
|
9
|
-
* - No watermark ordering — the SMT is a set, not a log
|
|
10
|
-
* - Root hash provides O(1) "are we in sync?" comparison
|
|
11
|
-
* - Supports subtree hashing for O(log n) set reconciliation
|
|
12
|
-
* - Per-protocol sub-trees for scoped sync
|
|
13
|
-
*/
|
|
14
|
-
export interface StateIndex {
|
|
15
|
-
/**
|
|
16
|
-
* Opens a connection to the underlying store.
|
|
17
|
-
*/
|
|
18
|
-
open(): Promise<void>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Closes the connection to the underlying store.
|
|
22
|
-
*/
|
|
23
|
-
close(): Promise<void>;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Clears all data. Mainly used for cleaning up in test environments.
|
|
27
|
-
*/
|
|
28
|
-
clear(): Promise<void>;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Insert a message into the state index.
|
|
32
|
-
*
|
|
33
|
-
* @param tenant - the tenant's DID
|
|
34
|
-
* @param messageCid - the CID of the message
|
|
35
|
-
* @param indexes - key-value pairs from the message (used to extract `protocol` for
|
|
36
|
-
* per-protocol sub-tree maintenance, and stored for reverse lookup during deletion)
|
|
37
|
-
*/
|
|
38
|
-
insert(tenant: string, messageCid: string, indexes: KeyValues): Promise<void>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Delete messages from the state index.
|
|
42
|
-
*
|
|
43
|
-
* @param tenant - the tenant's DID
|
|
44
|
-
* @param messageCids - the CIDs of the messages to remove
|
|
45
|
-
*/
|
|
46
|
-
delete(tenant: string, messageCids: string[]): Promise<void>;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Get the SMT root hash for a tenant's global state (all protocols).
|
|
50
|
-
*
|
|
51
|
-
* @param tenant - the tenant's DID
|
|
52
|
-
* @returns the root hash. Returns the default empty root if no messages exist.
|
|
53
|
-
*/
|
|
54
|
-
getRoot(tenant: string): Promise<Hash>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get the SMT root hash for a specific protocol's state within a tenant.
|
|
58
|
-
*
|
|
59
|
-
* @param tenant - the tenant's DID
|
|
60
|
-
* @param protocol - the protocol URI
|
|
61
|
-
* @returns the root hash. Returns the default empty root if no messages exist for this protocol.
|
|
62
|
-
*/
|
|
63
|
-
getProtocolRoot(tenant: string, protocol: string): Promise<Hash>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Get the hash of a subtree at a given bit prefix within a tenant's global tree.
|
|
67
|
-
* Used by the sync protocol for tree walking during set reconciliation.
|
|
68
|
-
*
|
|
69
|
-
* @param tenant - the tenant's DID
|
|
70
|
-
* @param prefix - array of booleans representing the path (false=left, true=right)
|
|
71
|
-
*/
|
|
72
|
-
getSubtreeHash(tenant: string, prefix: boolean[]): Promise<Hash>;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Get the hash of a subtree at a given bit prefix within a protocol-scoped tree.
|
|
76
|
-
*
|
|
77
|
-
* @param tenant - the tenant's DID
|
|
78
|
-
* @param protocol - the protocol URI
|
|
79
|
-
* @param prefix - array of booleans representing the path (false=left, true=right)
|
|
80
|
-
*/
|
|
81
|
-
getProtocolSubtreeHash(tenant: string, protocol: string, prefix: boolean[]): Promise<Hash>;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Get all leaf messageCids under a given prefix in the tenant's global tree.
|
|
85
|
-
* Used by the sync protocol to enumerate leaves in a divergent subtree.
|
|
86
|
-
*
|
|
87
|
-
* @param tenant - the tenant's DID
|
|
88
|
-
* @param prefix - array of booleans representing the path
|
|
89
|
-
*/
|
|
90
|
-
getLeaves(tenant: string, prefix: boolean[]): Promise<string[]>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get all leaf messageCids under a given prefix in a protocol-scoped tree.
|
|
94
|
-
*
|
|
95
|
-
* @param tenant - the tenant's DID
|
|
96
|
-
* @param protocol - the protocol URI
|
|
97
|
-
* @param prefix - array of booleans representing the path
|
|
98
|
-
*/
|
|
99
|
-
getProtocolLeaves(tenant: string, protocol: string, prefix: boolean[]): Promise<string[]>;
|
|
100
|
-
}
|