@enbox/dwn-sdk-js 0.4.8 → 0.4.10
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 +1 -1
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +1262 -3888
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/constants.js +0 -26
- package/dist/esm/src/core/constants.js.map +1 -1
- package/dist/esm/src/core/encryption-control.js +0 -10
- package/dist/esm/src/core/encryption-control.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js.map +1 -1
- package/dist/esm/src/index.js +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +0 -9
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/store/index-level-compound.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +6 -2
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +2 -7
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +0 -27
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +23 -51
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +17 -31
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/tests/core/constants.spec.js +1 -11
- package/dist/esm/tests/core/constants.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +5 -5
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/features/author-delegated-grant.spec.js +16 -16
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +7 -7
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +8 -8
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +18 -63
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune-cross-protocol.spec.js +5 -5
- package/dist/esm/tests/features/records-prune-cross-protocol.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +15 -15
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-squash.spec.js +9 -9
- package/dist/esm/tests/features/records-squash.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +28 -28
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +3 -3
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/data-stream.fuzz.spec.js +2 -2
- package/dist/esm/tests/fuzz/data-stream.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/filter.fuzz.spec.js +1 -1
- package/dist/esm/tests/fuzz/filter.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/records-utils.fuzz.spec.js +2 -2
- package/dist/esm/tests/fuzz/records-utils.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/resumable-task-store.fuzz.spec.js +4 -4
- package/dist/esm/tests/fuzz/resumable-task-store.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +16 -16
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +5 -5
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +11 -11
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +23 -23
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +120 -120
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +16 -14
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +10 -10
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +41 -41
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +9 -9
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +5 -51
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +4 -4
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +2 -2
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +28 -28
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +3 -3
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +83 -83
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +2 -2
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +30 -30
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/store-dependent-tests.spec.js +5 -0
- package/dist/esm/tests/store-dependent-tests.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +15 -15
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +18 -30
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-control-test-utils.js +1 -1
- package/dist/esm/tests/utils/encryption-control-test-utils.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +31 -34
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +8 -8
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +2 -2
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +76 -24
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +88 -120
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +0 -13
- package/dist/types/src/core/constants.d.ts.map +1 -1
- package/dist/types/src/core/encryption-control.d.ts +0 -1
- package/dist/types/src/core/encryption-control.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +0 -7
- package/dist/types/src/core/replication-apply.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +1 -2
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +0 -4
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/store/index-level-compound.d.ts +2 -4
- package/dist/types/src/store/index-level-compound.d.ts.map +1 -1
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +1 -1
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +0 -3
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -11
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/jws.d.ts +1 -2
- package/dist/types/src/utils/jws.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +2 -7
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -8
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +17 -1
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/constants.ts +0 -30
- package/src/core/encryption-control.ts +1 -17
- package/src/core/replication-apply.ts +0 -8
- package/src/index.ts +0 -1
- package/src/interfaces/messages-subscribe.ts +1 -2
- package/src/interfaces/records-write.ts +0 -13
- package/src/store/index-level-compound.ts +2 -5
- package/src/store/level-wrapper.ts +6 -2
- package/src/types/protocols-types.ts +2 -1
- package/src/utils/encryption.ts +2 -15
- package/src/utils/hd-key.ts +1 -32
- package/src/utils/jws.ts +1 -2
- package/src/utils/protocols.ts +15 -78
- package/src/utils/records.ts +15 -57
- package/dist/esm/tests/validation/json-schemas/encryption/delivery.spec.js +0 -47
- package/dist/esm/tests/validation/json-schemas/encryption/delivery.spec.js.map +0 -1
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js +0 -72
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js.map +0 -1
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts +0 -2
- package/dist/types/tests/validation/json-schemas/encryption/delivery.spec.d.ts.map +0 -1
- package/dist/types/tests/validation/json-schemas/encryption/grant-key.spec.d.ts +0 -2
- package/dist/types/tests/validation/json-schemas/encryption/grant-key.spec.d.ts.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { MessagesFilter } from '../types/messages-types.js';
|
|
2
1
|
import type { MessageSigner } from '../types/signer.js';
|
|
3
2
|
import type { ProgressToken } from '../types/subscriptions.js';
|
|
4
|
-
import type { MessagesSubscribeDescriptor, MessagesSubscribeMessage } from '../types/messages-types.js';
|
|
3
|
+
import type { MessagesFilter, MessagesSubscribeDescriptor, MessagesSubscribeMessage } from '../types/messages-types.js';
|
|
5
4
|
|
|
6
5
|
import { AbstractMessage } from '../core/abstract-message.js';
|
|
7
6
|
import { Message } from '../core/message.js';
|
|
@@ -518,19 +518,6 @@ export class RecordsWrite implements MessageInterface<RecordsWriteMessage> {
|
|
|
518
518
|
return this.message;
|
|
519
519
|
}
|
|
520
520
|
|
|
521
|
-
/**
|
|
522
|
-
* Encrypts the symmetric encryption key using the public keys given and attaches the resulting `encryption` property.
|
|
523
|
-
*/
|
|
524
|
-
public async encryptSymmetricEncryptionKey(
|
|
525
|
-
encryptionInput: EncryptionInput,
|
|
526
|
-
): Promise<void> {
|
|
527
|
-
this._message.encryption = await createEncryptionProperty(encryptionInput);
|
|
528
|
-
|
|
529
|
-
delete this._message.authorization;
|
|
530
|
-
this._signaturePayload = undefined;
|
|
531
|
-
this._author = undefined;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
521
|
/**
|
|
535
522
|
* Signs the RecordsWrite, the signer is commonly the author, but can also be a delegate.
|
|
536
523
|
*/
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import type { CompoundIndexDefinition, IndexedItem, IndexLevelOptions } from './index-level.js';
|
|
1
2
|
import type { Filter, KeyValues, QueryOptions } from '../types/query-types.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type { LevelWrapperBatchOperation, LevelWrapperIteratorOptions } from './level-wrapper.js';
|
|
4
|
-
|
|
5
|
-
import type { CompoundIndexDefinition } from './index-level.js';
|
|
6
|
-
import type { LevelWrapper } from './level-wrapper.js';
|
|
3
|
+
import type { LevelWrapper, LevelWrapperBatchOperation, LevelWrapperIteratorOptions } from './level-wrapper.js';
|
|
7
4
|
|
|
8
5
|
import { FilterUtility } from '../utils/filter.js';
|
|
9
6
|
import { SortDirection } from '../types/query-types.js';
|
|
@@ -251,8 +251,12 @@ export class LevelWrapper<V> {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
// derive an exclusive `maxKey` by changing the last prefix character to the immediate succeeding character in unicode
|
|
254
|
-
// (which matches how `abstract-level` creates a `boundary`)
|
|
255
|
-
|
|
254
|
+
// (which matches how `abstract-level` creates a `boundary`).
|
|
255
|
+
//
|
|
256
|
+
// This MUST stay UTF-16 code-unit based (`charCodeAt`/`fromCharCode`) to match `abstract-level`'s
|
|
257
|
+
// boundary semantics: `fromCharCode` wraps at 0xFFFF whereas `fromCodePoint` would emit an astral
|
|
258
|
+
// surrogate pair, producing a different — and incorrect — key range. NOSONAR (typescript:S7758).
|
|
259
|
+
const maxKey = prefix.slice(0, -1) + String.fromCharCode(prefix.charCodeAt(prefix.length - 1) + 1); // NOSONAR
|
|
256
260
|
const minKey = prefix;
|
|
257
261
|
|
|
258
262
|
return [minKey, maxKey];
|
|
@@ -237,7 +237,8 @@ type ProtocolRuleSetValue =
|
|
|
237
237
|
| ProtocolTagsDefinition
|
|
238
238
|
| ProtocolSizeDefinition
|
|
239
239
|
| ProtocolRecordLimitDefinition
|
|
240
|
-
|
|
|
240
|
+
// `ProtocolDeliveryStrategy` ('direct' | 'subscribe') is intentionally omitted here: its
|
|
241
|
+
// values are already covered by the `string` member below (see the `$delivery` field typing).
|
|
241
242
|
| boolean
|
|
242
243
|
| string
|
|
243
244
|
| undefined;
|
package/src/utils/encryption.ts
CHANGED
|
@@ -107,13 +107,11 @@ export type KeyUnwrapPayload = {
|
|
|
107
107
|
export type X25519KeyWrapInput = {
|
|
108
108
|
cek: Uint8Array;
|
|
109
109
|
keyInput: X25519KeyEncryptionInput;
|
|
110
|
-
ephemeralPrivateKey?: Jwk;
|
|
111
110
|
};
|
|
112
111
|
|
|
113
112
|
export type SealWrapInput = {
|
|
114
113
|
privateKeyBytes: Uint8Array;
|
|
115
114
|
keyInput: SealKeyWrapInput;
|
|
116
|
-
ephemeralPrivateKey?: Jwk;
|
|
117
115
|
};
|
|
118
116
|
|
|
119
117
|
export type SealUnwrapInput = {
|
|
@@ -180,17 +178,6 @@ export class Encryption {
|
|
|
180
178
|
return Encryption.toStream(ciphertext);
|
|
181
179
|
}
|
|
182
180
|
|
|
183
|
-
public static async decryptStream(
|
|
184
|
-
algorithm: ContentEncryptionAlgorithm,
|
|
185
|
-
keyBytes: Uint8Array,
|
|
186
|
-
initializationVector: Uint8Array,
|
|
187
|
-
ciphertextStream: ReadableStream<Uint8Array>,
|
|
188
|
-
): Promise<ReadableStream<Uint8Array>> {
|
|
189
|
-
const ciphertext = await Encryption.readStream(ciphertextStream);
|
|
190
|
-
const plaintext = await Encryption.decrypt(algorithm, keyBytes, initializationVector, ciphertext);
|
|
191
|
-
return Encryption.toStream(plaintext);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
181
|
public static async wrapKey(input: X25519KeyWrapInput): Promise<{ encryptedKey: Uint8Array; ephemeralPublicKey: PublicKeyJwk }> {
|
|
195
182
|
if (Encryption.isX25519KeyAgreementAlgorithm(input.keyInput.algorithm)) {
|
|
196
183
|
return Encryption.wrapX25519Key(input);
|
|
@@ -206,7 +193,7 @@ export class Encryption {
|
|
|
206
193
|
|
|
207
194
|
Encryption.validateContentEncryptionKey(input.privateKeyBytes);
|
|
208
195
|
|
|
209
|
-
const privateKey =
|
|
196
|
+
const privateKey = await X25519.generateKey();
|
|
210
197
|
const publicKey = await X25519.getPublicKey({ key: privateKey }) as PublicKeyJwk;
|
|
211
198
|
const sharedSecret = await X25519.sharedSecret({
|
|
212
199
|
privateKeyA : privateKey,
|
|
@@ -231,7 +218,7 @@ export class Encryption {
|
|
|
231
218
|
private static async wrapX25519Key(input: X25519KeyWrapInput): Promise<{ encryptedKey: Uint8Array; ephemeralPublicKey: PublicKeyJwk }> {
|
|
232
219
|
Encryption.validateContentEncryptionKey(input.cek);
|
|
233
220
|
|
|
234
|
-
const privateKey =
|
|
221
|
+
const privateKey = await X25519.generateKey();
|
|
235
222
|
const publicKey = await X25519.getPublicKey({ key: privateKey }) as PublicKeyJwk;
|
|
236
223
|
const sharedSecret = await X25519.sharedSecret({
|
|
237
224
|
privateKeyA : privateKey,
|
package/src/utils/hd-key.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { PrivateKeyJwk
|
|
1
|
+
import type { PrivateKeyJwk } from '../types/jose-types.js';
|
|
2
2
|
|
|
3
3
|
import { Encoder } from './encoder.js';
|
|
4
|
-
import { X25519 } from '@enbox/crypto';
|
|
5
4
|
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
6
5
|
|
|
7
6
|
export enum KeyDerivationScheme {
|
|
@@ -20,36 +19,6 @@ export type DerivedPrivateJwk = {
|
|
|
20
19
|
* Class containing hierarchical deterministic key related utility methods used by the DWN.
|
|
21
20
|
*/
|
|
22
21
|
export class HdKey {
|
|
23
|
-
/**
|
|
24
|
-
* Derives a descendant private key.
|
|
25
|
-
* Uses X25519 keys for encryption key derivation.
|
|
26
|
-
*/
|
|
27
|
-
public static async derivePrivateKey(ancestorKey: DerivedPrivateJwk, subDerivationPath: string[]): Promise<DerivedPrivateJwk> {
|
|
28
|
-
const ancestorPrivateKey = await X25519.privateKeyToBytes({ privateKey: ancestorKey.derivedPrivateKey });
|
|
29
|
-
const ancestorPrivateKeyDerivationPath = ancestorKey.derivationPath ?? [];
|
|
30
|
-
const derivedPrivateKeyBytes = await HdKey.derivePrivateKeyBytes(ancestorPrivateKey, subDerivationPath);
|
|
31
|
-
const derivedPrivateKeyJwk = await X25519.bytesToPrivateKey({ privateKeyBytes: derivedPrivateKeyBytes });
|
|
32
|
-
const derivedDescendantPrivateKey: DerivedPrivateJwk = {
|
|
33
|
-
rootKeyId : ancestorKey.rootKeyId,
|
|
34
|
-
derivationScheme : ancestorKey.derivationScheme,
|
|
35
|
-
derivationPath : [...ancestorPrivateKeyDerivationPath, ...subDerivationPath],
|
|
36
|
-
derivedPrivateKey : derivedPrivateKeyJwk as PrivateKeyJwk
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return derivedDescendantPrivateKey;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Derives a descendant public key from an ancestor private key.
|
|
44
|
-
* Uses X25519 keys for encryption key derivation.
|
|
45
|
-
*/
|
|
46
|
-
public static async derivePublicKey(ancestorKey: DerivedPrivateJwk, subDerivationPath: string[]): Promise<PublicKeyJwk> {
|
|
47
|
-
const derivedDescendantPrivateKey = await HdKey.derivePrivateKey(ancestorKey, subDerivationPath);
|
|
48
|
-
const derivedDescendantPublicKey = await X25519.getPublicKey({ key: derivedDescendantPrivateKey.derivedPrivateKey });
|
|
49
|
-
|
|
50
|
-
return derivedDescendantPublicKey as PublicKeyJwk;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
22
|
/**
|
|
54
23
|
* Derives a hardened hierarchical deterministic private key.
|
|
55
24
|
*/
|
package/src/utils/jws.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { GeneralJws } from '../types/jws-types.js';
|
|
2
1
|
import type { MessageSigner } from '../types/signer.js';
|
|
3
|
-
import type { SignatureEntry } from '../types/jws-types.js';
|
|
2
|
+
import type { GeneralJws, SignatureEntry } from '../types/jws-types.js';
|
|
4
3
|
import type { KeyMaterial, PublicKeyJwk } from '../types/jose-types.js';
|
|
5
4
|
|
|
6
5
|
import { Encoder } from './encoder.js';
|
package/src/utils/protocols.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { DerivedPrivateJwk } from '../utils/hd-key.js';
|
|
2
1
|
import type { EncryptionKeyDeriver } from '../types/encryption-types.js';
|
|
3
|
-
import type { PrivateKeyJwk, PublicKeyJwk } from '../types/jose-types.js';
|
|
4
2
|
import type { ProtocolDefinition, ProtocolRuleSet } from '../types/protocols-types.js';
|
|
5
3
|
|
|
6
|
-
import {
|
|
7
|
-
import { HdKey, KeyDerivationScheme } from '../utils/hd-key.js';
|
|
4
|
+
import { KeyDerivationScheme } from '../utils/hd-key.js';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Result of parsing a cross-protocol reference in `alias:path` format.
|
|
@@ -116,104 +113,44 @@ export class Protocols {
|
|
|
116
113
|
* because their records belong to the referenced protocol, whose own encryption keys govern them.
|
|
117
114
|
* Children of `$ref` nodes are still processed because they belong to the composing protocol.
|
|
118
115
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
116
|
+
* Accepts an EncryptionKeyDeriver that performs key derivation internally.
|
|
117
|
+
* The private key never leaves the caller's boundary.
|
|
121
118
|
*/
|
|
122
119
|
public static async deriveAndInjectPublicEncryptionKeys(
|
|
123
120
|
protocolDefinition: ProtocolDefinition,
|
|
124
121
|
keyDeriver: EncryptionKeyDeriver,
|
|
125
|
-
): Promise<ProtocolDefinition>;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Overload 2 (raw-key): Takes rootKeyId and raw PrivateKeyJwk directly.
|
|
129
|
-
*/
|
|
130
|
-
public static async deriveAndInjectPublicEncryptionKeys(
|
|
131
|
-
protocolDefinition: ProtocolDefinition,
|
|
132
|
-
rootKeyId: string,
|
|
133
|
-
privateJwk: PrivateKeyJwk,
|
|
134
|
-
): Promise<ProtocolDefinition>;
|
|
135
|
-
|
|
136
|
-
// Implementation dispatches based on argument type.
|
|
137
|
-
public static async deriveAndInjectPublicEncryptionKeys(
|
|
138
|
-
protocolDefinition: ProtocolDefinition,
|
|
139
|
-
rootKeyIdOrKeyDeriver: string | EncryptionKeyDeriver,
|
|
140
|
-
privateJwk?: PrivateKeyJwk,
|
|
141
122
|
): Promise<ProtocolDefinition> {
|
|
142
123
|
// clone before modify
|
|
143
124
|
const clone = JSON.parse(JSON.stringify(protocolDefinition)) as ProtocolDefinition;
|
|
144
125
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
clone.$keyAgreement = {
|
|
150
|
-
publicKeyJwk: await keyDeriver.derivePublicKey(basePath),
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
async function injectKeysViaCallback(
|
|
154
|
-
ruleSet: ProtocolRuleSet, parentPath: string[],
|
|
155
|
-
): Promise<void> {
|
|
156
|
-
for (const key in ruleSet) {
|
|
157
|
-
if (!key.startsWith('$')) {
|
|
158
|
-
const currentPath = [...parentPath, key];
|
|
159
|
-
const childRuleSet = ruleSet[key] as ProtocolRuleSet;
|
|
160
|
-
|
|
161
|
-
// Skip $ref nodes — they are governed by the referenced protocol's encryption keys.
|
|
162
|
-
// Still recurse into children, which belong to the composing protocol.
|
|
163
|
-
if (childRuleSet.$ref !== undefined) {
|
|
164
|
-
await injectKeysViaCallback(childRuleSet, currentPath);
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const publicKeyJwk = await keyDeriver.derivePublicKey(currentPath);
|
|
169
|
-
childRuleSet.$keyAgreement = { publicKeyJwk };
|
|
170
|
-
await injectKeysViaCallback(childRuleSet, currentPath);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
await injectKeysViaCallback(clone.structure as ProtocolRuleSet, basePath);
|
|
176
|
-
return clone;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Raw-key path
|
|
180
|
-
const rootKeyId = rootKeyIdOrKeyDeriver;
|
|
126
|
+
const basePath = [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol];
|
|
127
|
+
clone.$keyAgreement = {
|
|
128
|
+
publicKeyJwk: await keyDeriver.derivePublicKey(basePath),
|
|
129
|
+
};
|
|
181
130
|
|
|
182
|
-
|
|
183
|
-
|
|
131
|
+
async function injectKeys(
|
|
132
|
+
ruleSet: ProtocolRuleSet, parentPath: string[],
|
|
133
|
+
): Promise<void> {
|
|
184
134
|
for (const key in ruleSet) {
|
|
185
|
-
// if we encounter a nested rule set (a property name that doesn't begin with '$'), recursively inject the `$keyAgreement` property
|
|
186
135
|
if (!key.startsWith('$')) {
|
|
187
|
-
const
|
|
136
|
+
const currentPath = [...parentPath, key];
|
|
188
137
|
const childRuleSet = ruleSet[key] as ProtocolRuleSet;
|
|
189
138
|
|
|
190
139
|
// Skip $ref nodes — they are governed by the referenced protocol's encryption keys.
|
|
191
140
|
// Still recurse into children, which belong to the composing protocol.
|
|
192
141
|
if (childRuleSet.$ref !== undefined) {
|
|
193
|
-
await
|
|
142
|
+
await injectKeys(childRuleSet, currentPath);
|
|
194
143
|
continue;
|
|
195
144
|
}
|
|
196
145
|
|
|
197
|
-
const publicKeyJwk = await
|
|
198
|
-
|
|
146
|
+
const publicKeyJwk = await keyDeriver.derivePublicKey(currentPath);
|
|
199
147
|
childRuleSet.$keyAgreement = { publicKeyJwk };
|
|
200
|
-
await
|
|
148
|
+
await injectKeys(childRuleSet, currentPath);
|
|
201
149
|
}
|
|
202
150
|
}
|
|
203
151
|
}
|
|
204
152
|
|
|
205
|
-
|
|
206
|
-
const rootKey: DerivedPrivateJwk = {
|
|
207
|
-
derivationScheme : KeyDerivationScheme.ProtocolPath,
|
|
208
|
-
derivedPrivateKey : privateJwk!,
|
|
209
|
-
rootKeyId
|
|
210
|
-
};
|
|
211
|
-
const protocolLevelDerivedKey = await HdKey.derivePrivateKey(rootKey, [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol]);
|
|
212
|
-
clone.$keyAgreement = {
|
|
213
|
-
publicKeyJwk: await X25519.getPublicKey({ key: protocolLevelDerivedKey.derivedPrivateKey }) as PublicKeyJwk,
|
|
214
|
-
};
|
|
215
|
-
await addEncryptionProperty(clone.structure as ProtocolRuleSet, protocolLevelDerivedKey);
|
|
216
|
-
|
|
153
|
+
await injectKeys(clone.structure as ProtocolRuleSet, basePath);
|
|
217
154
|
return clone;
|
|
218
155
|
}
|
|
219
156
|
}
|
package/src/utils/records.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { DerivedPrivateJwk } from './hd-key.js';
|
|
2
|
-
import type { Jwk } from '@enbox/crypto';
|
|
3
2
|
import type { KeyDecrypter } from '../types/encryption-types.js';
|
|
4
|
-
import type { PublicKeyJwk } from '../types/jose-types.js';
|
|
5
3
|
import type { X25519KeyEncryption } from './encryption.js';
|
|
6
4
|
import type { Filter, KeyValues, StartsWithFilter } from '../types/query-types.js';
|
|
7
5
|
import type { GenericMessage, GenericSignaturePayload, MessageSort } from '../types/message-types.js';
|
|
@@ -63,31 +61,12 @@ export class Records {
|
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
63
|
* Decrypts the encrypted data in a message reply.
|
|
66
|
-
*
|
|
67
|
-
* Overload 1 (callback-based): Accepts a KeyDecrypter that performs
|
|
68
|
-
* X25519-HKDF key agreement + AES Key Unwrap internally.
|
|
64
|
+
* Accepts a KeyDecrypter that performs X25519-HKDF key agreement + AES Key Unwrap internally.
|
|
69
65
|
*/
|
|
70
66
|
public static async decrypt(
|
|
71
67
|
recordsWrite: RecordsWriteMessage,
|
|
72
68
|
keyDecrypter: KeyDecrypter,
|
|
73
69
|
cipherStream: ReadableStream<Uint8Array>,
|
|
74
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Overload 2 (raw-key): Takes DerivedPrivateJwk directly.
|
|
78
|
-
* @param ancestorPrivateKey Any ancestor private key in the key derivation path.
|
|
79
|
-
*/
|
|
80
|
-
public static async decrypt(
|
|
81
|
-
recordsWrite: RecordsWriteMessage,
|
|
82
|
-
ancestorPrivateKey: DerivedPrivateJwk,
|
|
83
|
-
cipherStream: ReadableStream<Uint8Array>,
|
|
84
|
-
): Promise<ReadableStream<Uint8Array>>;
|
|
85
|
-
|
|
86
|
-
// Implementation dispatches based on argument type.
|
|
87
|
-
public static async decrypt(
|
|
88
|
-
recordsWrite: RecordsWriteMessage,
|
|
89
|
-
keyOrDecrypter: DerivedPrivateJwk | KeyDecrypter,
|
|
90
|
-
cipherStream: ReadableStream<Uint8Array>,
|
|
91
70
|
): Promise<ReadableStream<Uint8Array>> {
|
|
92
71
|
const { encryption } = recordsWrite;
|
|
93
72
|
if (encryption === undefined) {
|
|
@@ -101,27 +80,21 @@ export class Records {
|
|
|
101
80
|
const actualDataCid = await Cid.computeDagPbCidFromBytes(ciphertext);
|
|
102
81
|
Records.validateEncryptedDataIntegrity(recordsWrite, actualDataCid, ciphertext.byteLength);
|
|
103
82
|
|
|
104
|
-
const { fullDerivationPath,
|
|
105
|
-
await Records.findMatchingKeyEncryption(recordsWrite,
|
|
83
|
+
const { fullDerivationPath, matchingKeyEncryption } =
|
|
84
|
+
await Records.findMatchingKeyEncryption(recordsWrite, keyDecrypter);
|
|
106
85
|
|
|
107
86
|
if (matchingKeyEncryption === undefined) {
|
|
108
87
|
throw new DwnError(
|
|
109
88
|
DwnErrorCode.RecordsDecryptNoMatchingKeyEncryptedFound,
|
|
110
|
-
`Unable to find a matching key encryption entry for '${
|
|
89
|
+
`Unable to find a matching key encryption entry for '${keyDecrypter.rootKeyId}' and '${keyDecrypter.derivationScheme}'.`
|
|
111
90
|
);
|
|
112
91
|
}
|
|
113
92
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
ephemeralPublicKey : matchingKeyEncryption.ephemeralPublicKey,
|
|
120
|
-
keyEncryption : matchingKeyEncryption,
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
cek = await Encryption.unwrapKey(leafPrivateKey!, matchingKeyEncryption);
|
|
124
|
-
}
|
|
93
|
+
const cek = await keyDecrypter.decrypt(fullDerivationPath, {
|
|
94
|
+
encryptedKey : Encoder.base64UrlToBytes(matchingKeyEncryption.encryptedKey),
|
|
95
|
+
ephemeralPublicKey : matchingKeyEncryption.ephemeralPublicKey,
|
|
96
|
+
keyEncryption : matchingKeyEncryption,
|
|
97
|
+
});
|
|
125
98
|
|
|
126
99
|
const iv = Encoder.base64UrlToBytes(encryption.initializationVector);
|
|
127
100
|
const plaintext = await Encryption.decrypt(encryption.algorithm, cek, iv, ciphertext);
|
|
@@ -132,33 +105,18 @@ export class Records {
|
|
|
132
105
|
|
|
133
106
|
private static async findMatchingKeyEncryption(
|
|
134
107
|
recordsWrite: RecordsWriteMessage,
|
|
135
|
-
|
|
136
|
-
): Promise<{ fullDerivationPath: string[];
|
|
108
|
+
keyDecrypter: KeyDecrypter,
|
|
109
|
+
): Promise<{ fullDerivationPath: string[]; matchingKeyEncryption?: X25519KeyEncryption }> {
|
|
137
110
|
const { encryption } = recordsWrite;
|
|
138
|
-
const fullDerivationPath = Records.constructKeyDerivationPath(
|
|
139
|
-
|
|
140
|
-
if ('decrypt' in keyOrDecrypter) {
|
|
141
|
-
const publicKey = await keyOrDecrypter.derivePublicKey(fullDerivationPath);
|
|
142
|
-
const keyId = await Encryption.getKeyId(publicKey);
|
|
143
|
-
return {
|
|
144
|
-
fullDerivationPath,
|
|
145
|
-
matchingKeyEncryption: encryption!.keyEncryption.find((entry): boolean =>
|
|
146
|
-
entry.derivationScheme === keyOrDecrypter.derivationScheme && entry.keyId === keyId
|
|
147
|
-
),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const leafPrivateKeyBytes = await Records.derivePrivateKey(keyOrDecrypter, fullDerivationPath);
|
|
152
|
-
const leafPrivateKey = await X25519.bytesToPrivateKey({ privateKeyBytes: leafPrivateKeyBytes });
|
|
111
|
+
const fullDerivationPath = Records.constructKeyDerivationPath(keyDecrypter.derivationScheme, recordsWrite);
|
|
153
112
|
|
|
154
|
-
const publicKey = await
|
|
155
|
-
const keyId =
|
|
113
|
+
const publicKey = await keyDecrypter.derivePublicKey(fullDerivationPath);
|
|
114
|
+
const keyId = await Encryption.getKeyId(publicKey);
|
|
156
115
|
|
|
157
116
|
return {
|
|
158
117
|
fullDerivationPath,
|
|
159
|
-
leafPrivateKey,
|
|
160
118
|
matchingKeyEncryption: encryption!.keyEncryption.find((entry): boolean =>
|
|
161
|
-
entry.derivationScheme ===
|
|
119
|
+
entry.derivationScheme === keyDecrypter.derivationScheme && entry.keyId === keyId
|
|
162
120
|
),
|
|
163
121
|
};
|
|
164
122
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { validateJsonSchema } from '../../../../src/schema-validator.js';
|
|
2
|
-
import { describe, expect, it } from 'bun:test';
|
|
3
|
-
const delivery = {
|
|
4
|
-
contextId: 'thread-1',
|
|
5
|
-
keyId: 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
|
|
6
|
-
keyMaterial: {
|
|
7
|
-
algorithm: 'X25519-HKDF-SHA256+A256KW',
|
|
8
|
-
derivationScheme: 'roleAudience',
|
|
9
|
-
keyId: 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
|
|
10
|
-
privateKeyJwk: {
|
|
11
|
-
crv: 'X25519',
|
|
12
|
-
d: 'private-key',
|
|
13
|
-
kty: 'OKP',
|
|
14
|
-
x: 'public-key',
|
|
15
|
-
},
|
|
16
|
-
publicKeyJwk: {
|
|
17
|
-
crv: 'X25519',
|
|
18
|
-
kty: 'OKP',
|
|
19
|
-
x: 'public-key',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
protocol: 'https://example.com/protocol',
|
|
23
|
-
rolePath: 'thread/participant',
|
|
24
|
-
};
|
|
25
|
-
describe('Delivery Schema', () => {
|
|
26
|
-
it('should accept a roleAudience key delivery payload', () => {
|
|
27
|
-
expect(() => validateJsonSchema('Delivery', delivery)).not.toThrow();
|
|
28
|
-
});
|
|
29
|
-
it('should reject legacy epoch fields', () => {
|
|
30
|
-
const invalidDelivery = {
|
|
31
|
-
...structuredClone(delivery),
|
|
32
|
-
epoch: 1,
|
|
33
|
-
};
|
|
34
|
-
expect(() => validateJsonSchema('Delivery', invalidDelivery)).toThrow();
|
|
35
|
-
});
|
|
36
|
-
it('should reject non-roleAudience key material', () => {
|
|
37
|
-
const invalidDelivery = structuredClone(delivery);
|
|
38
|
-
invalidDelivery.keyMaterial.derivationScheme = 'protocolPath';
|
|
39
|
-
expect(() => validateJsonSchema('Delivery', invalidDelivery)).toThrow();
|
|
40
|
-
});
|
|
41
|
-
it('should reject key IDs that are not base64url thumbprints', () => {
|
|
42
|
-
const invalidDelivery = structuredClone(delivery);
|
|
43
|
-
invalidDelivery.keyMaterial.keyId = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEF!';
|
|
44
|
-
expect(() => validateJsonSchema('Delivery', invalidDelivery)).toThrow();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
//# sourceMappingURL=delivery.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery.spec.js","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/delivery.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,QAAQ,GAAG;IACf,SAAS,EAAK,UAAU;IACxB,KAAK,EAAS,6CAA6C;IAC3D,WAAW,EAAG;QACZ,SAAS,EAAU,2BAA2B;QAC9C,gBAAgB,EAAG,cAAc;QACjC,KAAK,EAAc,6CAA6C;QAChE,aAAa,EAAM;YACjB,GAAG,EAAG,QAAQ;YACd,CA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UAAU,EAAE,eAAe,CAAC,CACtD,CAAC,OAAO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { validateJsonSchema } from '../../../../src/schema-validator.js';
|
|
2
|
-
import { describe, expect, it } from 'bun:test';
|
|
3
|
-
const grantKey = {
|
|
4
|
-
grantId: 'grant-id',
|
|
5
|
-
keyMaterial: {
|
|
6
|
-
algorithm: 'X25519-HKDF-SHA256+A256KW',
|
|
7
|
-
derivationPath: ['protocolPath', 'https://example.com/protocol', 'message'],
|
|
8
|
-
derivationScheme: 'protocolPath',
|
|
9
|
-
keyId: 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG',
|
|
10
|
-
privateKeyJwk: {
|
|
11
|
-
crv: 'X25519',
|
|
12
|
-
d: 'private-key',
|
|
13
|
-
kty: 'OKP',
|
|
14
|
-
x: 'public-key',
|
|
15
|
-
},
|
|
16
|
-
publicKeyJwk: {
|
|
17
|
-
crv: 'X25519',
|
|
18
|
-
kty: 'OKP',
|
|
19
|
-
x: 'public-key',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
scope: {
|
|
23
|
-
protocol: 'https://example.com/protocol',
|
|
24
|
-
protocolPath: 'message',
|
|
25
|
-
scheme: 'protocolPath',
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
describe('GrantKey Schema', () => {
|
|
29
|
-
it('should accept protocolPath derivation paths', () => {
|
|
30
|
-
expect(() => validateJsonSchema('GrantKey', grantKey)).not.toThrow();
|
|
31
|
-
});
|
|
32
|
-
it('should reject derivation paths that do not start with protocolPath', () => {
|
|
33
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
34
|
-
invalidGrantKey.keyMaterial.derivationPath[0] = 'unsupported';
|
|
35
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
36
|
-
});
|
|
37
|
-
it('should reject empty derivation path segments', () => {
|
|
38
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
39
|
-
invalidGrantKey.keyMaterial.derivationPath[2] = '';
|
|
40
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
41
|
-
});
|
|
42
|
-
it('should reject derivation paths with too many segments', () => {
|
|
43
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
44
|
-
invalidGrantKey.keyMaterial.derivationPath = [
|
|
45
|
-
'protocolPath',
|
|
46
|
-
'https://example.com/protocol',
|
|
47
|
-
'a',
|
|
48
|
-
'b',
|
|
49
|
-
'c',
|
|
50
|
-
'd',
|
|
51
|
-
'e',
|
|
52
|
-
'f',
|
|
53
|
-
'g',
|
|
54
|
-
'h',
|
|
55
|
-
'i',
|
|
56
|
-
'j',
|
|
57
|
-
'k',
|
|
58
|
-
];
|
|
59
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
60
|
-
});
|
|
61
|
-
it('should reject key IDs that are not base64url thumbprints', () => {
|
|
62
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
63
|
-
invalidGrantKey.keyMaterial.keyId = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEF!';
|
|
64
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
65
|
-
});
|
|
66
|
-
it('should reject unsupported key material algorithms', () => {
|
|
67
|
-
const invalidGrantKey = structuredClone(grantKey);
|
|
68
|
-
invalidGrantKey.keyMaterial.algorithm = 'unsupported';
|
|
69
|
-
expect(() => validateJsonSchema('GrantKey', invalidGrantKey)).toThrow();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
//# sourceMappingURL=grant-key.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grant-key.spec.js","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/grant-key.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,C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,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery.spec.d.ts","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/delivery.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grant-key.spec.d.ts","sourceRoot":"","sources":["../../../../../../tests/validation/json-schemas/encryption/grant-key.spec.ts"],"names":[],"mappings":""}
|