@enbox/dwn-sdk-js 0.0.6 → 0.0.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/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +762 -911
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/abstract-message.js +4 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -1
- package/dist/esm/src/core/auth.js +22 -33
- package/dist/esm/src/core/auth.js.map +1 -1
- package/dist/esm/src/core/constants.js +11 -0
- package/dist/esm/src/core/constants.js.map +1 -0
- package/dist/esm/src/core/core-protocol.js +44 -0
- package/dist/esm/src/core/core-protocol.js.map +1 -0
- package/dist/esm/src/core/dwn-constant.js +7 -7
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +10 -12
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +50 -52
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message.js +85 -116
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +63 -78
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +266 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization-validation.js +321 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +144 -741
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/record-chain.js +64 -0
- package/dist/esm/src/core/record-chain.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +53 -72
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +50 -65
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/tenant-gate.js +2 -13
- package/dist/esm/src/core/tenant-gate.js.map +1 -1
- package/dist/esm/src/dwn.js +108 -101
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +67 -81
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +51 -63
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +75 -89
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +153 -163
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +52 -55
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +97 -85
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +75 -93
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +116 -105
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +130 -132
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +164 -104
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +213 -280
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +5 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +24 -32
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +28 -41
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/messages-sync.js +26 -40
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +87 -65
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +55 -68
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +50 -66
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +45 -55
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +60 -76
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +51 -67
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +53 -68
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-query.js +102 -0
- package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-write-signing.js +81 -0
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +396 -610
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js +23 -35
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +56 -69
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +43 -14
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +28 -14
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +325 -227
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +42 -64
- package/dist/esm/src/smt/smt-store-level.js.map +1 -1
- package/dist/esm/src/smt/smt-store-memory.js +19 -45
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
- package/dist/esm/src/smt/smt-utils.js +28 -45
- package/dist/esm/src/smt/smt-utils.js.map +1 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +113 -150
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +54 -156
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +48 -153
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +137 -100
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level-compound.js +246 -0
- package/dist/esm/src/store/index-level-compound.js.map +1 -0
- package/dist/esm/src/store/index-level.js +307 -715
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +143 -244
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +71 -94
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/resumable-task-store-level.js +62 -101
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +131 -146
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +10 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/utils/abort.js +8 -19
- package/dist/esm/src/utils/abort.js.map +1 -1
- package/dist/esm/src/utils/array.js +15 -49
- package/dist/esm/src/utils/array.js.map +1 -1
- package/dist/esm/src/utils/cid.js +29 -77
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +37 -65
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +136 -162
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/filter.js +1 -12
- package/dist/esm/src/utils/filter.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +45 -71
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +9 -20
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +12 -23
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/messages.js +21 -33
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +9 -17
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +62 -70
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +103 -166
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +60 -96
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +54 -71
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +5 -18
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/src/utils/url.js +3 -3
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +3 -12
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +50 -59
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +10 -18
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +65 -89
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +337 -347
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +160 -172
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +78 -82
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +449 -184
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +981 -360
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +45 -54
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +99 -108
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +108 -117
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-immutable.spec.js +315 -0
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +178 -194
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +456 -463
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +88 -98
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +215 -210
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +309 -171
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +272 -199
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +247 -241
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +159 -172
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +101 -105
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +266 -279
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +984 -996
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +542 -671
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +433 -302
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1216 -1140
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +190 -219
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +36 -45
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +49 -55
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +127 -138
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +372 -36
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +55 -64
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +66 -76
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +451 -354
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +160 -108
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +404 -414
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +13 -22
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +229 -238
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +12 -13
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +16 -13
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +8 -15
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +24 -33
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +48 -57
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +229 -82
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +46 -55
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +10 -19
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +3 -12
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +18 -20
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +22 -33
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +14 -27
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +446 -467
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +44 -24
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +49 -40
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +11 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/src/core/core-protocol.d.ts +89 -0
- package/dist/types/src/core/core-protocol.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +9 -12
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +6 -2
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts +81 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +24 -106
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/record-chain.d.ts +24 -0
- package/dist/types/src/core/record-chain.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +19 -7
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +3 -8
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-sync.d.ts +3 -8
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts +3 -8
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +3 -6
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +3 -8
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -8
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +3 -8
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +4 -24
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +8 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
- package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts +34 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +13 -53
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +1 -1
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +40 -3
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
- package/dist/types/src/store/data-store-level.d.ts +20 -4
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level-compound.d.ts +70 -0
- package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +4 -58
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +4 -4
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +3 -3
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +12 -3
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +24 -3
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +7 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +41 -1
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +16 -6
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/subscriptions.d.ts +151 -13
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -9
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/messages.d.ts +7 -5
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +5 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -11
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
- 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/records-immutable.spec.d.ts +2 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
- 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-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/messages-sync.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/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +11 -12
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +18 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/core/constants.ts +11 -0
- package/src/core/core-protocol.ts +129 -0
- package/src/core/dwn-error.ts +15 -12
- package/src/core/grant-authorization.ts +20 -3
- package/src/core/protocol-authorization-action.ts +377 -0
- package/src/core/protocol-authorization-validation.ts +487 -0
- package/src/core/protocol-authorization.ts +111 -856
- package/src/core/record-chain.ts +99 -0
- package/src/core/records-grant-authorization.ts +6 -8
- package/src/dwn.ts +58 -73
- package/src/event-stream/event-emitter-event-log.ts +283 -0
- package/src/handlers/messages-read.ts +8 -9
- package/src/handlers/messages-subscribe.ts +24 -28
- package/src/handlers/messages-sync.ts +10 -16
- package/src/handlers/protocols-configure.ts +47 -32
- package/src/handlers/protocols-query.ts +6 -9
- package/src/handlers/records-count.ts +11 -10
- package/src/handlers/records-delete.ts +12 -21
- package/src/handlers/records-query.ts +12 -12
- package/src/handlers/records-read.ts +34 -22
- package/src/handlers/records-subscribe.ts +47 -26
- package/src/handlers/records-write.ts +47 -104
- package/src/index.ts +9 -5
- package/src/interfaces/messages-subscribe.ts +7 -1
- package/src/interfaces/protocols-configure.ts +73 -8
- package/src/interfaces/records-count.ts +1 -1
- package/src/interfaces/records-delete.ts +1 -1
- package/src/interfaces/records-query.ts +1 -1
- package/src/interfaces/records-read.ts +1 -1
- package/src/interfaces/records-subscribe.ts +8 -1
- package/src/interfaces/records-write-query.ts +139 -0
- package/src/interfaces/records-write-signing.ts +123 -0
- package/src/interfaces/records-write.ts +66 -261
- package/src/protocols/permission-grant.ts +1 -1
- package/src/protocols/permission-request.ts +1 -1
- package/src/protocols/permissions.ts +148 -6
- package/src/state-index/state-index-level.ts +5 -7
- package/src/store/data-store-level.ts +124 -34
- package/src/store/index-level-compound.ts +324 -0
- package/src/store/index-level.ts +68 -341
- package/src/store/storage-controller.ts +11 -11
- package/src/types/message-types.ts +3 -3
- package/src/types/messages-types.ts +12 -3
- package/src/types/method-handler.ts +26 -4
- package/src/types/mitt.d.ts +28 -0
- package/src/types/permission-types.ts +7 -0
- package/src/types/protocols-types.ts +46 -0
- package/src/types/records-types.ts +16 -6
- package/src/types/subscriptions.ts +178 -14
- package/src/utils/hd-key.ts +0 -9
- package/src/utils/messages.ts +17 -37
- package/src/utils/protocols.ts +8 -0
- package/src/utils/records.ts +8 -59
- package/dist/esm/src/event-stream/event-emitter-stream.js +0 -60
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -77
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +0 -123
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
- package/src/event-stream/event-emitter-stream.ts +0 -69
package/src/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// export everything that we want to be consumable
|
|
2
2
|
export type { DwnConfig } from './dwn.js';
|
|
3
|
-
export type { EventListener,
|
|
3
|
+
export type { EventListener, EventLog, EventLogEntry, EventLogReadOptions, EventLogReadResult, EventLogSubscribeOptions, EventSubscription, MessageEvent, SubscriptionEose, SubscriptionEvent, SubscriptionListener, SubscriptionMessage, SubscriptionReply } from './types/subscriptions.js';
|
|
4
4
|
export type { AuthorizationModel, Descriptor, DelegatedGrantRecordsWriteMessage, GenericMessage, GenericMessageReply, GenericSignaturePayload, MessageSort, MessageSubscription, Pagination, QueryResultEntry, Status } from './types/message-types.js';
|
|
5
5
|
export type { MessagesFilter, MessagesReadMessage as MessagesReadMessage, MessagesReadReply as MessagesReadReply, MessagesReadReplyEntry as MessagesReadReplyEntry, MessagesReadDescriptor, MessagesSubscribeDescriptor, MessagesSubscribeMessage, MessagesSubscribeReply, MessageSubscriptionHandler, MessagesSubscribeMessageOptions, MessagesSyncAction, MessagesSyncDescriptor, MessagesSyncMessage, MessagesSyncReply } from './types/messages-types.js';
|
|
6
6
|
export type { GT, LT, Filter, FilterValue, KeyValues, EqualFilter, OneOfFilter, RangeFilter, RangeCriterion, PaginationCursor, QueryOptions, RangeValue, StartsWithFilter } from './types/query-types.js';
|
|
7
|
-
export type { ProtocolsConfigureDescriptor, ProtocolDefinition, ProtocolTypes, ProtocolRuleSet, ProtocolsQueryFilter, ProtocolsConfigureMessage, ProtocolsQueryMessage, ProtocolsQueryReply, ProtocolActionRule, ProtocolPathEncryption, ProtocolsQueryDescriptor, ProtocolSizeDefinition, ProtocolTagsDefinition, ProtocolTagSchema, ProtocolType, ProtocolUses } from './types/protocols-types.js';
|
|
7
|
+
export type { ProtocolsConfigureDescriptor, ProtocolDefinition, ProtocolTypes, ProtocolRuleSet, ProtocolsQueryFilter, ProtocolsConfigureMessage, ProtocolsQueryMessage, ProtocolsQueryReply, ProtocolActionRule, ProtocolPathEncryption, ProtocolsQueryDescriptor, ProtocolRecordLimitDefinition, ProtocolSizeDefinition, ProtocolTagsDefinition, ProtocolTagSchema, ProtocolType, ProtocolUses } from './types/protocols-types.js';
|
|
8
|
+
export { ProtocolRecordLimitStrategy } from './types/protocols-types.js';
|
|
8
9
|
export type { DataEncodedRecordsWriteMessage, RecordsCountDescriptor, RecordsCountMessage, RecordsCountReply, RecordsDeleteMessage, RecordsFilter, RecordsQueryMessage, RecordsQueryReply, RecordsQueryReplyEntry, RecordsReadMessage, RecordsReadReply, RecordsSubscribeDescriptor, RecordsSubscribeMessage, RecordsSubscribeReply, RecordSubscriptionHandler, RecordsWriteDescriptor, RecordsWriteTags, RecordsWriteTagValue, RecordsWriteMessage, RecordsWriteSignaturePayload, RecordsDeleteDescriptor, RecordsQueryDescriptor, RecordsReadDescriptor, RecordsSubscribeMessageOptions, RecordsWriteMessageOptions, InternalRecordsWriteMessage, RecordEvent, RecordsWriteTagsFilter } from './types/records-types.js';
|
|
9
10
|
export type { GeneralJws, SignatureEntry } from './types/jws-types.js';
|
|
10
11
|
export { authenticate } from './core/auth.js';
|
|
12
|
+
export { CoreProtocolRegistry } from './core/core-protocol.js';
|
|
13
|
+
export { PERMISSIONS_REVOCATION_PATH } from './core/constants.js';
|
|
14
|
+
export type { CoreProtocol, CoreProtocolStores } from './core/core-protocol.js';
|
|
11
15
|
export { AllowAllTenantGate } from './core/tenant-gate.js';
|
|
12
16
|
export type { ActiveTenantCheckResult, TenantGate } from './core/tenant-gate.js';
|
|
13
17
|
export { Cid } from './utils/cid.js';
|
|
@@ -72,7 +76,7 @@ export { Time } from './utils/time.js';
|
|
|
72
76
|
export * from './types/permission-types.js';
|
|
73
77
|
export * from './types/records-types.js';
|
|
74
78
|
|
|
75
|
-
// concrete implementations of stores and event
|
|
79
|
+
// concrete implementations of stores and event log
|
|
76
80
|
export { BlockstoreLevel } from './store/blockstore-level.js';
|
|
77
81
|
export type { BlockstoreLevelConfig } from './store/blockstore-level.js';
|
|
78
82
|
export { DataStoreLevel } from './store/data-store-level.js';
|
|
@@ -85,8 +89,8 @@ export { MessageStoreLevel } from './store/message-store-level.js';
|
|
|
85
89
|
export type { MessageStoreLevelConfig } from './store/message-store-level.js';
|
|
86
90
|
export { ResumableTaskStoreLevel } from './store/resumable-task-store-level.js';
|
|
87
91
|
export type { ResumableTaskStoreLevelConfig } from './store/resumable-task-store-level.js';
|
|
88
|
-
export {
|
|
89
|
-
export type {
|
|
92
|
+
export { EventEmitterEventLog } from './event-stream/event-emitter-event-log.js';
|
|
93
|
+
export type { EventEmitterEventLogConfig } from './event-stream/event-emitter-event-log.js';
|
|
90
94
|
|
|
91
95
|
// Sparse Merkle Tree and StateIndex
|
|
92
96
|
export type { StateIndex } from './types/state-index.js';
|
|
@@ -13,8 +13,13 @@ import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.j
|
|
|
13
13
|
export type MessagesSubscribeOptions = {
|
|
14
14
|
signer: MessageSigner;
|
|
15
15
|
messageTimestamp?: string;
|
|
16
|
-
filters?: MessagesFilter[]
|
|
16
|
+
filters?: MessagesFilter[];
|
|
17
17
|
permissionGrantId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Opaque EventLog cursor string to resume from. When provided, catch-up events are
|
|
20
|
+
* replayed from the EventLog and an EOSE marker is delivered before live events.
|
|
21
|
+
*/
|
|
22
|
+
cursor?: string;
|
|
18
23
|
};
|
|
19
24
|
|
|
20
25
|
export class MessagesSubscribe extends AbstractMessage<MessagesSubscribeMessage> {
|
|
@@ -48,6 +53,7 @@ export class MessagesSubscribe extends AbstractMessage<MessagesSubscribeMessage>
|
|
|
48
53
|
filters : options.filters ?? [],
|
|
49
54
|
messageTimestamp : options.messageTimestamp ?? currentTime,
|
|
50
55
|
permissionGrantId : options.permissionGrantId,
|
|
56
|
+
cursor : options.cursor,
|
|
51
57
|
};
|
|
52
58
|
|
|
53
59
|
removeUndefinedProperties(descriptor);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { DataEncodedRecordsWriteMessage } from '../types/records-types.js';
|
|
2
2
|
import type { MessageSigner } from '../types/signer.js';
|
|
3
3
|
import type { MessageStore } from '../types/message-store.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
ProtocolActionRule, ProtocolDefinition, ProtocolRuleSet, ProtocolsConfigureDescriptor,
|
|
6
|
+
ProtocolsConfigureMessage, ProtocolTypes, ProtocolUses
|
|
7
|
+
} from '../types/protocols-types.js';
|
|
5
8
|
|
|
6
9
|
import { AbstractMessage } from '../core/abstract-message.js';
|
|
7
10
|
import Ajv from 'ajv/dist/2020.js';
|
|
@@ -13,7 +16,7 @@ import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
|
13
16
|
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
14
17
|
import { isCrossProtocolRef, parseCrossProtocolRef } from '../utils/protocols.js';
|
|
15
18
|
import { normalizeProtocolUrl, normalizeSchemaUrl, validateProtocolUrlNormalized, validateSchemaUrlNormalized } from '../utils/url.js';
|
|
16
|
-
import { ProtocolAction, ProtocolActor } from '../types/protocols-types.js';
|
|
19
|
+
import { ProtocolAction, ProtocolActor, ProtocolRecordLimitStrategy } from '../types/protocols-types.js';
|
|
17
20
|
|
|
18
21
|
export type ProtocolsConfigureOptions = {
|
|
19
22
|
messageTimestamp?: string;
|
|
@@ -65,7 +68,7 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
65
68
|
* @param messageStore Used to check if the grant has been revoked.
|
|
66
69
|
*/
|
|
67
70
|
public async authorizeAuthorDelegate(messageStore: MessageStore): Promise<void> {
|
|
68
|
-
const delegatedGrant =
|
|
71
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization.authorDelegatedGrant!);
|
|
69
72
|
await ProtocolsGrantAuthorization.authorizeConfigure({
|
|
70
73
|
protocolsConfigureMessage : this.message,
|
|
71
74
|
expectedGrantor : this.author!,
|
|
@@ -151,7 +154,8 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
151
154
|
ruleSetProtocolPath : '',
|
|
152
155
|
recordTypes,
|
|
153
156
|
roles,
|
|
154
|
-
uses
|
|
157
|
+
uses,
|
|
158
|
+
types : definition.types,
|
|
155
159
|
});
|
|
156
160
|
}
|
|
157
161
|
|
|
@@ -196,9 +200,12 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
196
200
|
* Validates the given rule set structure then recursively validates its nested child rule sets.
|
|
197
201
|
*/
|
|
198
202
|
private static validateRuleSetRecursively(
|
|
199
|
-
input: {
|
|
203
|
+
input: {
|
|
204
|
+
ruleSet: ProtocolRuleSet, ruleSetProtocolPath: string, recordTypes: string[],
|
|
205
|
+
roles: string[], uses?: ProtocolUses, types: ProtocolTypes
|
|
206
|
+
}
|
|
200
207
|
): void {
|
|
201
|
-
const { ruleSet, ruleSetProtocolPath, recordTypes, roles, uses } = input;
|
|
208
|
+
const { ruleSet, ruleSetProtocolPath, recordTypes, roles, uses, types } = input;
|
|
202
209
|
|
|
203
210
|
// Validate $ref constraints: $ref is only supported at root level (no `/` in protocol path),
|
|
204
211
|
// and a $ref node is a pure attachment point with no other directives.
|
|
@@ -225,6 +232,27 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
225
232
|
}
|
|
226
233
|
}
|
|
227
234
|
|
|
235
|
+
// Validate $recordLimit
|
|
236
|
+
if (ruleSet.$recordLimit !== undefined) {
|
|
237
|
+
const { max, strategy } = ruleSet.$recordLimit;
|
|
238
|
+
|
|
239
|
+
if (!Number.isInteger(max) || max < 1) {
|
|
240
|
+
throw new DwnError(
|
|
241
|
+
DwnErrorCode.ProtocolsConfigureInvalidRecordLimit,
|
|
242
|
+
`Invalid $recordLimit.max value ${max} at protocol path '${ruleSetProtocolPath}': must be an integer >= 1.`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const validStrategies = Object.values(ProtocolRecordLimitStrategy) as string[];
|
|
247
|
+
if (!validStrategies.includes(strategy as string)) {
|
|
248
|
+
throw new DwnError(
|
|
249
|
+
DwnErrorCode.ProtocolsConfigureInvalidRecordLimit,
|
|
250
|
+
`Invalid $recordLimit.strategy '${strategy}' at protocol path '${ruleSetProtocolPath}': ` +
|
|
251
|
+
`must be one of ${validStrategies.join(', ')}.`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
228
256
|
if (ruleSet.$tags) {
|
|
229
257
|
const ajv = new Ajv.default();
|
|
230
258
|
const { $allowUndefinedTags, $requiredTags, ...tagProperties } = ruleSet.$tags;
|
|
@@ -370,6 +398,42 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
370
398
|
}
|
|
371
399
|
}
|
|
372
400
|
|
|
401
|
+
// Warn when `encryptionRequired: true` is combined with `{ who: 'anyone', can: ['read'] }`.
|
|
402
|
+
// Authorization allows anyone to read the record, but encryption prevents them from
|
|
403
|
+
// decrypting the data — almost certainly unintentional. (issue #115)
|
|
404
|
+
if (ruleSetProtocolPath !== '') {
|
|
405
|
+
const typeName = ruleSetProtocolPath.split('/').pop()!;
|
|
406
|
+
const protocolType = types[typeName];
|
|
407
|
+
if (protocolType?.encryptionRequired === true) {
|
|
408
|
+
const anyoneCanRead = actionRules.some(
|
|
409
|
+
(rule: ProtocolActionRule): boolean => rule.who === ProtocolActor.Anyone && rule.can.includes(ProtocolAction.Read)
|
|
410
|
+
);
|
|
411
|
+
if (anyoneCanRead) {
|
|
412
|
+
console.warn(
|
|
413
|
+
`ProtocolsConfigure: type '${typeName}' at path '${ruleSetProtocolPath}' has ` +
|
|
414
|
+
`encryptionRequired: true but allows { who: 'anyone', can: ['read'] }. ` +
|
|
415
|
+
`Anyone can read the record but no one outside the key holders can decrypt it.`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Warn when `$immutable: true` is combined with `$actions` that include `update` or `co-update`.
|
|
422
|
+
// The `$immutable` directive overrides any update permission — updates are always rejected.
|
|
423
|
+
if (ruleSet.$immutable === true && actionRules.length > 0) {
|
|
424
|
+
const hasUpdateAction = actionRules.some(
|
|
425
|
+
(rule: ProtocolActionRule): boolean =>
|
|
426
|
+
rule.can.includes(ProtocolAction.Update) || rule.can.includes(ProtocolAction.CoUpdate)
|
|
427
|
+
);
|
|
428
|
+
if (hasUpdateAction) {
|
|
429
|
+
console.warn(
|
|
430
|
+
`ProtocolsConfigure: protocol path '${ruleSetProtocolPath}' has $immutable: true ` +
|
|
431
|
+
`but $actions include 'update' or 'co-update'. The $immutable directive takes ` +
|
|
432
|
+
`precedence — updates will always be rejected regardless of action rules.`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
373
437
|
// Validate nested rule sets
|
|
374
438
|
for (const recordType in ruleSet) {
|
|
375
439
|
if (recordType.startsWith('$')) {
|
|
@@ -399,7 +463,8 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
399
463
|
ruleSetProtocolPath : childRuleSetProtocolPath,
|
|
400
464
|
recordTypes,
|
|
401
465
|
roles,
|
|
402
|
-
uses
|
|
466
|
+
uses,
|
|
467
|
+
types,
|
|
403
468
|
});
|
|
404
469
|
}
|
|
405
470
|
}
|
|
@@ -429,7 +494,7 @@ export class ProtocolsConfigure extends AbstractMessage<ProtocolsConfigureMessag
|
|
|
429
494
|
}
|
|
430
495
|
|
|
431
496
|
// validate that `$ref` nodes do not have other directives
|
|
432
|
-
const forbiddenDirectives = ['$actions', '$role', '$size', '$tags', '$encryption'] as const;
|
|
497
|
+
const forbiddenDirectives = ['$actions', '$role', '$size', '$tags', '$encryption', '$recordLimit', '$immutable'] as const;
|
|
433
498
|
for (const directive of forbiddenDirectives) {
|
|
434
499
|
if (ruleSet[directive] !== undefined) {
|
|
435
500
|
throw new DwnError(
|
|
@@ -94,7 +94,7 @@ export class RecordsCount extends AbstractMessage<RecordsCountMessage> {
|
|
|
94
94
|
* @param messageStore Used to check if the grant has been revoked.
|
|
95
95
|
*/
|
|
96
96
|
public async authorizeDelegate(messageStore: MessageStore): Promise<void> {
|
|
97
|
-
const delegatedGrant =
|
|
97
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
98
98
|
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
99
99
|
incomingMessage : this.message,
|
|
100
100
|
expectedGrantor : this.author!,
|
|
@@ -110,7 +110,7 @@ export class RecordsDelete extends AbstractMessage<RecordsDeleteMessage> {
|
|
|
110
110
|
* @param messageStore Used to check if the grant has been revoked.
|
|
111
111
|
*/
|
|
112
112
|
public async authorizeDelegate(recordsWriteToDelete: RecordsWriteMessage, messageStore: MessageStore): Promise<void> {
|
|
113
|
-
const delegatedGrant =
|
|
113
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
114
114
|
await RecordsGrantAuthorization.authorizeDelete({
|
|
115
115
|
recordsDeleteMessage : this.message,
|
|
116
116
|
recordsWriteToDelete,
|
|
@@ -119,7 +119,7 @@ export class RecordsQuery extends AbstractMessage<RecordsQueryMessage> {
|
|
|
119
119
|
* @param messageStore Used to check if the grant has been revoked.
|
|
120
120
|
*/
|
|
121
121
|
public async authorizeDelegate(messageStore: MessageStore): Promise<void> {
|
|
122
|
-
const delegatedGrant =
|
|
122
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
123
123
|
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
124
124
|
incomingMessage : this.message,
|
|
125
125
|
expectedGrantee : this.signer!,
|
|
@@ -110,7 +110,7 @@ export class RecordsRead extends AbstractMessage<RecordsReadMessage> {
|
|
|
110
110
|
* @param messageStore Used to check if the grant has been revoked.
|
|
111
111
|
*/
|
|
112
112
|
public async authorizeDelegate(matchedRecordsWrite: RecordsWriteMessage, messageStore: MessageStore): Promise<void> {
|
|
113
|
-
const delegatedGrant =
|
|
113
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
114
114
|
await RecordsGrantAuthorization.authorizeRead({
|
|
115
115
|
recordsReadMessage : this.message,
|
|
116
116
|
recordsWriteMessageToBeRead : matchedRecordsWrite,
|
|
@@ -22,6 +22,12 @@ export type RecordsSubscribeOptions = {
|
|
|
22
22
|
signer?: MessageSigner;
|
|
23
23
|
protocolRole?: string;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Opaque EventLog cursor string to resume from. When provided, catch-up events are
|
|
27
|
+
* replayed from the EventLog and an EOSE marker is delivered before live events.
|
|
28
|
+
*/
|
|
29
|
+
cursor?: string;
|
|
30
|
+
|
|
25
31
|
/**
|
|
26
32
|
* The delegated grant to sign on behalf of the logical author, which is the grantor (`grantedBy`) of the delegated grant.
|
|
27
33
|
*/
|
|
@@ -68,6 +74,7 @@ export class RecordsSubscribe extends AbstractMessage<RecordsSubscribeMessage> {
|
|
|
68
74
|
filter : Records.normalizeFilter(options.filter),
|
|
69
75
|
dateSort : options.dateSort,
|
|
70
76
|
pagination : options.pagination,
|
|
77
|
+
cursor : options.cursor,
|
|
71
78
|
};
|
|
72
79
|
|
|
73
80
|
// delete all descriptor properties that are `undefined` else the code will encounter the following IPLD issue when attempting to generate CID:
|
|
@@ -97,7 +104,7 @@ export class RecordsSubscribe extends AbstractMessage<RecordsSubscribeMessage> {
|
|
|
97
104
|
* @param messageStore Used to check if the grant has been revoked.
|
|
98
105
|
*/
|
|
99
106
|
public async authorizeDelegate(messageStore: MessageStore): Promise<void> {
|
|
100
|
-
const delegatedGrant =
|
|
107
|
+
const delegatedGrant = PermissionGrant.parse(this.message.authorization!.authorDelegatedGrant!);
|
|
101
108
|
await RecordsGrantAuthorization.authorizeQueryOrSubscribe({
|
|
102
109
|
incomingMessage : this.message,
|
|
103
110
|
expectedGrantor : this.author!,
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { GenericMessage } from '../types/message-types.js';
|
|
2
|
+
import type { MessageStore } from '../types/message-store.js';
|
|
3
|
+
import type { RecordsWrite } from './records-write.js';
|
|
4
|
+
import type { InternalRecordsWriteMessage, RecordsWriteMessage } from '../types/records-types.js';
|
|
5
|
+
|
|
6
|
+
import { Jws } from '../utils/jws.js';
|
|
7
|
+
import { Message } from '../core/message.js';
|
|
8
|
+
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
9
|
+
import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
|
|
10
|
+
|
|
11
|
+
// Late-bound import to avoid circular dependency at module-evaluation time.
|
|
12
|
+
// `RecordsWrite` imports this module; this module needs `RecordsWrite.isInitialWrite` and `.parse`.
|
|
13
|
+
let _RecordsWriteClass: typeof RecordsWrite;
|
|
14
|
+
async function getRecordsWrite(): Promise<typeof RecordsWrite> {
|
|
15
|
+
if (!_RecordsWriteClass) {
|
|
16
|
+
const mod = await import('./records-write.js');
|
|
17
|
+
_RecordsWriteClass = mod.RecordsWrite;
|
|
18
|
+
}
|
|
19
|
+
return _RecordsWriteClass;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Gets the initial write from the given list of messages.
|
|
24
|
+
*/
|
|
25
|
+
export async function getInitialWrite(messages: GenericMessage[]): Promise<RecordsWriteMessage> {
|
|
26
|
+
const RW = await getRecordsWrite();
|
|
27
|
+
for (const message of messages) {
|
|
28
|
+
if (await RW.isInitialWrite(message)) {
|
|
29
|
+
return message as RecordsWriteMessage;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw new DwnError(DwnErrorCode.RecordsWriteGetInitialWriteNotFound, `Initial write is not found.`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Verifies that immutable properties of the two given messages are identical.
|
|
38
|
+
* @throws {DwnError} if immutable properties between two RecordsWrite messages differ.
|
|
39
|
+
*/
|
|
40
|
+
export function verifyEqualityOfImmutableProperties(
|
|
41
|
+
existingWriteMessage: RecordsWriteMessage, newMessage: RecordsWriteMessage
|
|
42
|
+
): boolean {
|
|
43
|
+
const mutableDescriptorProperties = ['dataCid', 'dataSize', 'dataFormat', 'datePublished', 'published', 'messageTimestamp', 'tags'];
|
|
44
|
+
|
|
45
|
+
// get distinct property names that exist in either the existing message given or new message
|
|
46
|
+
let descriptorPropertyNames: string[] = [];
|
|
47
|
+
descriptorPropertyNames.push(...Object.keys(existingWriteMessage.descriptor));
|
|
48
|
+
descriptorPropertyNames.push(...Object.keys(newMessage.descriptor));
|
|
49
|
+
descriptorPropertyNames = [...new Set(descriptorPropertyNames)]; // step to remove duplicates
|
|
50
|
+
|
|
51
|
+
// ensure all immutable properties are not modified
|
|
52
|
+
for (const descriptorPropertyName of descriptorPropertyNames) {
|
|
53
|
+
// if property is supposed to be immutable
|
|
54
|
+
if (mutableDescriptorProperties.indexOf(descriptorPropertyName) === -1) {
|
|
55
|
+
const valueInExistingWrite = (existingWriteMessage.descriptor as Record<string, unknown>)[descriptorPropertyName];
|
|
56
|
+
const valueInNewMessage = (newMessage.descriptor as Record<string, unknown>)[descriptorPropertyName];
|
|
57
|
+
if (valueInNewMessage !== valueInExistingWrite) {
|
|
58
|
+
throw new DwnError(
|
|
59
|
+
DwnErrorCode.RecordsWriteImmutablePropertyChanged,
|
|
60
|
+
`${descriptorPropertyName} is an immutable property: cannot change '${valueInExistingWrite}' to '${valueInNewMessage}'`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets the DID of the attesters of the given message.
|
|
71
|
+
*/
|
|
72
|
+
export function getAttesters(message: InternalRecordsWriteMessage): string[] {
|
|
73
|
+
const attestationSignatures = message.attestation?.signatures ?? [];
|
|
74
|
+
const attesters = attestationSignatures.map((signature): string => Jws.getSignerDid(signature));
|
|
75
|
+
return attesters;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Fetches the newest RecordsWrite for a given recordId from the message store.
|
|
80
|
+
* @throws {DwnError} if no write is found.
|
|
81
|
+
*/
|
|
82
|
+
export async function fetchNewestRecordsWrite(
|
|
83
|
+
messageStore: MessageStore,
|
|
84
|
+
tenant: string,
|
|
85
|
+
recordId: string,
|
|
86
|
+
): Promise<RecordsWriteMessage> {
|
|
87
|
+
// get existing RecordsWrite messages matching the `recordId`
|
|
88
|
+
const query = {
|
|
89
|
+
interface : DwnInterfaceName.Records,
|
|
90
|
+
method : DwnMethodName.Write,
|
|
91
|
+
recordId : recordId
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const { messages: existingMessages } = await messageStore.query(tenant, [ query ]);
|
|
95
|
+
const newestWrite = await Message.getNewestMessage(existingMessages);
|
|
96
|
+
if (newestWrite !== undefined) {
|
|
97
|
+
return newestWrite as RecordsWriteMessage;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
throw new DwnError(DwnErrorCode.RecordsWriteGetNewestWriteRecordNotFound, 'record not found');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Fetches the initial RecordsWrite of a record.
|
|
105
|
+
* @returns The initial RecordsWrite if found; `undefined` otherwise.
|
|
106
|
+
*/
|
|
107
|
+
export async function fetchInitialRecordsWrite(
|
|
108
|
+
messageStore: MessageStore,
|
|
109
|
+
tenant: string,
|
|
110
|
+
recordId: string
|
|
111
|
+
): Promise<RecordsWrite | undefined> {
|
|
112
|
+
const initialRecordsWriteMessage = await fetchInitialRecordsWriteMessage(messageStore, tenant, recordId);
|
|
113
|
+
if (initialRecordsWriteMessage === undefined) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const RW = await getRecordsWrite();
|
|
118
|
+
const initialRecordsWrite = await RW.parse(initialRecordsWriteMessage);
|
|
119
|
+
return initialRecordsWrite;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Fetches the initial RecordsWrite message of a record.
|
|
124
|
+
* @returns The initial RecordsWriteMessage if found; `undefined` otherwise.
|
|
125
|
+
*/
|
|
126
|
+
export async function fetchInitialRecordsWriteMessage(
|
|
127
|
+
messageStore: MessageStore,
|
|
128
|
+
tenant: string,
|
|
129
|
+
recordId: string
|
|
130
|
+
): Promise<RecordsWriteMessage | undefined> {
|
|
131
|
+
const query = { entryId: recordId };
|
|
132
|
+
const { messages } = await messageStore.query(tenant, [query]);
|
|
133
|
+
|
|
134
|
+
if (messages.length === 0) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return messages[0] as RecordsWriteMessage;
|
|
139
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { GeneralJws } from '../types/jws-types.js';
|
|
2
|
+
import type { MessageSigner } from '../types/signer.js';
|
|
3
|
+
import type { EncryptionInput, JweEncryption } from '../utils/encryption.js';
|
|
4
|
+
import type { RecordsWriteAttestationPayload, RecordsWriteMessage, RecordsWriteSignaturePayload } from '../types/records-types.js';
|
|
5
|
+
|
|
6
|
+
import { Cid } from '../utils/cid.js';
|
|
7
|
+
import { Encoder } from '../utils/encoder.js';
|
|
8
|
+
import { Encryption } from '../utils/encryption.js';
|
|
9
|
+
import { GeneralJwsBuilder } from '../jose/jws/general/builder.js';
|
|
10
|
+
import { Jws } from '../utils/jws.js';
|
|
11
|
+
import { removeUndefinedProperties } from '../utils/object.js';
|
|
12
|
+
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates the JWE `encryption` property if encryption input is given. Else `undefined` is returned.
|
|
16
|
+
* Uses ECDH-ES+A256KW key agreement with X25519 and AEAD content encryption (A256GCM or XC20P).
|
|
17
|
+
* @param encryptionInput The encryption input containing CEK, IV, authentication tag, and recipient key encryption inputs.
|
|
18
|
+
*/
|
|
19
|
+
export async function createEncryptionProperty(
|
|
20
|
+
encryptionInput: EncryptionInput | undefined,
|
|
21
|
+
): Promise<JweEncryption | undefined> {
|
|
22
|
+
if (encryptionInput === undefined) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Build the JWE structure. The authentication tag comes from the AEAD encryption of record data.
|
|
27
|
+
const jwe = await Encryption.buildJwe(encryptionInput, encryptionInput.authenticationTag);
|
|
28
|
+
|
|
29
|
+
return jwe;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates the `attestation` property of a RecordsWrite message if given signature inputs; returns `undefined` otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export async function createAttestation(descriptorCid: string, signers?: MessageSigner[]): Promise<GeneralJws | undefined> {
|
|
36
|
+
if (signers === undefined || signers.length === 0) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const attestationPayload: RecordsWriteAttestationPayload = { descriptorCid };
|
|
41
|
+
const attestationPayloadBytes = Encoder.objectToBytes(attestationPayload);
|
|
42
|
+
|
|
43
|
+
const builder = await GeneralJwsBuilder.create(attestationPayloadBytes, signers);
|
|
44
|
+
return builder.getJws();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates the `signature` property in the `authorization` of a `RecordsWrite` message.
|
|
49
|
+
*/
|
|
50
|
+
export async function createSignerSignature(input: {
|
|
51
|
+
recordId: string,
|
|
52
|
+
contextId: string,
|
|
53
|
+
descriptorCid: string,
|
|
54
|
+
attestation: GeneralJws | undefined,
|
|
55
|
+
encryption: JweEncryption | undefined,
|
|
56
|
+
signer: MessageSigner,
|
|
57
|
+
delegatedGrantId?: string,
|
|
58
|
+
permissionGrantId?: string,
|
|
59
|
+
protocolRole?: string
|
|
60
|
+
}): Promise<GeneralJws> {
|
|
61
|
+
const { recordId, contextId, descriptorCid, attestation, encryption, signer, delegatedGrantId, permissionGrantId, protocolRole } = input;
|
|
62
|
+
|
|
63
|
+
const attestationCid = attestation ? await Cid.computeCid(attestation) : undefined;
|
|
64
|
+
const encryptionCid = encryption ? await Cid.computeCid(encryption) : undefined;
|
|
65
|
+
|
|
66
|
+
const signaturePayload: RecordsWriteSignaturePayload = {
|
|
67
|
+
recordId,
|
|
68
|
+
descriptorCid,
|
|
69
|
+
contextId,
|
|
70
|
+
attestationCid,
|
|
71
|
+
encryptionCid,
|
|
72
|
+
delegatedGrantId,
|
|
73
|
+
permissionGrantId,
|
|
74
|
+
protocolRole
|
|
75
|
+
};
|
|
76
|
+
removeUndefinedProperties(signaturePayload);
|
|
77
|
+
|
|
78
|
+
const signaturePayloadBytes = Encoder.objectToBytes(signaturePayload);
|
|
79
|
+
|
|
80
|
+
const builder = await GeneralJwsBuilder.create(signaturePayloadBytes, [signer]);
|
|
81
|
+
const signature = builder.getJws();
|
|
82
|
+
|
|
83
|
+
return signature;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Validates the structural integrity of the `attestation` property.
|
|
88
|
+
* NOTE: Cryptographic verification of attestation signatures is performed in `authenticate()`.
|
|
89
|
+
*/
|
|
90
|
+
export async function validateAttestationIntegrity(message: RecordsWriteMessage): Promise<void> {
|
|
91
|
+
if (message.attestation === undefined) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// TODO: support multiple attesters (https://github.com/enboxorg/enbox/issues/223)
|
|
96
|
+
if (message.attestation.signatures.length !== 1) {
|
|
97
|
+
throw new DwnError(
|
|
98
|
+
DwnErrorCode.RecordsWriteAttestationIntegrityMoreThanOneSignature,
|
|
99
|
+
`Currently implementation only supports 1 attester, but got ${message.attestation.signatures.length}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const payloadJson = Jws.decodePlainObjectPayload(message.attestation);
|
|
104
|
+
const { descriptorCid } = payloadJson;
|
|
105
|
+
|
|
106
|
+
// `descriptorCid` validation - ensure that the provided descriptorCid matches the CID of the actual message
|
|
107
|
+
const expectedDescriptorCid = await Cid.computeCid(message.descriptor);
|
|
108
|
+
if (descriptorCid !== expectedDescriptorCid) {
|
|
109
|
+
throw new DwnError(
|
|
110
|
+
DwnErrorCode.RecordsWriteAttestationIntegrityDescriptorCidMismatch,
|
|
111
|
+
`descriptorCid ${descriptorCid} does not match expected descriptorCid ${expectedDescriptorCid}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// check to ensure that no other unexpected properties exist in payload.
|
|
116
|
+
const propertyCount = Object.keys(payloadJson).length;
|
|
117
|
+
if (propertyCount > 1) {
|
|
118
|
+
throw new DwnError(
|
|
119
|
+
DwnErrorCode.RecordsWriteAttestationIntegrityInvalidPayloadProperty,
|
|
120
|
+
`Only 'descriptorCid' is allowed in attestation payload, but got ${propertyCount} properties.`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|