@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 * as cbor from '@ipld/dag-cbor';
|
|
11
2
|
import { CID } from 'multiformats/cid';
|
|
12
3
|
import { DataStream } from '../../src/utils/data-stream.js';
|
|
@@ -34,6 +25,22 @@ import { X25519 } from '@enbox/crypto';
|
|
|
34
25
|
import { ContentEncryptionAlgorithm, Encryption } from '../../src/utils/encryption.js';
|
|
35
26
|
import { DwnInterfaceName, DwnMethodName } from '../../src/enums/dwn-interface-method.js';
|
|
36
27
|
import { HdKey, KeyDerivationScheme } from '../../src/utils/hd-key.js';
|
|
28
|
+
/**
|
|
29
|
+
* Protocol definition that matches the defaults used by `TestDataGenerator.generateRecordsWrite()`:
|
|
30
|
+
* `protocol: 'http://test-protocol.xyz'`, `protocolPath: 'testRecord'`.
|
|
31
|
+
*
|
|
32
|
+
* Install via `TestDataGenerator.installDefaultTestProtocol(dwn, persona)`.
|
|
33
|
+
*/
|
|
34
|
+
export const defaultTestProtocolDefinition = {
|
|
35
|
+
protocol: 'http://test-protocol.xyz',
|
|
36
|
+
published: false,
|
|
37
|
+
types: {
|
|
38
|
+
testRecord: {}
|
|
39
|
+
},
|
|
40
|
+
structure: {
|
|
41
|
+
testRecord: {}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
37
44
|
/**
|
|
38
45
|
* Utility class for generating data for testing.
|
|
39
46
|
*/
|
|
@@ -41,143 +48,146 @@ export class TestDataGenerator {
|
|
|
41
48
|
/**
|
|
42
49
|
* Generates a persona.
|
|
43
50
|
*/
|
|
44
|
-
static generatePersona(input) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
publicJwk: encPublicKey,
|
|
65
|
-
privateJwk: encPrivateKey,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const persona = {
|
|
69
|
-
did,
|
|
70
|
-
keyId,
|
|
71
|
-
keyPair,
|
|
72
|
-
encryptionKeyPair,
|
|
73
|
-
signer: new PrivateKeySigner({
|
|
74
|
-
privateJwk: keyPair.privateJwk,
|
|
75
|
-
algorithm: keyPair.privateJwk.alg,
|
|
76
|
-
keyId: `${did}#${keyId}`,
|
|
77
|
-
})
|
|
51
|
+
static async generatePersona(input) {
|
|
52
|
+
// generate DID if not given
|
|
53
|
+
let did = input?.did;
|
|
54
|
+
if (!did) {
|
|
55
|
+
const didSuffix = TestDataGenerator.randomString(32);
|
|
56
|
+
did = `did:example:${didSuffix}`;
|
|
57
|
+
}
|
|
58
|
+
// generate persona key ID if not given
|
|
59
|
+
const keyIdSuffix = TestDataGenerator.randomString(10);
|
|
60
|
+
const keyId = input?.keyId ?? `${did}#${keyIdSuffix}`;
|
|
61
|
+
// generate persona signing key pair if not given (secp256k1 for ES256K signatures)
|
|
62
|
+
const keyPair = input?.keyPair ?? await Secp256k1.generateKeyPair();
|
|
63
|
+
// generate persona encryption key pair if not given (X25519 for ECDH-ES key agreement)
|
|
64
|
+
let encryptionKeyPair = input?.encryptionKeyPair;
|
|
65
|
+
if (!encryptionKeyPair) {
|
|
66
|
+
const encPrivateKey = await X25519.generateKey();
|
|
67
|
+
const encPublicKey = await X25519.getPublicKey({ key: encPrivateKey });
|
|
68
|
+
encryptionKeyPair = {
|
|
69
|
+
publicJwk: encPublicKey,
|
|
70
|
+
privateJwk: encPrivateKey,
|
|
78
71
|
};
|
|
79
|
-
|
|
72
|
+
}
|
|
73
|
+
const persona = {
|
|
74
|
+
did,
|
|
75
|
+
keyId,
|
|
76
|
+
keyPair,
|
|
77
|
+
encryptionKeyPair,
|
|
78
|
+
signer: new PrivateKeySigner({
|
|
79
|
+
privateJwk: keyPair.privateJwk,
|
|
80
|
+
algorithm: keyPair.privateJwk.alg,
|
|
81
|
+
keyId: `${did}#${keyId}`,
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
return persona;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Installs the default test protocol (`http://test-protocol.xyz` with `testRecord` type)
|
|
88
|
+
* on the given DWN for the given persona. Call this before processing any RecordsWrite
|
|
89
|
+
* created with `generateRecordsWrite()` that uses the default protocol.
|
|
90
|
+
*/
|
|
91
|
+
static async installDefaultTestProtocol(dwn, persona) {
|
|
92
|
+
const protocolsConfigure = await ProtocolsConfigure.create({
|
|
93
|
+
definition: defaultTestProtocolDefinition,
|
|
94
|
+
signer: Jws.createSigner(persona),
|
|
80
95
|
});
|
|
96
|
+
const reply = await dwn.processMessage(persona.did, protocolsConfigure.message);
|
|
97
|
+
if (reply.status.code !== 202) {
|
|
98
|
+
throw new Error(`Failed to install default test protocol: ${reply.status.code} ${reply.status.detail}`);
|
|
99
|
+
}
|
|
81
100
|
}
|
|
82
101
|
/**
|
|
83
102
|
* Generates a ProtocolsConfigure message for testing.
|
|
84
103
|
* Optional parameters are generated if not given.
|
|
85
104
|
* Implementation currently uses `ProtocolsConfigure.create()`.
|
|
86
105
|
*/
|
|
87
|
-
static generateProtocolsConfigure(input) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
types: {},
|
|
99
|
-
structure: {}
|
|
100
|
-
};
|
|
101
|
-
definition.types[generatedLabel] = {
|
|
102
|
-
schema: `test-object`,
|
|
103
|
-
dataFormats: ['text/plain']
|
|
104
|
-
};
|
|
105
|
-
definition.structure[generatedLabel] = {};
|
|
106
|
-
}
|
|
107
|
-
const signer = Jws.createSigner(author);
|
|
108
|
-
const options = {
|
|
109
|
-
messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
|
|
110
|
-
definition,
|
|
111
|
-
signer,
|
|
112
|
-
permissionGrantId: input === null || input === void 0 ? void 0 : input.permissionGrantId,
|
|
113
|
-
delegatedGrant: input === null || input === void 0 ? void 0 : input.delegatedGrant
|
|
106
|
+
static async generateProtocolsConfigure(input) {
|
|
107
|
+
const author = input?.author ?? await TestDataGenerator.generatePersona();
|
|
108
|
+
// generate protocol types and definition if not given
|
|
109
|
+
let definition = input?.protocolDefinition;
|
|
110
|
+
if (!definition) {
|
|
111
|
+
const generatedLabel = 'record' + TestDataGenerator.randomString(10);
|
|
112
|
+
definition = {
|
|
113
|
+
protocol: TestDataGenerator.randomString(20),
|
|
114
|
+
published: input?.published ?? false,
|
|
115
|
+
types: {},
|
|
116
|
+
structure: {}
|
|
114
117
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
message: protocolsConfigure.message,
|
|
119
|
-
protocolsConfigure
|
|
118
|
+
definition.types[generatedLabel] = {
|
|
119
|
+
schema: `test-object`,
|
|
120
|
+
dataFormats: ['text/plain']
|
|
120
121
|
};
|
|
121
|
-
|
|
122
|
+
definition.structure[generatedLabel] = {};
|
|
123
|
+
}
|
|
124
|
+
const signer = Jws.createSigner(author);
|
|
125
|
+
const options = {
|
|
126
|
+
messageTimestamp: input?.messageTimestamp,
|
|
127
|
+
definition,
|
|
128
|
+
signer,
|
|
129
|
+
permissionGrantId: input?.permissionGrantId,
|
|
130
|
+
delegatedGrant: input?.delegatedGrant
|
|
131
|
+
};
|
|
132
|
+
const protocolsConfigure = await ProtocolsConfigure.create(options);
|
|
133
|
+
return {
|
|
134
|
+
author,
|
|
135
|
+
message: protocolsConfigure.message,
|
|
136
|
+
protocolsConfigure
|
|
137
|
+
};
|
|
122
138
|
}
|
|
123
139
|
;
|
|
124
140
|
/**
|
|
125
141
|
* Generates a ProtocolsQuery message for testing.
|
|
126
142
|
*/
|
|
127
|
-
static generateProtocolsQuery(input) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
protocolsQuery
|
|
145
|
-
};
|
|
146
|
-
});
|
|
143
|
+
static async generateProtocolsQuery(input) {
|
|
144
|
+
// generate author persona if not given
|
|
145
|
+
const author = input?.author ?? await TestDataGenerator.generatePersona();
|
|
146
|
+
const signer = Jws.createSigner(author);
|
|
147
|
+
const options = {
|
|
148
|
+
messageTimestamp: input?.messageTimestamp,
|
|
149
|
+
filter: input?.filter,
|
|
150
|
+
signer,
|
|
151
|
+
permissionGrantId: input?.permissionGrantId,
|
|
152
|
+
};
|
|
153
|
+
removeUndefinedProperties(options);
|
|
154
|
+
const protocolsQuery = await ProtocolsQuery.create(options);
|
|
155
|
+
return {
|
|
156
|
+
author,
|
|
157
|
+
message: protocolsQuery.message,
|
|
158
|
+
protocolsQuery
|
|
159
|
+
};
|
|
147
160
|
}
|
|
148
161
|
;
|
|
149
|
-
static generateGrantCreate(input) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
dataEncodedMessage: grant.dataEncodedMessage
|
|
179
|
-
};
|
|
180
|
-
});
|
|
162
|
+
static async generateGrantCreate(input) {
|
|
163
|
+
const author = input?.author ?? await TestDataGenerator.generatePersona();
|
|
164
|
+
const grantedToPersona = input?.grantedTo ?? await TestDataGenerator.generatePersona();
|
|
165
|
+
const dateExpires = input?.dateExpires ?? Time.createOffsetTimestamp({ seconds: 10 });
|
|
166
|
+
const scope = input?.scope ?? {
|
|
167
|
+
interface: DwnInterfaceName.Messages,
|
|
168
|
+
method: DwnMethodName.Read
|
|
169
|
+
};
|
|
170
|
+
const signer = Jws.createSigner(author);
|
|
171
|
+
const grantedTo = grantedToPersona.did;
|
|
172
|
+
const options = {
|
|
173
|
+
signer,
|
|
174
|
+
grantedTo,
|
|
175
|
+
dateExpires,
|
|
176
|
+
scope,
|
|
177
|
+
description: input?.description ?? TestDataGenerator.randomString(10),
|
|
178
|
+
delegated: input?.delegated ?? false,
|
|
179
|
+
requestId: input?.requestId,
|
|
180
|
+
conditions: input?.conditions,
|
|
181
|
+
};
|
|
182
|
+
const grant = await PermissionsProtocol.createGrant(options);
|
|
183
|
+
const dataStream = DataStream.fromBytes(grant.permissionGrantBytes);
|
|
184
|
+
return {
|
|
185
|
+
dataStream,
|
|
186
|
+
recordsWrite: grant.recordsWrite,
|
|
187
|
+
dataBytes: grant.permissionGrantBytes,
|
|
188
|
+
message: grant.recordsWrite.message,
|
|
189
|
+
dataEncodedMessage: grant.dataEncodedMessage
|
|
190
|
+
};
|
|
181
191
|
}
|
|
182
192
|
;
|
|
183
193
|
/**
|
|
@@ -190,54 +200,51 @@ export class TestDataGenerator {
|
|
|
190
200
|
* @param input.signer MessageSigner of the message. Generated if not given.
|
|
191
201
|
* @param input.schema Schema of the message. Randomly generated if not given.
|
|
192
202
|
*/
|
|
193
|
-
static generateRecordsWrite(input) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
recordsWrite
|
|
239
|
-
};
|
|
240
|
-
});
|
|
203
|
+
static async generateRecordsWrite(input) {
|
|
204
|
+
const author = input?.author ?? await TestDataGenerator.generatePersona();
|
|
205
|
+
const signer = Jws.createSigner(author);
|
|
206
|
+
const attestationSigners = Jws.createSigners(input?.attesters ?? []);
|
|
207
|
+
const dataCid = input?.dataCid;
|
|
208
|
+
const dataSize = input?.dataSize;
|
|
209
|
+
let dataBytes;
|
|
210
|
+
let dataStream;
|
|
211
|
+
if (dataCid === undefined && dataSize === undefined) {
|
|
212
|
+
dataBytes = input?.data ?? TestDataGenerator.randomBytes(32);
|
|
213
|
+
dataStream = DataStream.fromBytes(dataBytes);
|
|
214
|
+
}
|
|
215
|
+
const options = {
|
|
216
|
+
recipient: input?.recipient,
|
|
217
|
+
protocol: input?.protocol ?? 'http://test-protocol.xyz',
|
|
218
|
+
protocolPath: input?.protocolPath ?? 'testRecord',
|
|
219
|
+
protocolRole: input?.protocolRole,
|
|
220
|
+
schema: input?.schema ?? `http://${TestDataGenerator.randomString(20)}`,
|
|
221
|
+
tags: input?.tags,
|
|
222
|
+
recordId: input?.recordId,
|
|
223
|
+
parentContextId: input?.parentContextId,
|
|
224
|
+
published: input?.published,
|
|
225
|
+
dataFormat: input?.dataFormat ?? 'application/json',
|
|
226
|
+
dateCreated: input?.dateCreated,
|
|
227
|
+
messageTimestamp: input?.messageTimestamp,
|
|
228
|
+
datePublished: input?.datePublished,
|
|
229
|
+
data: dataBytes,
|
|
230
|
+
dataCid,
|
|
231
|
+
dataSize,
|
|
232
|
+
signer,
|
|
233
|
+
attestationSigners,
|
|
234
|
+
encryptionInput: input?.encryptionInput,
|
|
235
|
+
permissionGrantId: input?.permissionGrantId,
|
|
236
|
+
};
|
|
237
|
+
const recordsWrite = await RecordsWrite.create(options);
|
|
238
|
+
const message = recordsWrite.message;
|
|
239
|
+
return {
|
|
240
|
+
author,
|
|
241
|
+
message,
|
|
242
|
+
dataCid,
|
|
243
|
+
dataSize,
|
|
244
|
+
dataBytes,
|
|
245
|
+
dataStream,
|
|
246
|
+
recordsWrite
|
|
247
|
+
};
|
|
241
248
|
}
|
|
242
249
|
;
|
|
243
250
|
/**
|
|
@@ -253,286 +260,264 @@ export class TestDataGenerator {
|
|
|
253
260
|
* @param input.encryptSymmetricKeyWithProtocolContextDerivedKey
|
|
254
261
|
* Set to `true` to attach the symmetric key encrypted by the protocol context derived public key
|
|
255
262
|
*/
|
|
256
|
-
static generateProtocolEncryptedRecordsWrite(input) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
263
|
+
static async generateProtocolEncryptedRecordsWrite(input) {
|
|
264
|
+
const { plaintextBytes, author, recipient, protocolDefinition, protocolPath, protocolParentContextId, protocolContextDerivingRootKeyId, protocolContextDerivedPublicKeyJwk, } = input;
|
|
265
|
+
// encrypt the plaintext data for the target with a randomly generated symmetric key
|
|
266
|
+
const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12); // 12 bytes for AES-GCM
|
|
267
|
+
const dataEncryptionKey = TestDataGenerator.randomBytes(32);
|
|
268
|
+
const { ciphertext: encryptedDataBytes, tag: authenticationTag } = await Encryption.aeadEncrypt(ContentEncryptionAlgorithm.A256GCM, dataEncryptionKey, dataEncryptionInitializationVector, plaintextBytes);
|
|
269
|
+
// author generates a RecordsWrite using the encrypted data
|
|
270
|
+
const protocolPathSegments = protocolPath.split('/');
|
|
271
|
+
const recordType = protocolPathSegments[protocolPathSegments.length - 1];
|
|
272
|
+
const { message, dataStream, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
|
|
273
|
+
author,
|
|
274
|
+
recipient,
|
|
275
|
+
protocol: protocolDefinition.protocol,
|
|
276
|
+
protocolPath,
|
|
277
|
+
parentContextId: protocolParentContextId,
|
|
278
|
+
schema: protocolDefinition.types[recordType].schema,
|
|
279
|
+
dataFormat: protocolDefinition.types[recordType].dataFormats?.[0],
|
|
280
|
+
data: encryptedDataBytes
|
|
281
|
+
});
|
|
282
|
+
// final encryption input (`keyEncryptionInputs` to be populated below)
|
|
283
|
+
const encryptionInput = {
|
|
284
|
+
initializationVector: dataEncryptionInitializationVector,
|
|
285
|
+
key: dataEncryptionKey,
|
|
286
|
+
authenticationTag,
|
|
287
|
+
keyEncryptionInputs: []
|
|
288
|
+
};
|
|
289
|
+
if (input.encryptSymmetricKeyWithProtocolPathDerivedKey) {
|
|
290
|
+
// locate the rule set corresponding the protocol path of the message
|
|
291
|
+
let protocolRuleSetSegment = protocolDefinition.structure;
|
|
292
|
+
for (const pathSegment of protocolPathSegments) {
|
|
293
|
+
protocolRuleSetSegment = protocolRuleSetSegment[pathSegment];
|
|
294
|
+
}
|
|
295
|
+
const protocolPathDerivedPublicKeyJwk = protocolRuleSetSegment.$encryption?.publicKeyJwk;
|
|
296
|
+
const protocolPathDerivationRootKeyId = protocolRuleSetSegment.$encryption?.rootKeyId;
|
|
297
|
+
const protocolPathDerivedKeyEncryptionInput = {
|
|
298
|
+
publicKeyId: protocolPathDerivationRootKeyId,
|
|
299
|
+
publicKey: protocolPathDerivedPublicKeyJwk,
|
|
300
|
+
derivationScheme: KeyDerivationScheme.ProtocolPath
|
|
283
301
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
302
|
+
encryptionInput.keyEncryptionInputs.push(protocolPathDerivedKeyEncryptionInput);
|
|
303
|
+
}
|
|
304
|
+
if (input.encryptSymmetricKeyWithProtocolContextDerivedKey) {
|
|
305
|
+
// generate key encryption input that will encrypt the symmetric encryption key using protocol-context derived public key
|
|
306
|
+
let protocolContextDerivedKeyEncryptionInput;
|
|
307
|
+
if (protocolParentContextId === undefined) {
|
|
308
|
+
// author generates protocol-context derived public key for encrypting symmetric key
|
|
309
|
+
const authorRootPrivateKey = {
|
|
310
|
+
rootKeyId: author.keyId,
|
|
311
|
+
derivationScheme: KeyDerivationScheme.ProtocolContext,
|
|
312
|
+
derivedPrivateKey: author.encryptionKeyPair.privateJwk
|
|
313
|
+
};
|
|
314
|
+
const contextId = await RecordsWrite.getEntryId(author.did, message.descriptor);
|
|
315
|
+
const contextDerivationPath = Records.constructKeyDerivationPathUsingProtocolContextScheme(contextId);
|
|
316
|
+
const authorGeneratedProtocolContextDerivedPublicKeyJwk = await HdKey.derivePublicKey(authorRootPrivateKey, contextDerivationPath);
|
|
317
|
+
protocolContextDerivedKeyEncryptionInput = {
|
|
318
|
+
publicKeyId: author.keyId,
|
|
319
|
+
publicKey: authorGeneratedProtocolContextDerivedPublicKeyJwk,
|
|
320
|
+
derivationScheme: KeyDerivationScheme.ProtocolContext
|
|
296
321
|
};
|
|
297
|
-
encryptionInput.keyEncryptionInputs.push(protocolPathDerivedKeyEncryptionInput);
|
|
298
322
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
// author generates protocol-context derived public key for encrypting symmetric key
|
|
304
|
-
const authorRootPrivateKey = {
|
|
305
|
-
rootKeyId: author.keyId,
|
|
306
|
-
derivationScheme: KeyDerivationScheme.ProtocolContext,
|
|
307
|
-
derivedPrivateKey: author.encryptionKeyPair.privateJwk
|
|
308
|
-
};
|
|
309
|
-
const contextId = yield RecordsWrite.getEntryId(author.did, message.descriptor);
|
|
310
|
-
const contextDerivationPath = Records.constructKeyDerivationPathUsingProtocolContextScheme(contextId);
|
|
311
|
-
const authorGeneratedProtocolContextDerivedPublicKeyJwk = yield HdKey.derivePublicKey(authorRootPrivateKey, contextDerivationPath);
|
|
312
|
-
protocolContextDerivedKeyEncryptionInput = {
|
|
313
|
-
publicKeyId: author.keyId,
|
|
314
|
-
publicKey: authorGeneratedProtocolContextDerivedPublicKeyJwk,
|
|
315
|
-
derivationScheme: KeyDerivationScheme.ProtocolContext
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
if (protocolContextDerivingRootKeyId === undefined ||
|
|
320
|
-
protocolContextDerivedPublicKeyJwk === undefined) {
|
|
321
|
-
throw new Error('`protocolContextDerivingRootKeyId` and `protocolContextDerivedPublicKeyJwk` must both be defined if `protocolContextId` is given');
|
|
322
|
-
}
|
|
323
|
-
protocolContextDerivedKeyEncryptionInput = {
|
|
324
|
-
publicKeyId: protocolContextDerivingRootKeyId,
|
|
325
|
-
publicKey: protocolContextDerivedPublicKeyJwk,
|
|
326
|
-
derivationScheme: KeyDerivationScheme.ProtocolContext
|
|
327
|
-
};
|
|
323
|
+
else {
|
|
324
|
+
if (protocolContextDerivingRootKeyId === undefined ||
|
|
325
|
+
protocolContextDerivedPublicKeyJwk === undefined) {
|
|
326
|
+
throw new Error('`protocolContextDerivingRootKeyId` and `protocolContextDerivedPublicKeyJwk` must both be defined if `protocolContextId` is given');
|
|
328
327
|
}
|
|
329
|
-
|
|
328
|
+
protocolContextDerivedKeyEncryptionInput = {
|
|
329
|
+
publicKeyId: protocolContextDerivingRootKeyId,
|
|
330
|
+
publicKey: protocolContextDerivedPublicKeyJwk,
|
|
331
|
+
derivationScheme: KeyDerivationScheme.ProtocolContext
|
|
332
|
+
};
|
|
330
333
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
});
|
|
334
|
+
encryptionInput.keyEncryptionInputs.push(protocolContextDerivedKeyEncryptionInput);
|
|
335
|
+
}
|
|
336
|
+
await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput);
|
|
337
|
+
await recordsWrite.sign({ signer: Jws.createSigner(author) });
|
|
338
|
+
return { message, dataStream: dataStream, recordsWrite, encryptedDataBytes, encryptionInput };
|
|
335
339
|
}
|
|
336
340
|
/**
|
|
337
341
|
* Generates a valid RecordsWrite that modifies the given an existing write.
|
|
338
342
|
* Any mutable property is not specified will be automatically mutated.
|
|
339
343
|
* e.g. if `published` is not specified, it will be toggled from the state of the given existing write.
|
|
340
344
|
*/
|
|
341
|
-
static generateFromRecordsWrite(input) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
dataStream
|
|
366
|
-
};
|
|
367
|
-
});
|
|
345
|
+
static async generateFromRecordsWrite(input) {
|
|
346
|
+
const existingMessage = input.existingWrite.message;
|
|
347
|
+
const currentTime = Time.getCurrentTimestamp();
|
|
348
|
+
const published = input.published ?? existingMessage.descriptor.published ? false : true; // toggle from the parent value if not given explicitly
|
|
349
|
+
const datePublished = input.datePublished ?? (published ? currentTime : undefined);
|
|
350
|
+
const dataBytes = input.data ?? TestDataGenerator.randomBytes(32);
|
|
351
|
+
const dataStream = DataStream.fromBytes(dataBytes);
|
|
352
|
+
const options = {
|
|
353
|
+
recordsWriteMessage: input.existingWrite.message,
|
|
354
|
+
data: dataBytes,
|
|
355
|
+
published,
|
|
356
|
+
datePublished,
|
|
357
|
+
messageTimestamp: input.messageTimestamp,
|
|
358
|
+
protocolRole: input.protocolRole,
|
|
359
|
+
tags: input.tags,
|
|
360
|
+
signer: Jws.createSigner(input.author)
|
|
361
|
+
};
|
|
362
|
+
const recordsWrite = await RecordsWrite.createFrom(options);
|
|
363
|
+
return {
|
|
364
|
+
message: recordsWrite.message,
|
|
365
|
+
recordsWrite,
|
|
366
|
+
dataBytes,
|
|
367
|
+
dataStream
|
|
368
|
+
};
|
|
368
369
|
}
|
|
369
370
|
/**
|
|
370
371
|
* Generates a RecordsQuery message for testing.
|
|
371
372
|
*/
|
|
372
|
-
static generateRecordsQuery(input) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
message
|
|
402
|
-
};
|
|
403
|
-
});
|
|
373
|
+
static async generateRecordsQuery(input) {
|
|
374
|
+
let author = input?.author;
|
|
375
|
+
const anonymous = input?.anonymous ?? false;
|
|
376
|
+
if (anonymous && author) {
|
|
377
|
+
throw new Error('Cannot have `author` and be anonymous at the same time.');
|
|
378
|
+
}
|
|
379
|
+
// generate author if needed
|
|
380
|
+
if (author === undefined && !anonymous) {
|
|
381
|
+
author = await TestDataGenerator.generatePersona();
|
|
382
|
+
}
|
|
383
|
+
let signer = undefined;
|
|
384
|
+
if (author !== undefined) {
|
|
385
|
+
signer = Jws.createSigner(author);
|
|
386
|
+
}
|
|
387
|
+
const options = {
|
|
388
|
+
messageTimestamp: input?.messageTimestamp,
|
|
389
|
+
signer,
|
|
390
|
+
filter: input?.filter ?? { schema: TestDataGenerator.randomString(10) }, // must have one filter property if no filter is given
|
|
391
|
+
dateSort: input?.dateSort,
|
|
392
|
+
pagination: input?.pagination,
|
|
393
|
+
protocolRole: input?.protocolRole,
|
|
394
|
+
};
|
|
395
|
+
removeUndefinedProperties(options);
|
|
396
|
+
const recordsQuery = await RecordsQuery.create(options);
|
|
397
|
+
const message = recordsQuery.message;
|
|
398
|
+
return {
|
|
399
|
+
author,
|
|
400
|
+
message
|
|
401
|
+
};
|
|
404
402
|
}
|
|
405
403
|
;
|
|
406
404
|
/**
|
|
407
405
|
* Generates a RecordsSubscribe message for testing.
|
|
408
406
|
*/
|
|
409
|
-
static generateRecordsSubscribe(input) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
};
|
|
440
|
-
});
|
|
407
|
+
static async generateRecordsSubscribe(input) {
|
|
408
|
+
let author = input?.author;
|
|
409
|
+
const anonymous = input?.anonymous ?? false;
|
|
410
|
+
if (anonymous && author) {
|
|
411
|
+
throw new Error('Cannot have `author` and be anonymous at the same time.');
|
|
412
|
+
}
|
|
413
|
+
// generate author if needed
|
|
414
|
+
if (author === undefined && !anonymous) {
|
|
415
|
+
author = await TestDataGenerator.generatePersona();
|
|
416
|
+
}
|
|
417
|
+
let signer = undefined;
|
|
418
|
+
if (author !== undefined) {
|
|
419
|
+
signer = Jws.createSigner(author);
|
|
420
|
+
}
|
|
421
|
+
const options = {
|
|
422
|
+
messageTimestamp: input?.messageTimestamp,
|
|
423
|
+
signer,
|
|
424
|
+
filter: input?.filter ?? { schema: TestDataGenerator.randomString(10) }, // must have one filter property if no filter is given
|
|
425
|
+
dateSort: input?.dateSort,
|
|
426
|
+
pagination: input?.pagination,
|
|
427
|
+
protocolRole: input?.protocolRole,
|
|
428
|
+
cursor: input?.cursor,
|
|
429
|
+
};
|
|
430
|
+
removeUndefinedProperties(options);
|
|
431
|
+
const recordsSubscribe = await RecordsSubscribe.create(options);
|
|
432
|
+
const message = recordsSubscribe.message;
|
|
433
|
+
return {
|
|
434
|
+
author,
|
|
435
|
+
message
|
|
436
|
+
};
|
|
441
437
|
}
|
|
442
438
|
/**
|
|
443
439
|
* Generates a RecordsCount message for testing.
|
|
444
440
|
*/
|
|
445
|
-
static generateRecordsCount(input) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
message
|
|
473
|
-
};
|
|
474
|
-
});
|
|
441
|
+
static async generateRecordsCount(input) {
|
|
442
|
+
let author = input?.author;
|
|
443
|
+
const anonymous = input?.anonymous ?? false;
|
|
444
|
+
if (anonymous && author) {
|
|
445
|
+
throw new Error('Cannot have `author` and be anonymous at the same time.');
|
|
446
|
+
}
|
|
447
|
+
// generate author if needed
|
|
448
|
+
if (author === undefined && !anonymous) {
|
|
449
|
+
author = await TestDataGenerator.generatePersona();
|
|
450
|
+
}
|
|
451
|
+
let signer = undefined;
|
|
452
|
+
if (author !== undefined) {
|
|
453
|
+
signer = Jws.createSigner(author);
|
|
454
|
+
}
|
|
455
|
+
const options = {
|
|
456
|
+
messageTimestamp: input?.messageTimestamp,
|
|
457
|
+
signer,
|
|
458
|
+
filter: input?.filter ?? { schema: TestDataGenerator.randomString(10) },
|
|
459
|
+
protocolRole: input?.protocolRole,
|
|
460
|
+
};
|
|
461
|
+
removeUndefinedProperties(options);
|
|
462
|
+
const recordsCount = await RecordsCount.create(options);
|
|
463
|
+
const message = recordsCount.message;
|
|
464
|
+
return {
|
|
465
|
+
author,
|
|
466
|
+
message
|
|
467
|
+
};
|
|
475
468
|
}
|
|
476
469
|
/**
|
|
477
470
|
* Generates a RecordsDelete for testing.
|
|
478
471
|
*/
|
|
479
|
-
static generateRecordsDelete(input) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
protocolRole: input === null || input === void 0 ? void 0 : input.protocolRole,
|
|
486
|
-
signer: Jws.createSigner(author)
|
|
487
|
-
});
|
|
488
|
-
return {
|
|
489
|
-
author,
|
|
490
|
-
recordsDelete,
|
|
491
|
-
message: recordsDelete.message
|
|
492
|
-
};
|
|
472
|
+
static async generateRecordsDelete(input) {
|
|
473
|
+
const author = input?.author ?? await TestDataGenerator.generateDidKeyPersona();
|
|
474
|
+
const recordsDelete = await RecordsDelete.create({
|
|
475
|
+
recordId: input?.recordId ?? await TestDataGenerator.randomCborSha256Cid(),
|
|
476
|
+
protocolRole: input?.protocolRole,
|
|
477
|
+
signer: Jws.createSigner(author)
|
|
493
478
|
});
|
|
479
|
+
return {
|
|
480
|
+
author,
|
|
481
|
+
recordsDelete,
|
|
482
|
+
message: recordsDelete.message
|
|
483
|
+
};
|
|
494
484
|
}
|
|
495
485
|
/**
|
|
496
486
|
* Generates a MessagesSubscribe message for testing.
|
|
497
487
|
*/
|
|
498
|
-
static generateMessagesSubscribe(input) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
};
|
|
517
|
-
});
|
|
488
|
+
static async generateMessagesSubscribe(input) {
|
|
489
|
+
const author = input?.author ?? await TestDataGenerator.generatePersona();
|
|
490
|
+
const signer = Jws.createSigner(author);
|
|
491
|
+
const options = {
|
|
492
|
+
filters: input?.filters,
|
|
493
|
+
messageTimestamp: input?.messageTimestamp,
|
|
494
|
+
permissionGrantId: input?.permissionGrantId,
|
|
495
|
+
cursor: input?.cursor,
|
|
496
|
+
signer,
|
|
497
|
+
};
|
|
498
|
+
removeUndefinedProperties(options);
|
|
499
|
+
const messagesSubscribe = await MessagesSubscribe.create(options);
|
|
500
|
+
const message = messagesSubscribe.message;
|
|
501
|
+
return {
|
|
502
|
+
author,
|
|
503
|
+
messagesSubscribe,
|
|
504
|
+
message
|
|
505
|
+
};
|
|
518
506
|
}
|
|
519
|
-
static generateMessagesRead(input) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
message: messagesRead.message,
|
|
534
|
-
};
|
|
535
|
-
});
|
|
507
|
+
static async generateMessagesRead(input) {
|
|
508
|
+
const author = input?.author ?? await TestDataGenerator.generatePersona();
|
|
509
|
+
const signer = Jws.createSigner(author);
|
|
510
|
+
const options = {
|
|
511
|
+
signer,
|
|
512
|
+
messageCid: input.messageCid,
|
|
513
|
+
permissionGrantId: input.permissionGrantId
|
|
514
|
+
};
|
|
515
|
+
const messagesRead = await MessagesRead.create(options);
|
|
516
|
+
return {
|
|
517
|
+
author,
|
|
518
|
+
messagesRead,
|
|
519
|
+
message: messagesRead.message,
|
|
520
|
+
};
|
|
536
521
|
}
|
|
537
522
|
/**
|
|
538
523
|
* Generates a dummy `authorization` property for a DWN message that only conforms to schema validation.
|
|
@@ -557,13 +542,11 @@ export class TestDataGenerator {
|
|
|
557
542
|
/**
|
|
558
543
|
* Generates a random but well-formed signature string in Base64Url format.
|
|
559
544
|
*/
|
|
560
|
-
static randomSignatureString() {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return signatureString;
|
|
566
|
-
});
|
|
545
|
+
static async randomSignatureString() {
|
|
546
|
+
const keyPair = await ed25519.generateKeyPair();
|
|
547
|
+
const signatureBytes = await ed25519.sign(TestDataGenerator.randomBytes(32), keyPair.privateJwk);
|
|
548
|
+
const signatureString = Encoder.bytesToBase64Url(signatureBytes);
|
|
549
|
+
return signatureString;
|
|
567
550
|
}
|
|
568
551
|
/**
|
|
569
552
|
* Generates a random alpha-numeric string.
|
|
@@ -592,13 +575,11 @@ export class TestDataGenerator {
|
|
|
592
575
|
/**
|
|
593
576
|
* Generates a random CBOR SHA256 CID.
|
|
594
577
|
*/
|
|
595
|
-
static randomCborSha256Cid() {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return cid.toString();
|
|
601
|
-
});
|
|
578
|
+
static async randomCborSha256Cid() {
|
|
579
|
+
const randomBytes = TestDataGenerator.randomBytes(32);
|
|
580
|
+
const randomMultihash = await sha256.digest(randomBytes);
|
|
581
|
+
const cid = await CID.createV1(cbor.code, randomMultihash);
|
|
582
|
+
return cid.toString();
|
|
602
583
|
}
|
|
603
584
|
/**
|
|
604
585
|
* Generates a random within a range (inclusive).
|
|
@@ -648,36 +629,34 @@ export class TestDataGenerator {
|
|
|
648
629
|
/**
|
|
649
630
|
* Generates a did:key persona.
|
|
650
631
|
*/
|
|
651
|
-
static generateDidKeyPersona() {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
};
|
|
680
|
-
});
|
|
632
|
+
static async generateDidKeyPersona() {
|
|
633
|
+
const did = await DidKey.create();
|
|
634
|
+
const signingMethod = await DidKey.getSigningMethod({ didDocument: did.document });
|
|
635
|
+
const keyId = signingMethod.id;
|
|
636
|
+
const portableDid = await did.export();
|
|
637
|
+
const keyPair = {
|
|
638
|
+
// TODO: #672 - port and use type from @enbox/crypto - https://github.com/enboxorg/enbox/issues/672
|
|
639
|
+
publicJwk: signingMethod.publicKeyJwk,
|
|
640
|
+
privateJwk: portableDid.privateKeys[0],
|
|
641
|
+
};
|
|
642
|
+
// Generate X25519 encryption key pair for did:key personas
|
|
643
|
+
const encPrivateKey = await X25519.generateKey();
|
|
644
|
+
const encPublicKey = await X25519.getPublicKey({ key: encPrivateKey });
|
|
645
|
+
const encryptionKeyPair = {
|
|
646
|
+
publicJwk: encPublicKey,
|
|
647
|
+
privateJwk: encPrivateKey,
|
|
648
|
+
};
|
|
649
|
+
return {
|
|
650
|
+
did: did.uri,
|
|
651
|
+
keyId,
|
|
652
|
+
keyPair,
|
|
653
|
+
encryptionKeyPair,
|
|
654
|
+
signer: new PrivateKeySigner({
|
|
655
|
+
privateJwk: keyPair.privateJwk,
|
|
656
|
+
algorithm: keyPair.privateJwk.alg,
|
|
657
|
+
keyId
|
|
658
|
+
})
|
|
659
|
+
};
|
|
681
660
|
}
|
|
682
661
|
}
|
|
683
662
|
//# sourceMappingURL=test-data-generator.js.map
|