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