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