@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,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
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
|
-
};
|
|
10
1
|
import sinon from 'sinon';
|
|
11
2
|
import { beforeEach, describe, expect, it } from 'bun:test';
|
|
12
3
|
import { DwnErrorCode } from '../../src/core/dwn-error.js';
|
|
@@ -20,74 +11,91 @@ describe('RecordsWrite', () => {
|
|
|
20
11
|
sinon.restore();
|
|
21
12
|
});
|
|
22
13
|
describe('create()', () => {
|
|
23
|
-
it('should be able to create and authorize a valid RecordsWrite message', () =>
|
|
14
|
+
it('should be able to create and authorize a valid RecordsWrite message', async () => {
|
|
24
15
|
// testing `create()` first
|
|
25
|
-
const alice =
|
|
16
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
26
17
|
const options = {
|
|
27
18
|
data: TestDataGenerator.randomBytes(10),
|
|
28
19
|
dataFormat: 'application/json',
|
|
29
20
|
dateCreated: '2022-10-14T10:20:30.405060Z',
|
|
30
|
-
recordId:
|
|
21
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
22
|
+
protocol: 'http://test-protocol.xyz',
|
|
23
|
+
protocolPath: 'testRecord',
|
|
31
24
|
signer: Jws.createSigner(alice)
|
|
32
25
|
};
|
|
33
|
-
const recordsWrite =
|
|
26
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
34
27
|
const message = recordsWrite.message;
|
|
35
28
|
expect(message.authorization).toBeDefined();
|
|
36
29
|
expect(message.descriptor.dataFormat).toBe(options.dataFormat);
|
|
37
30
|
expect(message.descriptor.dateCreated).toBe(options.dateCreated);
|
|
38
31
|
expect(message.recordId).toBe(options.recordId);
|
|
39
32
|
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
// authorizeRecordsWrite is a private instance method; invoke via bracket notation on an instance
|
|
34
|
+
const handler = new RecordsWriteHandler({
|
|
35
|
+
didResolver: {},
|
|
36
|
+
messageStore: messageStoreStub,
|
|
37
|
+
dataStore: {},
|
|
38
|
+
stateIndex: {},
|
|
39
|
+
});
|
|
40
|
+
await handler.authorizeRecordsWrite(alice.did, recordsWrite, messageStoreStub);
|
|
41
|
+
});
|
|
42
|
+
it('should include permissionGrantId in the descriptor when provided', async () => {
|
|
43
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
44
|
+
const grantId = await TestDataGenerator.randomCborSha256Cid();
|
|
45
|
+
const recordsWrite = await RecordsWrite.create({
|
|
46
46
|
data: TestDataGenerator.randomBytes(10),
|
|
47
47
|
dataFormat: 'application/json',
|
|
48
|
-
recordId:
|
|
48
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
49
|
+
protocol: 'http://test-protocol.xyz',
|
|
50
|
+
protocolPath: 'testRecord',
|
|
49
51
|
signer: Jws.createSigner(alice),
|
|
50
52
|
permissionGrantId: grantId,
|
|
51
53
|
});
|
|
52
54
|
expect(recordsWrite.message.descriptor.permissionGrantId).toBe(grantId);
|
|
53
|
-
})
|
|
54
|
-
it('should not include permissionGrantId in the descriptor when not provided', () =>
|
|
55
|
-
const alice =
|
|
56
|
-
const recordsWrite =
|
|
55
|
+
});
|
|
56
|
+
it('should not include permissionGrantId in the descriptor when not provided', async () => {
|
|
57
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
58
|
+
const recordsWrite = await RecordsWrite.create({
|
|
57
59
|
data: TestDataGenerator.randomBytes(10),
|
|
58
60
|
dataFormat: 'application/json',
|
|
59
|
-
recordId:
|
|
61
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
62
|
+
protocol: 'http://test-protocol.xyz',
|
|
63
|
+
protocolPath: 'testRecord',
|
|
60
64
|
signer: Jws.createSigner(alice),
|
|
61
65
|
});
|
|
62
66
|
expect(recordsWrite.message.descriptor.permissionGrantId).toBeUndefined();
|
|
63
|
-
})
|
|
64
|
-
it('should be able to auto-fill `datePublished` when `published` set to `true` but `datePublished` not given', () =>
|
|
65
|
-
const alice =
|
|
67
|
+
});
|
|
68
|
+
it('should be able to auto-fill `datePublished` when `published` set to `true` but `datePublished` not given', async () => {
|
|
69
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
66
70
|
const options = {
|
|
67
71
|
data: TestDataGenerator.randomBytes(10),
|
|
68
72
|
dataFormat: 'application/json',
|
|
69
|
-
recordId:
|
|
73
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
74
|
+
protocol: 'http://test-protocol.xyz',
|
|
75
|
+
protocolPath: 'testRecord',
|
|
70
76
|
published: true,
|
|
71
77
|
signer: Jws.createSigner(alice)
|
|
72
78
|
};
|
|
73
|
-
const recordsWrite =
|
|
79
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
74
80
|
const message = recordsWrite.message;
|
|
75
81
|
expect(message.descriptor.datePublished).toBeDefined();
|
|
76
|
-
})
|
|
77
|
-
it('should not allow `data` and `dataCid` to be both defined or undefined', () =>
|
|
78
|
-
const alice =
|
|
82
|
+
});
|
|
83
|
+
it('should not allow `data` and `dataCid` to be both defined or undefined', async () => {
|
|
84
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
79
85
|
// testing `data` and `dataCid` both defined
|
|
80
86
|
const options1 = {
|
|
81
87
|
recipient: alice.did,
|
|
82
88
|
data: TestDataGenerator.randomBytes(10),
|
|
83
|
-
dataCid:
|
|
89
|
+
dataCid: await TestDataGenerator.randomCborSha256Cid(),
|
|
84
90
|
dataFormat: 'application/json',
|
|
85
|
-
recordId:
|
|
91
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
92
|
+
protocol: 'http://test-protocol.xyz',
|
|
93
|
+
protocolPath: 'testRecord',
|
|
86
94
|
published: true,
|
|
87
95
|
signer: Jws.createSigner(alice)
|
|
88
96
|
};
|
|
89
97
|
const createPromise1 = RecordsWrite.create(options1);
|
|
90
|
-
|
|
98
|
+
await expect(createPromise1).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
|
|
91
99
|
// testing `data` and `dataCid` both undefined
|
|
92
100
|
const options2 = {
|
|
93
101
|
recipient: alice.did,
|
|
@@ -95,41 +103,47 @@ describe('RecordsWrite', () => {
|
|
|
95
103
|
// data : TestDataGenerator.randomBytes(10),
|
|
96
104
|
// dataCid : await TestDataGenerator.randomCborSha256Cid(),
|
|
97
105
|
dataFormat: 'application/json',
|
|
98
|
-
recordId:
|
|
106
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
107
|
+
protocol: 'http://test-protocol.xyz',
|
|
108
|
+
protocolPath: 'testRecord',
|
|
99
109
|
published: true,
|
|
100
110
|
signer: Jws.createSigner(alice)
|
|
101
111
|
};
|
|
102
112
|
const createPromise2 = RecordsWrite.create(options2);
|
|
103
|
-
|
|
104
|
-
})
|
|
105
|
-
it('should required `dataCid` and `dataSize` to be both defined or undefined at the same time', () =>
|
|
106
|
-
const alice =
|
|
113
|
+
await expect(createPromise2).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
|
|
114
|
+
});
|
|
115
|
+
it('should required `dataCid` and `dataSize` to be both defined or undefined at the same time', async () => {
|
|
116
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
107
117
|
const options1 = {
|
|
108
118
|
recipient: alice.did,
|
|
109
|
-
dataCid:
|
|
119
|
+
dataCid: await TestDataGenerator.randomCborSha256Cid(),
|
|
110
120
|
// dataSize : 123, // intentionally missing
|
|
111
121
|
dataFormat: 'application/json',
|
|
112
|
-
recordId:
|
|
122
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
123
|
+
protocol: 'http://test-protocol.xyz',
|
|
124
|
+
protocolPath: 'testRecord',
|
|
113
125
|
published: true,
|
|
114
126
|
signer: Jws.createSigner(alice)
|
|
115
127
|
};
|
|
116
128
|
const createPromise1 = RecordsWrite.create(options1);
|
|
117
|
-
|
|
129
|
+
await expect(createPromise1).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
|
|
118
130
|
const options2 = {
|
|
119
131
|
recipient: alice.did,
|
|
120
132
|
data: TestDataGenerator.randomBytes(10),
|
|
121
133
|
// dataCid : await TestDataGenerator.randomCborSha256Cid(), // intentionally missing
|
|
122
134
|
dataSize: 123,
|
|
123
135
|
dataFormat: 'application/json',
|
|
124
|
-
recordId:
|
|
136
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
137
|
+
protocol: 'http://test-protocol.xyz',
|
|
138
|
+
protocolPath: 'testRecord',
|
|
125
139
|
published: true,
|
|
126
140
|
signer: Jws.createSigner(alice)
|
|
127
141
|
};
|
|
128
142
|
const createPromise2 = RecordsWrite.create(options2);
|
|
129
|
-
|
|
130
|
-
})
|
|
131
|
-
it('should auto-normalize protocol URL', () =>
|
|
132
|
-
const alice =
|
|
143
|
+
await expect(createPromise2).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
|
|
144
|
+
});
|
|
145
|
+
it('should auto-normalize protocol URL', async () => {
|
|
146
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
133
147
|
const options = {
|
|
134
148
|
recipient: alice.did,
|
|
135
149
|
data: TestDataGenerator.randomBytes(10),
|
|
@@ -139,50 +153,41 @@ describe('RecordsWrite', () => {
|
|
|
139
153
|
protocolPath: 'example',
|
|
140
154
|
schema: 'http://foo.bar/schema'
|
|
141
155
|
};
|
|
142
|
-
const recordsWrite =
|
|
156
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
143
157
|
const message = recordsWrite.message;
|
|
144
158
|
expect(message.descriptor.protocol).toBe('http://example.com');
|
|
145
|
-
})
|
|
146
|
-
it('should
|
|
147
|
-
const alice =
|
|
148
|
-
const
|
|
159
|
+
});
|
|
160
|
+
it('should require `protocol` and `protocolPath`', async () => {
|
|
161
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
162
|
+
const baseOptions = {
|
|
149
163
|
recipient: alice.did,
|
|
150
|
-
|
|
151
|
-
// protocolPath : 'foo/bar', // intentionally missing
|
|
152
|
-
dataCid: yield TestDataGenerator.randomCborSha256Cid(),
|
|
164
|
+
dataCid: await TestDataGenerator.randomCborSha256Cid(),
|
|
153
165
|
dataSize: 123,
|
|
154
166
|
dataFormat: 'application/json',
|
|
155
|
-
recordId:
|
|
167
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
156
168
|
signer: Jws.createSigner(alice)
|
|
157
169
|
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
recipient: alice.did,
|
|
162
|
-
// protocol : 'http://example.com', // intentionally missing
|
|
170
|
+
// missing protocol
|
|
171
|
+
const missingProtocol = RecordsWrite.create({
|
|
172
|
+
...baseOptions,
|
|
163
173
|
protocolPath: 'foo/bar',
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
it('should be able to create a RecordsWrite successfully using a custom signer', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
});
|
|
175
|
+
await expect(missingProtocol).rejects.toThrow('`protocol` and `protocolPath` are required');
|
|
176
|
+
// missing protocolPath
|
|
177
|
+
const missingProtocolPath = RecordsWrite.create({
|
|
178
|
+
...baseOptions,
|
|
179
|
+
protocol: 'http://example.com',
|
|
180
|
+
});
|
|
181
|
+
await expect(missingProtocolPath).rejects.toThrow('`protocol` and `protocolPath` are required');
|
|
182
|
+
});
|
|
183
|
+
it('should be able to create a RecordsWrite successfully using a custom signer', async () => {
|
|
175
184
|
// create a custom signer
|
|
176
185
|
const hardCodedSignature = Encoder.stringToBytes('some_hard_coded_signature');
|
|
177
186
|
class CustomSigner {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
sign(_content) {
|
|
183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
return hardCodedSignature;
|
|
185
|
-
});
|
|
187
|
+
keyId = 'did:example:alice#key1';
|
|
188
|
+
algorithm = 'unused';
|
|
189
|
+
async sign(_content) {
|
|
190
|
+
return hardCodedSignature;
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
const signer = new CustomSigner();
|
|
@@ -190,70 +195,24 @@ describe('RecordsWrite', () => {
|
|
|
190
195
|
schema: 'http://any-schema.com',
|
|
191
196
|
protocol: 'http://example.com',
|
|
192
197
|
protocolPath: 'foo/bar',
|
|
193
|
-
dataCid:
|
|
198
|
+
dataCid: await TestDataGenerator.randomCborSha256Cid(),
|
|
194
199
|
dataSize: 123,
|
|
195
200
|
dataFormat: 'application/json',
|
|
196
|
-
recordId:
|
|
201
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
197
202
|
signer
|
|
198
203
|
};
|
|
199
|
-
const recordsWrite =
|
|
204
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
200
205
|
expect(recordsWrite.message.authorization.signature.signatures[0].signature).toBe(Encoder.bytesToBase64Url(hardCodedSignature));
|
|
201
|
-
})
|
|
202
|
-
it('should throw if
|
|
203
|
-
const alice =
|
|
204
|
-
const
|
|
205
|
-
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
206
|
-
const encryptionInput = {
|
|
207
|
-
initializationVector: dataEncryptionInitializationVector,
|
|
208
|
-
key: dataEncryptionKey,
|
|
209
|
-
authenticationTag: TestDataGenerator.randomBytes(16),
|
|
210
|
-
keyEncryptionInputs: [{
|
|
211
|
-
publicKeyId: alice.keyId, // reusing signing key for encryption purely as a convenience
|
|
212
|
-
publicKey: alice.encryptionKeyPair.publicJwk,
|
|
213
|
-
derivationScheme: KeyDerivationScheme.ProtocolPath
|
|
214
|
-
}]
|
|
215
|
-
};
|
|
216
|
-
// intentionally generating a record that is not protocol-based
|
|
217
|
-
const createPromise = RecordsWrite.create({
|
|
218
|
-
signer: Jws.createSigner(alice),
|
|
219
|
-
dataFormat: 'application/json',
|
|
220
|
-
data: TestDataGenerator.randomBytes(10),
|
|
221
|
-
encryptionInput
|
|
222
|
-
});
|
|
223
|
-
yield expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteMissingProtocol);
|
|
224
|
-
}));
|
|
225
|
-
it('should throw if attempting to use `schemas` key derivation encryption scheme on a record without `schema`', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
226
|
-
const alice = yield TestDataGenerator.generatePersona();
|
|
227
|
-
const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12);
|
|
228
|
-
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
229
|
-
const encryptionInput = {
|
|
230
|
-
initializationVector: dataEncryptionInitializationVector,
|
|
231
|
-
key: dataEncryptionKey,
|
|
232
|
-
authenticationTag: TestDataGenerator.randomBytes(16),
|
|
233
|
-
keyEncryptionInputs: [{
|
|
234
|
-
publicKeyId: alice.keyId, // reusing signing key for encryption purely as a convenience
|
|
235
|
-
publicKey: alice.encryptionKeyPair.publicJwk,
|
|
236
|
-
derivationScheme: KeyDerivationScheme.Schemas
|
|
237
|
-
}]
|
|
238
|
-
};
|
|
239
|
-
// intentionally generating a record that is without `schema`
|
|
240
|
-
const createPromise = RecordsWrite.create({
|
|
241
|
-
signer: Jws.createSigner(alice),
|
|
242
|
-
dataFormat: 'application/octet-stream',
|
|
243
|
-
data: TestDataGenerator.randomBytes(10),
|
|
244
|
-
encryptionInput
|
|
245
|
-
});
|
|
246
|
-
yield expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteMissingSchema);
|
|
247
|
-
}));
|
|
248
|
-
it('should throw if delegated grant is given but signer is not given', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
|
-
const alice = yield TestDataGenerator.generatePersona();
|
|
250
|
-
const bob = yield TestDataGenerator.generatePersona();
|
|
206
|
+
});
|
|
207
|
+
it('should throw if delegated grant is given but signer is not given', async () => {
|
|
208
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
209
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
251
210
|
const scope = {
|
|
252
211
|
interface: DwnInterfaceName.Records,
|
|
253
212
|
method: DwnMethodName.Write,
|
|
254
213
|
protocol: 'chat'
|
|
255
214
|
};
|
|
256
|
-
const grantToBob =
|
|
215
|
+
const grantToBob = await PermissionsProtocol.createGrant({
|
|
257
216
|
signer: Jws.createSigner(alice),
|
|
258
217
|
delegated: true, // this is a delegated grant
|
|
259
218
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
@@ -263,27 +222,29 @@ describe('RecordsWrite', () => {
|
|
|
263
222
|
});
|
|
264
223
|
const createPromise = RecordsWrite.create({
|
|
265
224
|
delegatedGrant: grantToBob.dataEncodedMessage,
|
|
225
|
+
protocol: 'http://test-protocol.xyz',
|
|
226
|
+
protocolPath: 'testRecord',
|
|
266
227
|
dataFormat: 'application/octet-stream',
|
|
267
228
|
data: TestDataGenerator.randomBytes(10),
|
|
268
229
|
});
|
|
269
|
-
|
|
270
|
-
})
|
|
230
|
+
await expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteCreateMissingSigner);
|
|
231
|
+
});
|
|
271
232
|
});
|
|
272
233
|
describe('createFrom()', () => {
|
|
273
|
-
it('should create a RecordsWrite with `published` set to `true` with just `publishedDate` given', () =>
|
|
274
|
-
const { author, recordsWrite } =
|
|
234
|
+
it('should create a RecordsWrite with `published` set to `true` with just `publishedDate` given', async () => {
|
|
235
|
+
const { author, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
|
|
275
236
|
published: false
|
|
276
237
|
});
|
|
277
|
-
const write =
|
|
238
|
+
const write = await RecordsWrite.createFrom({
|
|
278
239
|
recordsWriteMessage: recordsWrite.message,
|
|
279
240
|
datePublished: Time.getCurrentTimestamp(),
|
|
280
241
|
signer: Jws.createSigner(author)
|
|
281
242
|
});
|
|
282
243
|
expect(write.message.descriptor.published).toBe(true);
|
|
283
|
-
})
|
|
284
|
-
it('replace tags with updated tags, if tags do not exist in createFrom remove them', () =>
|
|
244
|
+
});
|
|
245
|
+
it('replace tags with updated tags, if tags do not exist in createFrom remove them', async () => {
|
|
285
246
|
// create a record with tags
|
|
286
|
-
const { author, message, recordsWrite } =
|
|
247
|
+
const { author, message, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
|
|
287
248
|
tags: {
|
|
288
249
|
tag1: ['value1', 'value2']
|
|
289
250
|
}
|
|
@@ -292,7 +253,7 @@ describe('RecordsWrite', () => {
|
|
|
292
253
|
expect(message.descriptor.tags.tag1).toBeDefined();
|
|
293
254
|
expect(message.descriptor.tags.tag1).toEqual(expect.arrayContaining(['value1', 'value2']));
|
|
294
255
|
// update the record's tags
|
|
295
|
-
const write =
|
|
256
|
+
const write = await RecordsWrite.createFrom({
|
|
296
257
|
recordsWriteMessage: recordsWrite.message,
|
|
297
258
|
signer: Jws.createSigner(author),
|
|
298
259
|
tags: {
|
|
@@ -304,30 +265,32 @@ describe('RecordsWrite', () => {
|
|
|
304
265
|
expect(write.message.descriptor.tags.tag2).toBeDefined();
|
|
305
266
|
expect(write.message.descriptor.tags.tag2).toEqual(expect.arrayContaining(['value1', 'value2', 'value3']));
|
|
306
267
|
// update without tags
|
|
307
|
-
const write2 =
|
|
268
|
+
const write2 = await RecordsWrite.createFrom({
|
|
308
269
|
recordsWriteMessage: write.message,
|
|
309
270
|
signer: Jws.createSigner(author),
|
|
310
271
|
});
|
|
311
272
|
expect(write2.message.descriptor.tags).toBeUndefined();
|
|
312
|
-
})
|
|
273
|
+
});
|
|
313
274
|
});
|
|
314
275
|
describe('parse()', () => {
|
|
315
|
-
it('should invoke JSON schema validation when parsing a RecordsWrite', () =>
|
|
316
|
-
const alice =
|
|
317
|
-
const recordsWrite =
|
|
276
|
+
it('should invoke JSON schema validation when parsing a RecordsWrite', async () => {
|
|
277
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
278
|
+
const recordsWrite = await RecordsWrite.create({
|
|
318
279
|
signer: Jws.createSigner(alice),
|
|
280
|
+
protocol: 'http://test-protocol.xyz',
|
|
281
|
+
protocolPath: 'testRecord',
|
|
319
282
|
dataFormat: 'application/octet-stream',
|
|
320
283
|
data: TestDataGenerator.randomBytes(10),
|
|
321
284
|
});
|
|
322
285
|
const validateJsonSchemaSpy = sinon.spy(Message, 'validateJsonSchema');
|
|
323
|
-
|
|
286
|
+
await RecordsWrite.parse(recordsWrite.message);
|
|
324
287
|
expect(validateJsonSchemaSpy.called).toBe(true);
|
|
325
|
-
})
|
|
288
|
+
});
|
|
326
289
|
});
|
|
327
290
|
describe('isSignedByAuthorDelegate()', () => {
|
|
328
|
-
it('should return false if the given RecordsWrite is not signed at all', () =>
|
|
291
|
+
it('should return false if the given RecordsWrite is not signed at all', async () => {
|
|
329
292
|
const data = new TextEncoder().encode('any data');
|
|
330
|
-
const recordsWrite =
|
|
293
|
+
const recordsWrite = await RecordsWrite.create({
|
|
331
294
|
protocol: 'unused',
|
|
332
295
|
protocolPath: 'unused',
|
|
333
296
|
schema: 'unused',
|
|
@@ -336,12 +299,12 @@ describe('RecordsWrite', () => {
|
|
|
336
299
|
});
|
|
337
300
|
const isSignedByAuthorDelegate = recordsWrite.isSignedByAuthorDelegate;
|
|
338
301
|
expect(isSignedByAuthorDelegate).toBe(false);
|
|
339
|
-
})
|
|
302
|
+
});
|
|
340
303
|
});
|
|
341
304
|
describe('isSignedByOwnerDelegate()', () => {
|
|
342
|
-
it('should return false if the given RecordsWrite is not signed at all', () =>
|
|
305
|
+
it('should return false if the given RecordsWrite is not signed at all', async () => {
|
|
343
306
|
const data = new TextEncoder().encode('any data');
|
|
344
|
-
const recordsWrite =
|
|
307
|
+
const recordsWrite = await RecordsWrite.create({
|
|
345
308
|
protocol: 'unused',
|
|
346
309
|
protocolPath: 'unused',
|
|
347
310
|
schema: 'unused',
|
|
@@ -350,103 +313,111 @@ describe('RecordsWrite', () => {
|
|
|
350
313
|
});
|
|
351
314
|
const isSignedByOwnerDelegate = recordsWrite.isSignedByOwnerDelegate;
|
|
352
315
|
expect(isSignedByOwnerDelegate).toBe(false);
|
|
353
|
-
})
|
|
316
|
+
});
|
|
354
317
|
});
|
|
355
318
|
describe('isInitialWrite()', () => {
|
|
356
|
-
it('should return false if given message is not a RecordsWrite', () =>
|
|
357
|
-
const { message } =
|
|
358
|
-
const isInitialWrite =
|
|
319
|
+
it('should return false if given message is not a RecordsWrite', async () => {
|
|
320
|
+
const { message } = await TestDataGenerator.generateRecordsQuery();
|
|
321
|
+
const isInitialWrite = await RecordsWrite.isInitialWrite(message);
|
|
359
322
|
expect(isInitialWrite).toBe(false);
|
|
360
|
-
})
|
|
323
|
+
});
|
|
361
324
|
});
|
|
362
325
|
describe('getEntryId()', () => {
|
|
363
|
-
it('should throw if the given author is undefined', () =>
|
|
364
|
-
const { message } =
|
|
326
|
+
it('should throw if the given author is undefined', async () => {
|
|
327
|
+
const { message } = await TestDataGenerator.generateRecordsWrite();
|
|
365
328
|
const author = undefined;
|
|
366
|
-
|
|
367
|
-
})
|
|
329
|
+
await expect(RecordsWrite.getEntryId(author, message.descriptor)).rejects.toThrow(DwnErrorCode.RecordsWriteGetEntryIdUndefinedAuthor);
|
|
330
|
+
});
|
|
368
331
|
});
|
|
369
332
|
describe('signAsOwner()', () => {
|
|
370
|
-
it('should throw if the RecordsWrite is not signed by an author yet', () =>
|
|
333
|
+
it('should throw if the RecordsWrite is not signed by an author yet', async () => {
|
|
371
334
|
const options = {
|
|
372
335
|
data: TestDataGenerator.randomBytes(10),
|
|
373
336
|
dataFormat: 'application/json',
|
|
374
337
|
dateCreated: '2023-07-27T10:20:30.405060Z',
|
|
375
|
-
recordId:
|
|
338
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
339
|
+
protocol: 'http://test-protocol.xyz',
|
|
340
|
+
protocolPath: 'testRecord',
|
|
376
341
|
};
|
|
377
|
-
const recordsWrite =
|
|
342
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
378
343
|
expect(recordsWrite.author).toBeUndefined();
|
|
379
344
|
expect(recordsWrite.signaturePayload).toBeUndefined();
|
|
380
|
-
const alice =
|
|
381
|
-
|
|
345
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
346
|
+
await expect(recordsWrite.signAsOwner(Jws.createSigner(alice))).rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerUnknownAuthor);
|
|
382
347
|
expect(recordsWrite.owner).toBeUndefined();
|
|
383
348
|
expect(recordsWrite.ownerSignaturePayload).toBeUndefined();
|
|
384
|
-
})
|
|
349
|
+
});
|
|
385
350
|
});
|
|
386
351
|
describe('signAsOwnerDelegate()', () => {
|
|
387
|
-
it('should throw if the RecordsWrite is not signed by an author yet', () =>
|
|
352
|
+
it('should throw if the RecordsWrite is not signed by an author yet', async () => {
|
|
388
353
|
const options = {
|
|
389
354
|
data: TestDataGenerator.randomBytes(10),
|
|
390
355
|
dataFormat: 'application/json',
|
|
391
356
|
dateCreated: '2023-07-27T10:20:30.405060Z',
|
|
392
|
-
recordId:
|
|
357
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
358
|
+
protocol: 'http://test-protocol.xyz',
|
|
359
|
+
protocolPath: 'testRecord',
|
|
393
360
|
};
|
|
394
|
-
const recordsWrite =
|
|
361
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
395
362
|
expect(recordsWrite.author).toBeUndefined();
|
|
396
363
|
expect(recordsWrite.signaturePayload).toBeUndefined();
|
|
397
364
|
// create a delegated grant
|
|
398
|
-
const alice =
|
|
399
|
-
const bob =
|
|
365
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
366
|
+
const bob = await TestDataGenerator.generateDidKeyPersona();
|
|
400
367
|
const scope = {
|
|
401
368
|
interface: DwnInterfaceName.Records,
|
|
402
369
|
method: DwnMethodName.Write,
|
|
403
370
|
protocol: 'chat'
|
|
404
371
|
};
|
|
405
|
-
const ownerDelegatedGrant =
|
|
372
|
+
const ownerDelegatedGrant = await PermissionsProtocol.createGrant({
|
|
406
373
|
signer: Jws.createSigner(alice),
|
|
407
374
|
delegated: true, // this is a delegated grant
|
|
408
375
|
dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
|
|
409
376
|
grantedTo: bob.did,
|
|
410
377
|
scope
|
|
411
378
|
});
|
|
412
|
-
|
|
379
|
+
await expect(recordsWrite.signAsOwnerDelegate(Jws.createSigner(bob), ownerDelegatedGrant.dataEncodedMessage))
|
|
413
380
|
.rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerDelegateUnknownAuthor);
|
|
414
381
|
expect(recordsWrite.owner).toBeUndefined();
|
|
415
382
|
expect(recordsWrite.ownerSignaturePayload).toBeUndefined();
|
|
416
|
-
})
|
|
383
|
+
});
|
|
417
384
|
});
|
|
418
385
|
describe('ownerSignatureSigner()', () => {
|
|
419
|
-
it('should return `undefined` if owner signature is not present in the message', () =>
|
|
386
|
+
it('should return `undefined` if owner signature is not present in the message', async () => {
|
|
420
387
|
const options = {
|
|
421
388
|
data: TestDataGenerator.randomBytes(10),
|
|
422
389
|
dataFormat: 'application/json',
|
|
423
390
|
dateCreated: '2023-07-27T10:20:30.405060Z',
|
|
424
|
-
recordId:
|
|
391
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
392
|
+
protocol: 'http://test-protocol.xyz',
|
|
393
|
+
protocolPath: 'testRecord',
|
|
425
394
|
};
|
|
426
|
-
const recordsWrite =
|
|
395
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
427
396
|
expect(recordsWrite.ownerSignatureSigner).toBeUndefined();
|
|
428
|
-
})
|
|
397
|
+
});
|
|
429
398
|
});
|
|
430
399
|
describe('message', () => {
|
|
431
|
-
it('should throw if attempting to access the message of a RecordsWrite that is not given authorization signature input', () =>
|
|
400
|
+
it('should throw if attempting to access the message of a RecordsWrite that is not given authorization signature input', async () => {
|
|
432
401
|
const options = {
|
|
433
402
|
data: TestDataGenerator.randomBytes(10),
|
|
434
403
|
dataFormat: 'application/json',
|
|
435
404
|
dateCreated: '2023-07-27T10:20:30.405060Z',
|
|
436
|
-
recordId:
|
|
405
|
+
recordId: await TestDataGenerator.randomCborSha256Cid(),
|
|
406
|
+
protocol: 'http://test-protocol.xyz',
|
|
407
|
+
protocolPath: 'testRecord',
|
|
437
408
|
};
|
|
438
|
-
const recordsWrite =
|
|
409
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
439
410
|
expect(recordsWrite.author).toBeUndefined();
|
|
440
411
|
expect(recordsWrite.signaturePayload).toBeUndefined();
|
|
441
412
|
expect(() => recordsWrite.message).toThrow(DwnErrorCode.RecordsWriteMissingSigner);
|
|
442
|
-
})
|
|
413
|
+
});
|
|
443
414
|
});
|
|
444
415
|
describe('encryptSymmetricEncryptionKey()', () => {
|
|
445
|
-
it('should replace encryption property by default', () =>
|
|
446
|
-
const alice =
|
|
416
|
+
it('should replace encryption property by default', async () => {
|
|
417
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
447
418
|
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
448
419
|
const dataEncryptionIV = TestDataGenerator.randomBytes(12);
|
|
449
|
-
const recordsWrite =
|
|
420
|
+
const recordsWrite = await RecordsWrite.create({
|
|
450
421
|
signer: Jws.createSigner(alice),
|
|
451
422
|
protocol: 'https://example.com/protocol',
|
|
452
423
|
protocolPath: 'test',
|
|
@@ -465,7 +436,7 @@ describe('RecordsWrite', () => {
|
|
|
465
436
|
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
466
437
|
}],
|
|
467
438
|
};
|
|
468
|
-
|
|
439
|
+
await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
|
|
469
440
|
expect(recordsWrite['_message'].encryption).toBeDefined();
|
|
470
441
|
expect(recordsWrite['_message'].encryption.recipients).toHaveLength(1);
|
|
471
442
|
expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('protocolPath');
|
|
@@ -477,19 +448,19 @@ describe('RecordsWrite', () => {
|
|
|
477
448
|
keyEncryptionInputs: [{
|
|
478
449
|
publicKeyId: alice.keyId,
|
|
479
450
|
publicKey: alice.encryptionKeyPair.publicJwk,
|
|
480
|
-
derivationScheme: KeyDerivationScheme.
|
|
451
|
+
derivationScheme: KeyDerivationScheme.ProtocolContext,
|
|
481
452
|
}],
|
|
482
453
|
};
|
|
483
|
-
|
|
484
|
-
// Should have replaced — only 1 entry with
|
|
454
|
+
await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2);
|
|
455
|
+
// Should have replaced — only 1 entry with ProtocolContext scheme
|
|
485
456
|
expect(recordsWrite['_message'].encryption.recipients).toHaveLength(1);
|
|
486
|
-
expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('
|
|
487
|
-
})
|
|
488
|
-
it('should append recipients when append option is true', () =>
|
|
489
|
-
const alice =
|
|
457
|
+
expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('protocolContext');
|
|
458
|
+
});
|
|
459
|
+
it('should append recipients when append option is true', async () => {
|
|
460
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
490
461
|
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
491
462
|
const dataEncryptionIV = TestDataGenerator.randomBytes(12);
|
|
492
|
-
const recordsWrite =
|
|
463
|
+
const recordsWrite = await RecordsWrite.create({
|
|
493
464
|
signer: Jws.createSigner(alice),
|
|
494
465
|
protocol: 'https://example.com/protocol',
|
|
495
466
|
protocolPath: 'test',
|
|
@@ -508,7 +479,7 @@ describe('RecordsWrite', () => {
|
|
|
508
479
|
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
509
480
|
}],
|
|
510
481
|
};
|
|
511
|
-
|
|
482
|
+
await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
|
|
512
483
|
const originalIV = recordsWrite['_message'].encryption.iv;
|
|
513
484
|
const originalProtected = recordsWrite['_message'].encryption.protected;
|
|
514
485
|
// Second encryption with append — ProtocolContext
|
|
@@ -522,7 +493,7 @@ describe('RecordsWrite', () => {
|
|
|
522
493
|
derivationScheme: KeyDerivationScheme.ProtocolContext,
|
|
523
494
|
}],
|
|
524
495
|
};
|
|
525
|
-
|
|
496
|
+
await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
|
|
526
497
|
// Should have both entries
|
|
527
498
|
const encryption = recordsWrite['_message'].encryption;
|
|
528
499
|
expect(encryption.recipients).toHaveLength(2);
|
|
@@ -538,16 +509,16 @@ describe('RecordsWrite', () => {
|
|
|
538
509
|
// When starting from a parsed/signed message (the signAsOwner test
|
|
539
510
|
// below), authorization IS preserved by append mode.
|
|
540
511
|
expect(recordsWrite['_message'].authorization).toBeUndefined();
|
|
541
|
-
})
|
|
542
|
-
it('should allow signAsOwner after append (reactive root-record upgrade)', () =>
|
|
512
|
+
});
|
|
513
|
+
it('should allow signAsOwner after append (reactive root-record upgrade)', async () => {
|
|
543
514
|
// Simulates the cross-DWN scenario: Bob authors a record, Alice (owner)
|
|
544
515
|
// appends a ProtocolContext recipient entry, then signs as owner.
|
|
545
|
-
const alice =
|
|
546
|
-
const bob =
|
|
516
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
517
|
+
const bob = await TestDataGenerator.generatePersona();
|
|
547
518
|
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
548
519
|
const dataEncryptionIV = TestDataGenerator.randomBytes(12);
|
|
549
520
|
// Bob creates and signs the record
|
|
550
|
-
const recordsWrite =
|
|
521
|
+
const recordsWrite = await RecordsWrite.create({
|
|
551
522
|
signer: Jws.createSigner(bob),
|
|
552
523
|
protocol: 'https://example.com/protocol',
|
|
553
524
|
protocolPath: 'thread',
|
|
@@ -566,12 +537,12 @@ describe('RecordsWrite', () => {
|
|
|
566
537
|
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
567
538
|
}],
|
|
568
539
|
};
|
|
569
|
-
|
|
570
|
-
|
|
540
|
+
await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
|
|
541
|
+
await recordsWrite.sign({ signer: Jws.createSigner(bob) });
|
|
571
542
|
expect(recordsWrite.author).toBe(bob.did);
|
|
572
543
|
expect(recordsWrite['_message'].authorization).toBeDefined();
|
|
573
544
|
// Simulate: Alice parses Bob's message and appends ProtocolContext
|
|
574
|
-
const parsed =
|
|
545
|
+
const parsed = await RecordsWrite.parse(recordsWrite.message);
|
|
575
546
|
expect(parsed.author).toBe(bob.did);
|
|
576
547
|
const encryptionInput2 = {
|
|
577
548
|
initializationVector: dataEncryptionIV,
|
|
@@ -583,12 +554,12 @@ describe('RecordsWrite', () => {
|
|
|
583
554
|
derivationScheme: KeyDerivationScheme.ProtocolContext,
|
|
584
555
|
}],
|
|
585
556
|
};
|
|
586
|
-
|
|
557
|
+
await parsed.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
|
|
587
558
|
// Author and authorization should be preserved after append
|
|
588
559
|
expect(parsed.author).toBe(bob.did);
|
|
589
560
|
expect(parsed['_message'].authorization).toBeDefined();
|
|
590
561
|
// Alice signs as owner — should NOT throw
|
|
591
|
-
|
|
562
|
+
await parsed.signAsOwner(Jws.createSigner(alice));
|
|
592
563
|
expect(parsed.owner).toBe(alice.did);
|
|
593
564
|
expect(parsed['_message'].authorization.ownerSignature).toBeDefined();
|
|
594
565
|
// Both recipient entries should be present
|
|
@@ -598,13 +569,13 @@ describe('RecordsWrite', () => {
|
|
|
598
569
|
expect(encryption.recipients[1].header.derivationScheme).toBe('protocolContext');
|
|
599
570
|
// validateIntegrity should pass — the stale encryptionCid in the
|
|
600
571
|
// author's signature is allowed when ownerSignature is present
|
|
601
|
-
|
|
602
|
-
})
|
|
603
|
-
it('should throw when append is true but encryption does not exist', () =>
|
|
604
|
-
const alice =
|
|
572
|
+
await parsed['validateIntegrity']();
|
|
573
|
+
});
|
|
574
|
+
it('should throw when append is true but encryption does not exist', async () => {
|
|
575
|
+
const alice = await TestDataGenerator.generatePersona();
|
|
605
576
|
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
606
577
|
const dataEncryptionIV = TestDataGenerator.randomBytes(12);
|
|
607
|
-
const recordsWrite =
|
|
578
|
+
const recordsWrite = await RecordsWrite.create({
|
|
608
579
|
signer: Jws.createSigner(alice),
|
|
609
580
|
protocol: 'https://example.com/protocol',
|
|
610
581
|
protocolPath: 'test',
|
|
@@ -621,8 +592,8 @@ describe('RecordsWrite', () => {
|
|
|
621
592
|
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
622
593
|
}],
|
|
623
594
|
};
|
|
624
|
-
|
|
625
|
-
})
|
|
595
|
+
await expect(recordsWrite.encryptSymmetricEncryptionKey(encryptionInput, { append: true })).rejects.toThrow(DwnErrorCode.RecordsWriteMissingEncryption);
|
|
596
|
+
});
|
|
626
597
|
});
|
|
627
598
|
});
|
|
628
599
|
//# sourceMappingURL=records-write.spec.js.map
|