@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
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
1
|
+
import { DwnConstant } from '../core/dwn-constant.js';
|
|
10
2
|
import { Encoder } from '../utils/encoder.js';
|
|
3
|
+
import { FilterUtility } from '../utils/filter.js';
|
|
4
|
+
import { Message } from '../core/message.js';
|
|
11
5
|
import { PermissionGrant } from './permission-grant.js';
|
|
12
6
|
import { PermissionRequest } from './permission-request.js';
|
|
13
|
-
import {
|
|
7
|
+
import { Records } from '../utils/records.js';
|
|
8
|
+
import { RecordsWrite } from '../interfaces/records-write.js';
|
|
14
9
|
import { Time } from '../utils/time.js';
|
|
15
10
|
import { validateJsonSchema } from '../schema-validator.js';
|
|
16
11
|
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
@@ -18,135 +13,312 @@ import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.j
|
|
|
18
13
|
import { normalizeProtocolUrl, validateProtocolUrlNormalized } from '../utils/url.js';
|
|
19
14
|
/**
|
|
20
15
|
* This is a first-class DWN protocol for managing permission grants of a given DWN.
|
|
16
|
+
*
|
|
17
|
+
* It implements the `CoreProtocol` interface so that its lifecycle hooks
|
|
18
|
+
* (validation, pre-processing, post-processing) are dispatched generically
|
|
19
|
+
* by the `CoreProtocolRegistry` rather than being hardcoded in handlers.
|
|
21
20
|
*/
|
|
22
21
|
export class PermissionsProtocol {
|
|
22
|
+
/**
|
|
23
|
+
* The URI of the DWN Permissions protocol.
|
|
24
|
+
*/
|
|
25
|
+
static uri = 'https://identity.foundation/dwn/permissions';
|
|
26
|
+
/**
|
|
27
|
+
* The protocol path of the `request` record.
|
|
28
|
+
*/
|
|
29
|
+
static requestPath = 'request';
|
|
30
|
+
/**
|
|
31
|
+
* The protocol path of the `grant` record.
|
|
32
|
+
*/
|
|
33
|
+
static grantPath = 'grant';
|
|
34
|
+
/**
|
|
35
|
+
* The protocol path of the `revocation` record.
|
|
36
|
+
*/
|
|
37
|
+
static revocationPath = 'grant/revocation';
|
|
38
|
+
/**
|
|
39
|
+
* The definition of the Permissions protocol.
|
|
40
|
+
*/
|
|
41
|
+
static definition = {
|
|
42
|
+
published: true,
|
|
43
|
+
protocol: PermissionsProtocol.uri,
|
|
44
|
+
types: {
|
|
45
|
+
request: {
|
|
46
|
+
dataFormats: ['application/json']
|
|
47
|
+
},
|
|
48
|
+
grant: {
|
|
49
|
+
dataFormats: ['application/json']
|
|
50
|
+
},
|
|
51
|
+
revocation: {
|
|
52
|
+
dataFormats: ['application/json']
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
structure: {
|
|
56
|
+
request: {
|
|
57
|
+
$size: {
|
|
58
|
+
max: 10000
|
|
59
|
+
},
|
|
60
|
+
$actions: [
|
|
61
|
+
{
|
|
62
|
+
who: 'anyone',
|
|
63
|
+
can: ['create']
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
grant: {
|
|
68
|
+
$size: {
|
|
69
|
+
max: 10000
|
|
70
|
+
},
|
|
71
|
+
$actions: [
|
|
72
|
+
{
|
|
73
|
+
who: 'recipient',
|
|
74
|
+
of: 'grant',
|
|
75
|
+
can: ['read']
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
revocation: {
|
|
79
|
+
$size: {
|
|
80
|
+
max: 10000
|
|
81
|
+
},
|
|
82
|
+
$actions: [
|
|
83
|
+
{
|
|
84
|
+
who: 'anyone',
|
|
85
|
+
can: ['read']
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// ---------- CoreProtocol instance accessors ----------
|
|
93
|
+
/** @inheritdoc */
|
|
94
|
+
get uri() {
|
|
95
|
+
return PermissionsProtocol.uri;
|
|
96
|
+
}
|
|
97
|
+
/** @inheritdoc */
|
|
98
|
+
get definition() {
|
|
99
|
+
return PermissionsProtocol.definition;
|
|
100
|
+
}
|
|
101
|
+
// ---------- CoreProtocol lifecycle hooks ----------
|
|
102
|
+
/** @inheritdoc */
|
|
103
|
+
validateRecord(message, dataBytes) {
|
|
104
|
+
PermissionsProtocol.validateSchema(message, dataBytes);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Pre-processing hook for permission revocation records.
|
|
108
|
+
* Validates that the revocation's `tags.protocol` matches the grant's scoped protocol.
|
|
109
|
+
*/
|
|
110
|
+
async preProcessWrite(tenant, message, messageStore) {
|
|
111
|
+
if (message.descriptor.protocolPath !== PermissionsProtocol.revocationPath) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// fetch the parent grant to compare the scoped protocol against the revocation tag
|
|
115
|
+
const permissionGrantId = message.descriptor.parentId;
|
|
116
|
+
const grant = await PermissionsProtocol.fetchGrant(tenant, messageStore, permissionGrantId);
|
|
117
|
+
const revokeTagProtocol = message.descriptor.tags?.protocol;
|
|
118
|
+
const grantProtocol = 'protocol' in grant.scope ? grant.scope.protocol : undefined;
|
|
119
|
+
if (grantProtocol !== revokeTagProtocol) {
|
|
120
|
+
throw new DwnError(DwnErrorCode.PermissionsProtocolValidateRevocationProtocolTagMismatch, `Revocation protocol ${revokeTagProtocol} does not match grant protocol ${grantProtocol}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Post-processing hook for permission revocation records.
|
|
125
|
+
* When a grant is revoked, all messages authorized by that grant and created
|
|
126
|
+
* after the revocation timestamp are deleted from all stores.
|
|
127
|
+
*
|
|
128
|
+
* Deletion order is deliberate to avoid orphaned data in case of crash:
|
|
129
|
+
* 1. data store (large blobs first)
|
|
130
|
+
* 2. state index (SMT entries)
|
|
131
|
+
* 3. message store
|
|
132
|
+
*/
|
|
133
|
+
async postProcessWrite(tenant, recordsWrite, stores) {
|
|
134
|
+
if (recordsWrite.message.descriptor.protocolPath !== PermissionsProtocol.revocationPath) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const permissionGrantId = recordsWrite.message.descriptor.parentId;
|
|
138
|
+
const grantAuthorizedMessagesQuery = {
|
|
139
|
+
permissionGrantId,
|
|
140
|
+
dateCreated: { gte: recordsWrite.message.descriptor.messageTimestamp },
|
|
141
|
+
};
|
|
142
|
+
const { messages: grantAuthorizedMessages } = await stores.messageStore.query(tenant, [grantAuthorizedMessagesQuery]);
|
|
143
|
+
if (grantAuthorizedMessages.length === 0) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// 1. Delete data from the data store first to avoid orphaned data blobs in case of crash.
|
|
147
|
+
// Only RecordsWrite messages with data larger than maxDataSizeAllowedToBeEncoded have data in the data store.
|
|
148
|
+
for (const message of grantAuthorizedMessages) {
|
|
149
|
+
if (message.descriptor.method === DwnMethodName.Write) {
|
|
150
|
+
const recordsWriteMessage = message;
|
|
151
|
+
if (recordsWriteMessage.descriptor.dataSize > DwnConstant.maxDataSizeAllowedToBeEncoded) {
|
|
152
|
+
await stores.dataStore.delete(tenant, recordsWriteMessage.recordId, recordsWriteMessage.descriptor.dataCid);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// 2. Compute CIDs and delete from state index before message store to avoid orphaned state entries.
|
|
157
|
+
const messageCids = await Promise.all(grantAuthorizedMessages.map((message) => Message.getCid(message)));
|
|
158
|
+
await stores.stateIndex.delete(tenant, messageCids);
|
|
159
|
+
// 3. Finally delete all messages from the message store.
|
|
160
|
+
await Promise.all(messageCids.map((cid) => stores.messageStore.delete(tenant, cid)));
|
|
161
|
+
}
|
|
162
|
+
/** @inheritdoc */
|
|
163
|
+
mapErrorToStatusCode(errorCode) {
|
|
164
|
+
if (errorCode.startsWith('PermissionsProtocolValidate')) {
|
|
165
|
+
return 400;
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Constructs an additional filter for protocol-scoped message queries so that
|
|
171
|
+
* permission records (grants, requests, revocations) tagged with the target
|
|
172
|
+
* protocol appear alongside that protocol's own records in sync/subscribe/read results.
|
|
173
|
+
*/
|
|
174
|
+
constructAdditionalMessageFilter(filter) {
|
|
175
|
+
const { protocol, messageTimestamp } = filter;
|
|
176
|
+
if (protocol === undefined) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
const taggedFilter = {
|
|
180
|
+
protocol: PermissionsProtocol.uri,
|
|
181
|
+
...Records.convertTagsFilter({ protocol }),
|
|
182
|
+
};
|
|
183
|
+
if (messageTimestamp !== undefined) {
|
|
184
|
+
const messageTimestampFilter = FilterUtility.convertRangeCriterion(messageTimestamp);
|
|
185
|
+
if (messageTimestampFilter) {
|
|
186
|
+
taggedFilter.messageTimestamp = messageTimestampFilter;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return taggedFilter;
|
|
190
|
+
}
|
|
191
|
+
// ---------- Static utility methods ----------
|
|
23
192
|
static parseRequest(base64UrlEncodedRequest) {
|
|
24
193
|
return Encoder.base64UrlToObject(base64UrlEncodedRequest);
|
|
25
194
|
}
|
|
26
195
|
/**
|
|
27
196
|
* Convenience method to create a permission request.
|
|
28
197
|
*/
|
|
29
|
-
static createRequest(options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
protocol: scope.protocol
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const permissionRequestBytes = Encoder.objectToBytes(permissionRequestData);
|
|
50
|
-
const recordsWrite = yield RecordsWrite.create({
|
|
51
|
-
signer: options.signer,
|
|
52
|
-
messageTimestamp: options.dateRequested,
|
|
53
|
-
protocol: PermissionsProtocol.uri,
|
|
54
|
-
protocolPath: PermissionsProtocol.requestPath,
|
|
55
|
-
dataFormat: 'application/json',
|
|
56
|
-
data: permissionRequestBytes,
|
|
57
|
-
tags: permissionTags,
|
|
58
|
-
});
|
|
59
|
-
const dataEncodedMessage = Object.assign(Object.assign({}, recordsWrite.message), { encodedData: Encoder.bytesToBase64Url(permissionRequestBytes) });
|
|
60
|
-
return {
|
|
61
|
-
recordsWrite,
|
|
62
|
-
permissionRequestData,
|
|
63
|
-
permissionRequestBytes,
|
|
64
|
-
dataEncodedMessage
|
|
198
|
+
static async createRequest(options) {
|
|
199
|
+
if (this.isRecordPermissionScope(options.scope) && options.scope.protocol === undefined) {
|
|
200
|
+
throw new DwnError(DwnErrorCode.PermissionsProtocolCreateRequestRecordsScopeMissingProtocol, 'Permission request for Records must have a scope with a `protocol` property');
|
|
201
|
+
}
|
|
202
|
+
const scope = PermissionsProtocol.normalizePermissionScope(options.scope);
|
|
203
|
+
const permissionRequestData = {
|
|
204
|
+
description: options.description,
|
|
205
|
+
delegated: options.delegated,
|
|
206
|
+
scope,
|
|
207
|
+
conditions: options.conditions,
|
|
208
|
+
};
|
|
209
|
+
// If the request is scoped to a protocol, the protocol tag must be included with the record.
|
|
210
|
+
// This is done in order to ensure a subset message query filtered to a protocol includes the permission requests associated with it.
|
|
211
|
+
let permissionTags = undefined;
|
|
212
|
+
if (this.hasProtocolScope(scope)) {
|
|
213
|
+
permissionTags = {
|
|
214
|
+
protocol: scope.protocol
|
|
65
215
|
};
|
|
216
|
+
}
|
|
217
|
+
const permissionRequestBytes = Encoder.objectToBytes(permissionRequestData);
|
|
218
|
+
const recordsWrite = await RecordsWrite.create({
|
|
219
|
+
signer: options.signer,
|
|
220
|
+
messageTimestamp: options.dateRequested,
|
|
221
|
+
protocol: PermissionsProtocol.uri,
|
|
222
|
+
protocolPath: PermissionsProtocol.requestPath,
|
|
223
|
+
dataFormat: 'application/json',
|
|
224
|
+
data: permissionRequestBytes,
|
|
225
|
+
tags: permissionTags,
|
|
66
226
|
});
|
|
227
|
+
const dataEncodedMessage = {
|
|
228
|
+
...recordsWrite.message,
|
|
229
|
+
encodedData: Encoder.bytesToBase64Url(permissionRequestBytes)
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
recordsWrite,
|
|
233
|
+
permissionRequestData,
|
|
234
|
+
permissionRequestBytes,
|
|
235
|
+
dataEncodedMessage
|
|
236
|
+
};
|
|
67
237
|
}
|
|
68
238
|
/**
|
|
69
239
|
* Convenience method to create a permission grant.
|
|
70
240
|
*/
|
|
71
|
-
static createGrant(options) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
protocol: scope.protocol
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const permissionGrantBytes = Encoder.objectToBytes(permissionGrantData);
|
|
94
|
-
const recordsWrite = yield RecordsWrite.create({
|
|
95
|
-
signer: options.signer,
|
|
96
|
-
messageTimestamp: options.dateGranted,
|
|
97
|
-
dateCreated: options.dateGranted,
|
|
98
|
-
recipient: options.grantedTo,
|
|
99
|
-
protocol: PermissionsProtocol.uri,
|
|
100
|
-
protocolPath: PermissionsProtocol.grantPath,
|
|
101
|
-
dataFormat: 'application/json',
|
|
102
|
-
data: permissionGrantBytes,
|
|
103
|
-
tags: permissionTags,
|
|
104
|
-
});
|
|
105
|
-
const dataEncodedMessage = Object.assign(Object.assign({}, recordsWrite.message), { encodedData: Encoder.bytesToBase64Url(permissionGrantBytes) });
|
|
106
|
-
return {
|
|
107
|
-
recordsWrite,
|
|
108
|
-
permissionGrantData,
|
|
109
|
-
permissionGrantBytes,
|
|
110
|
-
dataEncodedMessage
|
|
241
|
+
static async createGrant(options) {
|
|
242
|
+
if (this.isRecordPermissionScope(options.scope) && options.scope.protocol === undefined) {
|
|
243
|
+
throw new DwnError(DwnErrorCode.PermissionsProtocolCreateGrantRecordsScopeMissingProtocol, 'Permission grants for Records must have a scope with a `protocol` property');
|
|
244
|
+
}
|
|
245
|
+
const scope = PermissionsProtocol.normalizePermissionScope(options.scope);
|
|
246
|
+
const permissionGrantData = {
|
|
247
|
+
dateExpires: options.dateExpires,
|
|
248
|
+
requestId: options.requestId,
|
|
249
|
+
description: options.description,
|
|
250
|
+
delegated: options.delegated,
|
|
251
|
+
scope,
|
|
252
|
+
conditions: options.conditions,
|
|
253
|
+
};
|
|
254
|
+
// If the grant is scoped to a protocol, the protocol tag must be included with the record.
|
|
255
|
+
// This is done in order to ensure a subset message query filtered to a protocol includes the permission grants associated with it.
|
|
256
|
+
let permissionTags = undefined;
|
|
257
|
+
if (this.hasProtocolScope(scope)) {
|
|
258
|
+
permissionTags = {
|
|
259
|
+
protocol: scope.protocol
|
|
111
260
|
};
|
|
261
|
+
}
|
|
262
|
+
const permissionGrantBytes = Encoder.objectToBytes(permissionGrantData);
|
|
263
|
+
const recordsWrite = await RecordsWrite.create({
|
|
264
|
+
signer: options.signer,
|
|
265
|
+
messageTimestamp: options.dateGranted,
|
|
266
|
+
dateCreated: options.dateGranted,
|
|
267
|
+
recipient: options.grantedTo,
|
|
268
|
+
protocol: PermissionsProtocol.uri,
|
|
269
|
+
protocolPath: PermissionsProtocol.grantPath,
|
|
270
|
+
dataFormat: 'application/json',
|
|
271
|
+
data: permissionGrantBytes,
|
|
272
|
+
tags: permissionTags,
|
|
112
273
|
});
|
|
274
|
+
const dataEncodedMessage = {
|
|
275
|
+
...recordsWrite.message,
|
|
276
|
+
encodedData: Encoder.bytesToBase64Url(permissionGrantBytes)
|
|
277
|
+
};
|
|
278
|
+
return {
|
|
279
|
+
recordsWrite,
|
|
280
|
+
permissionGrantData,
|
|
281
|
+
permissionGrantBytes,
|
|
282
|
+
dataEncodedMessage
|
|
283
|
+
};
|
|
113
284
|
}
|
|
114
285
|
/**
|
|
115
286
|
* Convenience method to create a permission revocation.
|
|
116
287
|
*/
|
|
117
|
-
static createRevocation(options) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
tags: permissionTags,
|
|
141
|
-
});
|
|
142
|
-
const dataEncodedMessage = Object.assign(Object.assign({}, recordsWrite.message), { encodedData: Encoder.bytesToBase64Url(permissionRevocationBytes) });
|
|
143
|
-
return {
|
|
144
|
-
recordsWrite,
|
|
145
|
-
permissionRevocationData,
|
|
146
|
-
permissionRevocationBytes,
|
|
147
|
-
dataEncodedMessage
|
|
148
|
-
};
|
|
288
|
+
static async createRevocation(options) {
|
|
289
|
+
const permissionRevocationData = {
|
|
290
|
+
description: options.description,
|
|
291
|
+
};
|
|
292
|
+
const grantId = options.grant.id;
|
|
293
|
+
// if the grant was scoped to a protocol, the protocol tag must be included in the revocation
|
|
294
|
+
// This is done in order to ensure a subset message query filtered to a protocol includes the permission revocations associated with it.
|
|
295
|
+
//
|
|
296
|
+
// NOTE: the added tag is validated against the original grant when the revocation is processed by the DWN.
|
|
297
|
+
let permissionTags = undefined;
|
|
298
|
+
if (this.hasProtocolScope(options.grant.scope)) {
|
|
299
|
+
const protocol = normalizeProtocolUrl(options.grant.scope.protocol);
|
|
300
|
+
permissionTags = { protocol };
|
|
301
|
+
}
|
|
302
|
+
const permissionRevocationBytes = Encoder.objectToBytes(permissionRevocationData);
|
|
303
|
+
const recordsWrite = await RecordsWrite.create({
|
|
304
|
+
signer: options.signer,
|
|
305
|
+
parentContextId: grantId, // NOTE: since the grant is the root record, its record ID is also the context ID
|
|
306
|
+
protocol: PermissionsProtocol.uri,
|
|
307
|
+
protocolPath: PermissionsProtocol.revocationPath,
|
|
308
|
+
dataFormat: 'application/json',
|
|
309
|
+
data: permissionRevocationBytes,
|
|
310
|
+
tags: permissionTags,
|
|
149
311
|
});
|
|
312
|
+
const dataEncodedMessage = {
|
|
313
|
+
...recordsWrite.message,
|
|
314
|
+
encodedData: Encoder.bytesToBase64Url(permissionRevocationBytes)
|
|
315
|
+
};
|
|
316
|
+
return {
|
|
317
|
+
recordsWrite,
|
|
318
|
+
permissionRevocationData,
|
|
319
|
+
permissionRevocationBytes,
|
|
320
|
+
dataEncodedMessage
|
|
321
|
+
};
|
|
150
322
|
}
|
|
151
323
|
/**
|
|
152
324
|
* Validates the given Permissions protocol RecordsWrite. It can be a request, grant, or revocation.
|
|
@@ -180,25 +352,23 @@ export class PermissionsProtocol {
|
|
|
180
352
|
* @returns the PermissionGrant matching the `recordId` specified.
|
|
181
353
|
* @throws {Error} if PermissionGrant does not exist
|
|
182
354
|
*/
|
|
183
|
-
static fetchGrant(tenant, messageStore, permissionGrantId) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return permissionGrant;
|
|
201
|
-
});
|
|
355
|
+
static async fetchGrant(tenant, messageStore, permissionGrantId) {
|
|
356
|
+
const grantQuery = {
|
|
357
|
+
recordId: permissionGrantId,
|
|
358
|
+
isLatestBaseState: true
|
|
359
|
+
};
|
|
360
|
+
const { messages } = await messageStore.query(tenant, [grantQuery]);
|
|
361
|
+
const possibleGrantMessage = messages[0];
|
|
362
|
+
const dwnInterface = possibleGrantMessage?.descriptor.interface;
|
|
363
|
+
const dwnMethod = possibleGrantMessage?.descriptor.method;
|
|
364
|
+
if (dwnInterface !== DwnInterfaceName.Records ||
|
|
365
|
+
dwnMethod !== DwnMethodName.Write ||
|
|
366
|
+
possibleGrantMessage.descriptor.protocolPath !== PermissionsProtocol.grantPath) {
|
|
367
|
+
throw new DwnError(DwnErrorCode.GrantAuthorizationGrantMissing, `Could not find permission grant with record ID ${permissionGrantId}.`);
|
|
368
|
+
}
|
|
369
|
+
const permissionGrantMessage = possibleGrantMessage;
|
|
370
|
+
const permissionGrant = PermissionGrant.parse(permissionGrantMessage);
|
|
371
|
+
return permissionGrant;
|
|
202
372
|
}
|
|
203
373
|
/**
|
|
204
374
|
* Gets the scope from the given permission record.
|
|
@@ -206,32 +376,30 @@ export class PermissionsProtocol {
|
|
|
206
376
|
*
|
|
207
377
|
* @param messageStore The message store to fetch the grant for a revocation.
|
|
208
378
|
*/
|
|
209
|
-
static getScopeFromPermissionRecord(tenant, messageStore, incomingMessage) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
});
|
|
379
|
+
static async getScopeFromPermissionRecord(tenant, messageStore, incomingMessage) {
|
|
380
|
+
if (incomingMessage.descriptor.protocol !== PermissionsProtocol.uri) {
|
|
381
|
+
throw new DwnError(DwnErrorCode.PermissionsProtocolGetScopeInvalidProtocol, `Unexpected protocol for permission record: ${incomingMessage.descriptor.protocol}`);
|
|
382
|
+
}
|
|
383
|
+
if (incomingMessage.descriptor.protocolPath === PermissionsProtocol.revocationPath) {
|
|
384
|
+
const grant = await PermissionsProtocol.fetchGrant(tenant, messageStore, incomingMessage.descriptor.parentId);
|
|
385
|
+
return grant.scope;
|
|
386
|
+
}
|
|
387
|
+
else if (incomingMessage.descriptor.protocolPath === PermissionsProtocol.grantPath) {
|
|
388
|
+
const grant = PermissionGrant.parse(incomingMessage);
|
|
389
|
+
return grant.scope;
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
// if the record is not a grant or revocation, it must be a request
|
|
393
|
+
const request = PermissionRequest.parse(incomingMessage);
|
|
394
|
+
return request.scope;
|
|
395
|
+
}
|
|
228
396
|
}
|
|
229
397
|
/**
|
|
230
398
|
* Normalizes the given permission scope if needed.
|
|
231
399
|
* @returns The normalized permission scope.
|
|
232
400
|
*/
|
|
233
401
|
static normalizePermissionScope(permissionScope) {
|
|
234
|
-
const scope =
|
|
402
|
+
const scope = { ...permissionScope };
|
|
235
403
|
if (PermissionsProtocol.hasProtocolScope(scope)) {
|
|
236
404
|
scope.protocol = normalizeProtocolUrl(scope.protocol);
|
|
237
405
|
}
|
|
@@ -283,75 +451,5 @@ export class PermissionsProtocol {
|
|
|
283
451
|
}
|
|
284
452
|
}
|
|
285
453
|
}
|
|
286
|
-
/**
|
|
287
|
-
* The URI of the DWN Permissions protocol.
|
|
288
|
-
*/
|
|
289
|
-
PermissionsProtocol.uri = 'https://tbd.website/dwn/permissions';
|
|
290
|
-
/**
|
|
291
|
-
* The protocol path of the `request` record.
|
|
292
|
-
*/
|
|
293
|
-
PermissionsProtocol.requestPath = 'request';
|
|
294
|
-
/**
|
|
295
|
-
* The protocol path of the `grant` record.
|
|
296
|
-
*/
|
|
297
|
-
PermissionsProtocol.grantPath = 'grant';
|
|
298
|
-
/**
|
|
299
|
-
* The protocol path of the `revocation` record.
|
|
300
|
-
*/
|
|
301
|
-
PermissionsProtocol.revocationPath = 'grant/revocation';
|
|
302
|
-
/**
|
|
303
|
-
* The definition of the Permissions protocol.
|
|
304
|
-
*/
|
|
305
|
-
PermissionsProtocol.definition = {
|
|
306
|
-
published: true,
|
|
307
|
-
protocol: PermissionsProtocol.uri,
|
|
308
|
-
types: {
|
|
309
|
-
request: {
|
|
310
|
-
dataFormats: ['application/json']
|
|
311
|
-
},
|
|
312
|
-
grant: {
|
|
313
|
-
dataFormats: ['application/json']
|
|
314
|
-
},
|
|
315
|
-
revocation: {
|
|
316
|
-
dataFormats: ['application/json']
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
structure: {
|
|
320
|
-
request: {
|
|
321
|
-
$size: {
|
|
322
|
-
max: 10000
|
|
323
|
-
},
|
|
324
|
-
$actions: [
|
|
325
|
-
{
|
|
326
|
-
who: 'anyone',
|
|
327
|
-
can: ['create']
|
|
328
|
-
}
|
|
329
|
-
]
|
|
330
|
-
},
|
|
331
|
-
grant: {
|
|
332
|
-
$size: {
|
|
333
|
-
max: 10000
|
|
334
|
-
},
|
|
335
|
-
$actions: [
|
|
336
|
-
{
|
|
337
|
-
who: 'recipient',
|
|
338
|
-
of: 'grant',
|
|
339
|
-
can: ['read']
|
|
340
|
-
}
|
|
341
|
-
],
|
|
342
|
-
revocation: {
|
|
343
|
-
$size: {
|
|
344
|
-
max: 10000
|
|
345
|
-
},
|
|
346
|
-
$actions: [
|
|
347
|
-
{
|
|
348
|
-
who: 'anyone',
|
|
349
|
-
can: ['read']
|
|
350
|
-
}
|
|
351
|
-
]
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
454
|
;
|
|
357
455
|
//# sourceMappingURL=permissions.js.map
|