@enbox/dwn-sdk-js 0.4.4 → 0.4.5
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 +15 -15
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +5316 -2425
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/json-schemas/definitions.json +18 -0
- package/dist/esm/src/core/constants.js +3 -3
- package/dist/esm/src/core/constants.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +29 -1
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +20 -0
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-validation.js +80 -3
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
- package/dist/esm/src/core/recording-validation-state-reader.js +5 -0
- package/dist/esm/src/core/recording-validation-state-reader.js.map +1 -1
- package/dist/esm/src/core/replication-apply.js +163 -7
- package/dist/esm/src/core/replication-apply.js.map +1 -1
- package/dist/esm/src/core/validation-state-reader.js +20 -0
- package/dist/esm/src/core/validation-state-reader.js.map +1 -1
- package/dist/esm/src/dwn.js +19 -2
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/handlers/messages-query.js +3 -5
- package/dist/esm/src/handlers/messages-query.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +10 -4
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +1 -1
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +2 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +23 -10
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-signing.js +2 -8
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -1
- package/dist/esm/src/interfaces/records-write.js +43 -65
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/protocols/encryption.js +411 -0
- package/dist/esm/src/protocols/encryption.js.map +1 -0
- package/dist/esm/src/protocols/permission-grant.js +0 -5
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/types/message-types.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +135 -187
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +0 -1
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/permission-scope.js +9 -6
- package/dist/esm/src/utils/permission-scope.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +12 -9
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +54 -56
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/replication.js +27 -4
- package/dist/esm/src/utils/replication.js.map +1 -1
- package/dist/esm/tests/core/replication-apply.spec.js +141 -1
- package/dist/esm/tests/core/replication-apply.spec.js.map +1 -1
- package/dist/esm/tests/core/replication-replay-property.spec.js +1 -0
- package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-read-closure.spec.js +111 -0
- package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -1
- package/dist/esm/tests/core/validation-state-reader.spec.js +89 -0
- package/dist/esm/tests/core/validation-state-reader.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +30 -31
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/fuzz/encryption.fuzz.spec.js +29 -121
- package/dist/esm/tests/fuzz/encryption.fuzz.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-query.spec.js +71 -3
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +2 -2
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +9 -135
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +279 -19
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +17 -22
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +170 -150
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/protocols/encryption.spec.js +914 -0
- package/dist/esm/tests/protocols/encryption.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +100 -100
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +20 -2
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +88 -125
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +125 -255
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/permission-scope.spec.js +5 -1
- package/dist/esm/tests/utils/permission-scope.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +15 -5
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +7 -44
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js +63 -0
- package/dist/esm/tests/validation/json-schemas/encryption/grant-key.spec.js.map +1 -0
- package/dist/types/generated/precompiled-validators.d.ts +140 -92
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +2 -2
- package/dist/types/src/core/constants.d.ts.map +1 -1
- package/dist/types/src/core/core-protocol.d.ts +1 -1
- package/dist/types/src/core/core-protocol.d.ts.map +1 -1
- package/dist/types/src/core/dwn-error.d.ts +29 -1
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/messages-grant-authorization.d.ts +2 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-validation.d.ts +2 -2
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
- package/dist/types/src/core/recording-validation-state-reader.d.ts +9 -0
- package/dist/types/src/core/recording-validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/core/replication-apply.d.ts +4 -3
- package/dist/types/src/core/replication-apply.d.ts.map +1 -1
- package/dist/types/src/core/validation-state-reader.d.ts +9 -0
- package/dist/types/src/core/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +1 -0
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +6 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-signing.d.ts +4 -8
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write.d.ts +10 -26
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/encryption.d.ts +43 -0
- package/dist/types/src/protocols/encryption.d.ts.map +1 -0
- package/dist/types/src/protocols/permission-grant.d.ts +0 -7
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/types/encryption-types.d.ts +5 -38
- package/dist/types/src/types/encryption-types.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +0 -13
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +0 -9
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +9 -14
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +3 -3
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/validation-state-reader.d.ts +12 -0
- package/dist/types/src/types/validation-state-reader.d.ts.map +1 -1
- package/dist/types/src/utils/encryption.d.ts +54 -145
- package/dist/types/src/utils/encryption.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -1
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/permission-scope.d.ts +4 -3
- package/dist/types/src/utils/permission-scope.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +3 -5
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +5 -13
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/src/utils/replication.d.ts +3 -0
- package/dist/types/src/utils/replication.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/protocols/encryption.spec.d.ts +2 -0
- package/dist/types/tests/protocols/encryption.spec.d.ts.map +1 -0
- 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 +0 -5
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/dist/types/tests/validation/json-schemas/encryption/grant-key.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/encryption/grant-key.spec.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/core/constants.ts +3 -3
- package/src/core/core-protocol.ts +1 -1
- package/src/core/dwn-error.ts +29 -1
- package/src/core/messages-grant-authorization.ts +27 -0
- package/src/core/protocol-authorization-validation.ts +145 -6
- package/src/core/recording-validation-state-reader.ts +13 -0
- package/src/core/replication-apply.ts +222 -8
- package/src/core/validation-state-reader.ts +30 -0
- package/src/dwn.ts +24 -2
- package/src/handlers/messages-query.ts +6 -5
- package/src/handlers/protocols-configure.ts +19 -3
- package/src/handlers/records-write.ts +1 -1
- package/src/index.ts +15 -5
- package/src/interfaces/protocols-configure.ts +39 -12
- package/src/interfaces/records-write-signing.ts +5 -12
- package/src/interfaces/records-write.ts +75 -92
- package/src/protocols/encryption.ts +649 -0
- package/src/protocols/permission-grant.ts +0 -6
- package/src/types/encryption-types.ts +9 -38
- package/src/types/message-types.ts +0 -13
- package/src/types/permission-types.ts +0 -10
- package/src/types/protocols-types.ts +9 -16
- package/src/types/records-types.ts +3 -3
- package/src/types/validation-state-reader.ts +13 -0
- package/src/utils/encryption.ts +213 -283
- package/src/utils/hd-key.ts +1 -1
- package/src/utils/permission-scope.ts +10 -6
- package/src/utils/protocols.ts +16 -15
- package/src/utils/records.ts +86 -71
- package/src/utils/replication.ts +30 -4
- package/dist/esm/tests/vectors/protocol-definitions/chat.json +0 -70
|
@@ -1,225 +1,165 @@
|
|
|
1
1
|
import { concatBytes } from '@noble/ciphers/utils';
|
|
2
|
+
import { AesCtr, AesKw, computeJwkThumbprint, Hkdf, X25519 } from '@enbox/crypto';
|
|
2
3
|
import { Encoder } from './encoder.js';
|
|
3
4
|
import { KeyDerivationScheme } from './hd-key.js';
|
|
4
|
-
import {
|
|
5
|
-
/**
|
|
6
|
-
* Content encryption algorithms supported by the DWN.
|
|
7
|
-
* Both are AEAD (Authenticated Encryption with Associated Data) ciphers.
|
|
8
|
-
*/
|
|
5
|
+
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
9
6
|
export var ContentEncryptionAlgorithm;
|
|
10
7
|
(function (ContentEncryptionAlgorithm) {
|
|
11
|
-
|
|
12
|
-
ContentEncryptionAlgorithm["A256GCM"] = "A256GCM";
|
|
13
|
-
/** XChaCha20-Poly1305. 192-bit nonce (safe to randomize). Constant-time. */
|
|
14
|
-
ContentEncryptionAlgorithm["XC20P"] = "XC20P";
|
|
8
|
+
ContentEncryptionAlgorithm["A256CTR"] = "A256CTR";
|
|
15
9
|
})(ContentEncryptionAlgorithm || (ContentEncryptionAlgorithm = {}));
|
|
16
|
-
/**
|
|
17
|
-
* Key agreement algorithm used by the DWN.
|
|
18
|
-
* ECDH-ES with X25519 key agreement and AES-256 Key Wrap.
|
|
19
|
-
*/
|
|
20
10
|
export var KeyAgreementAlgorithm;
|
|
21
11
|
(function (KeyAgreementAlgorithm) {
|
|
22
|
-
KeyAgreementAlgorithm["
|
|
12
|
+
KeyAgreementAlgorithm["X25519HkdfSha256A256Kw"] = "X25519-HKDF-SHA256+A256KW";
|
|
23
13
|
})(KeyAgreementAlgorithm || (KeyAgreementAlgorithm = {}));
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
* Utility class for DWN encryption operations using JWE (RFC 7516).
|
|
30
|
-
* Uses ECDH-ES+A256KW key agreement with X25519 and either AES-256-GCM or XChaCha20-Poly1305
|
|
31
|
-
* for authenticated content encryption.
|
|
32
|
-
*/
|
|
14
|
+
export const ROLE_AUDIENCE_DERIVATION_SCHEME = 'roleAudience';
|
|
15
|
+
const AES_256_KEY_LENGTH_BYTES = 32;
|
|
16
|
+
const AES_CTR_COUNTER_LENGTH_BYTES = 16;
|
|
17
|
+
const AES_CTR_COUNTER_LENGTH_BITS = 128;
|
|
18
|
+
const KEK_INFO_PREFIX = KeyAgreementAlgorithm.X25519HkdfSha256A256Kw;
|
|
33
19
|
export class Encryption {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const combined = await AesGcm.encrypt({ data: plaintext, iv, key: keyJwk });
|
|
43
|
-
const ciphertext = combined.slice(0, combined.length - AES_GCM_TAG_LENGTH_BYTES);
|
|
44
|
-
const tag = combined.slice(combined.length - AES_GCM_TAG_LENGTH_BYTES);
|
|
45
|
-
return { ciphertext, tag };
|
|
46
|
-
}
|
|
47
|
-
else if (algorithm === ContentEncryptionAlgorithm.XC20P) {
|
|
48
|
-
// @noble/ciphers XChaCha20-Poly1305 returns ciphertext || tag
|
|
49
|
-
const combined = await XChaCha20Poly1305.encryptRaw({ data: plaintext, keyBytes, nonce: iv });
|
|
50
|
-
const ciphertext = combined.slice(0, combined.length - POLY1305_TAG_LENGTH_BYTES);
|
|
51
|
-
const tag = combined.slice(combined.length - POLY1305_TAG_LENGTH_BYTES);
|
|
52
|
-
return { ciphertext, tag };
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw new Error(`Unsupported content encryption algorithm: ${algorithm}`);
|
|
56
|
-
}
|
|
20
|
+
static async encrypt(algorithm, keyBytes, initializationVector, plaintext) {
|
|
21
|
+
Encryption.validateContentEncryptionParameters(algorithm, keyBytes, initializationVector);
|
|
22
|
+
return AesCtr.encrypt({
|
|
23
|
+
counter: initializationVector,
|
|
24
|
+
data: plaintext,
|
|
25
|
+
key: Encryption.toA256CtrJwk(keyBytes),
|
|
26
|
+
length: AES_CTR_COUNTER_LENGTH_BITS,
|
|
27
|
+
});
|
|
57
28
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const keyJwk = { kty: 'oct', k: Encoder.bytesToBase64Url(keyBytes), alg: 'A256GCM' };
|
|
67
|
-
return AesGcm.decrypt({ data: combined, iv, key: keyJwk });
|
|
68
|
-
}
|
|
69
|
-
else if (algorithm === ContentEncryptionAlgorithm.XC20P) {
|
|
70
|
-
return XChaCha20Poly1305.decryptRaw({ data: combined, keyBytes, nonce: iv });
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
throw new Error(`Unsupported content encryption algorithm: ${algorithm}`);
|
|
74
|
-
}
|
|
29
|
+
static async decrypt(algorithm, keyBytes, initializationVector, ciphertext) {
|
|
30
|
+
Encryption.validateContentEncryptionParameters(algorithm, keyBytes, initializationVector);
|
|
31
|
+
return AesCtr.decrypt({
|
|
32
|
+
counter: initializationVector,
|
|
33
|
+
data: ciphertext,
|
|
34
|
+
key: Encryption.toA256CtrJwk(keyBytes),
|
|
35
|
+
length: AES_CTR_COUNTER_LENGTH_BITS,
|
|
36
|
+
});
|
|
75
37
|
}
|
|
76
|
-
|
|
77
|
-
* Encrypts data as a ReadableStream using an AEAD cipher.
|
|
78
|
-
* Collects all chunks, encrypts, and returns a new stream of ciphertext || tag.
|
|
79
|
-
* The iv and tag are NOT embedded in the stream — they are stored in the JWE structure.
|
|
80
|
-
*/
|
|
81
|
-
static async aeadEncryptStream(algorithm, keyBytes, iv, plaintextStream) {
|
|
38
|
+
static async encryptStream(algorithm, keyBytes, initializationVector, plaintextStream) {
|
|
82
39
|
const plaintext = await Encryption.readStream(plaintextStream);
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
start(controller) {
|
|
86
|
-
controller.enqueue(ciphertext);
|
|
87
|
-
controller.close();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
return { ciphertextStream, tag };
|
|
40
|
+
const ciphertext = await Encryption.encrypt(algorithm, keyBytes, initializationVector, plaintext);
|
|
41
|
+
return Encryption.toStream(ciphertext);
|
|
91
42
|
}
|
|
92
|
-
|
|
93
|
-
* Decrypts a ciphertext stream using an AEAD cipher.
|
|
94
|
-
* Returns a ReadableStream of plaintext.
|
|
95
|
-
*/
|
|
96
|
-
static async aeadDecryptStream(algorithm, keyBytes, iv, ciphertextStream, tag) {
|
|
43
|
+
static async decryptStream(algorithm, keyBytes, initializationVector, ciphertextStream) {
|
|
97
44
|
const ciphertext = await Encryption.readStream(ciphertextStream);
|
|
98
|
-
const plaintext = await Encryption.
|
|
99
|
-
return
|
|
100
|
-
start(controller) {
|
|
101
|
-
controller.enqueue(plaintext);
|
|
102
|
-
controller.close();
|
|
103
|
-
}
|
|
104
|
-
});
|
|
45
|
+
const plaintext = await Encryption.decrypt(algorithm, keyBytes, initializationVector, ciphertext);
|
|
46
|
+
return Encryption.toStream(plaintext);
|
|
105
47
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
* @param recipientPublicKey - Recipient's X25519 public key (JWK).
|
|
111
|
-
* @param cek - The Content Encryption Key to wrap.
|
|
112
|
-
* @returns The wrapped CEK bytes.
|
|
113
|
-
*/
|
|
114
|
-
static async ecdhEsWrapKey(ephemeralPrivateKey, recipientPublicKey, cek) {
|
|
115
|
-
// 1. ECDH shared secret
|
|
48
|
+
static async wrapKey(recipientPublicKey, cek, keyInput, ephemeralPrivateKey) {
|
|
49
|
+
Encryption.validateContentEncryptionKey(cek);
|
|
50
|
+
const privateKey = ephemeralPrivateKey ?? await X25519.generateKey();
|
|
51
|
+
const publicKey = await X25519.getPublicKey({ key: privateKey });
|
|
116
52
|
const sharedSecret = await X25519.sharedSecret({
|
|
117
|
-
privateKeyA:
|
|
53
|
+
privateKeyA: privateKey,
|
|
118
54
|
publicKeyB: recipientPublicKey,
|
|
119
55
|
});
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
partyVInfo: '',
|
|
128
|
-
suppPubInfo: 256,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
// 3. AES-256 Key Wrap
|
|
132
|
-
const cekJwk = { kty: 'oct', k: Encoder.bytesToBase64Url(cek), alg: 'A256GCM' };
|
|
133
|
-
const kekJwk = { kty: 'oct', k: Encoder.bytesToBase64Url(kek), alg: 'A256KW' };
|
|
134
|
-
const wrappedKey = await AesKw.wrapKey({ unwrappedKey: cekJwk, encryptionKey: kekJwk });
|
|
135
|
-
return wrappedKey;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Performs ECDH-ES key agreement with X25519 and unwraps the CEK using AES-256 Key Unwrap.
|
|
139
|
-
*
|
|
140
|
-
* @param recipientPrivateKey - Recipient's X25519 private key (JWK).
|
|
141
|
-
* @param ephemeralPublicKey - Ephemeral X25519 public key from the JWE recipient header (JWK).
|
|
142
|
-
* @param wrappedKey - The wrapped CEK bytes.
|
|
143
|
-
* @returns The unwrapped CEK bytes.
|
|
144
|
-
*/
|
|
145
|
-
static async ecdhEsUnwrapKey(recipientPrivateKey, ephemeralPublicKey, wrappedKey) {
|
|
146
|
-
// 1. ECDH shared secret
|
|
56
|
+
const kek = await Encryption.deriveKek(sharedSecret, keyInput);
|
|
57
|
+
const cekJwk = Encryption.toA256CtrJwk(cek);
|
|
58
|
+
const kekJwk = { alg: 'A256KW', k: Encoder.bytesToBase64Url(kek), kty: 'oct' };
|
|
59
|
+
const encryptedKey = await AesKw.wrapKey({ encryptionKey: kekJwk, unwrappedKey: cekJwk });
|
|
60
|
+
return { encryptedKey, ephemeralPublicKey: publicKey };
|
|
61
|
+
}
|
|
62
|
+
static async unwrapKey(recipientPrivateKey, keyEncryption) {
|
|
147
63
|
const sharedSecret = await X25519.sharedSecret({
|
|
148
64
|
privateKeyA: recipientPrivateKey,
|
|
149
|
-
publicKeyB: ephemeralPublicKey,
|
|
65
|
+
publicKeyB: keyEncryption.ephemeralPublicKey,
|
|
150
66
|
});
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
sharedSecret,
|
|
154
|
-
keyDataLen: 256,
|
|
155
|
-
fixedInfo: {
|
|
156
|
-
algorithmId: 'A256KW',
|
|
157
|
-
partyUInfo: '',
|
|
158
|
-
partyVInfo: '',
|
|
159
|
-
suppPubInfo: 256,
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
// 3. AES-256 Key Unwrap
|
|
163
|
-
const kekJwk = { kty: 'oct', k: Encoder.bytesToBase64Url(kek), alg: 'A256KW' };
|
|
67
|
+
const kek = await Encryption.deriveKek(sharedSecret, keyEncryption);
|
|
68
|
+
const kekJwk = { alg: 'A256KW', k: Encoder.bytesToBase64Url(kek), kty: 'oct' };
|
|
164
69
|
const unwrappedJwk = await AesKw.unwrapKey({
|
|
165
|
-
wrappedKeyBytes: wrappedKey,
|
|
166
|
-
wrappedKeyAlgorithm: 'A256GCM',
|
|
167
70
|
decryptionKey: kekJwk,
|
|
71
|
+
wrappedKeyAlgorithm: ContentEncryptionAlgorithm.A256CTR,
|
|
72
|
+
wrappedKeyBytes: Encoder.base64UrlToBytes(keyEncryption.encryptedKey),
|
|
168
73
|
});
|
|
169
74
|
return Encoder.base64UrlToBytes(unwrappedJwk.k);
|
|
170
75
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
*
|
|
176
|
-
* @param encryptionInput - Describes the CEK, IV, and recipient key encryption inputs.
|
|
177
|
-
* @param tag - The authentication tag produced by the AEAD cipher during data encryption.
|
|
178
|
-
*/
|
|
179
|
-
static async buildJwe(encryptionInput, tag) {
|
|
180
|
-
const enc = encryptionInput.algorithm ?? ContentEncryptionAlgorithm.A256GCM;
|
|
181
|
-
const protectedHeader = {
|
|
182
|
-
alg: KeyAgreementAlgorithm.EcdhEsA256kw,
|
|
183
|
-
enc,
|
|
184
|
-
};
|
|
185
|
-
const protectedHeaderBase64url = Encoder.stringToBase64Url(JSON.stringify(protectedHeader));
|
|
186
|
-
const recipients = [];
|
|
76
|
+
static async buildEncryptionProperty(encryptionInput) {
|
|
77
|
+
const algorithm = encryptionInput.algorithm ?? ContentEncryptionAlgorithm.A256CTR;
|
|
78
|
+
Encryption.validateContentEncryptionParameters(algorithm, encryptionInput.key, encryptionInput.initializationVector);
|
|
79
|
+
const keyEncryption = [];
|
|
187
80
|
for (const keyInput of encryptionInput.keyEncryptionInputs) {
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
kid: keyInput.publicKeyId,
|
|
195
|
-
epk: ephemeralPublicKey,
|
|
196
|
-
derivationScheme: keyInput.derivationScheme,
|
|
81
|
+
const { encryptedKey, ephemeralPublicKey } = await Encryption.wrapKey(keyInput.publicKey, encryptionInput.key, keyInput);
|
|
82
|
+
const common = {
|
|
83
|
+
algorithm: KeyAgreementAlgorithm.X25519HkdfSha256A256Kw,
|
|
84
|
+
encryptedKey: Encoder.bytesToBase64Url(encryptedKey),
|
|
85
|
+
ephemeralPublicKey,
|
|
86
|
+
keyId: keyInput.keyId,
|
|
197
87
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
88
|
+
if (keyInput.derivationScheme === KeyDerivationScheme.ProtocolPath) {
|
|
89
|
+
keyEncryption.push({
|
|
90
|
+
...common,
|
|
91
|
+
derivationScheme: KeyDerivationScheme.ProtocolPath,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
keyEncryption.push({
|
|
96
|
+
...common,
|
|
97
|
+
derivationScheme: ROLE_AUDIENCE_DERIVATION_SCHEME,
|
|
98
|
+
epoch: keyInput.epoch,
|
|
99
|
+
protocol: keyInput.protocol,
|
|
100
|
+
role: keyInput.role,
|
|
101
|
+
});
|
|
201
102
|
}
|
|
202
|
-
recipients.push({
|
|
203
|
-
header: recipientHeader,
|
|
204
|
-
encrypted_key: Encoder.bytesToBase64Url(wrappedKey),
|
|
205
|
-
});
|
|
206
103
|
}
|
|
207
104
|
return {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
recipients,
|
|
105
|
+
algorithm,
|
|
106
|
+
initializationVector: Encoder.bytesToBase64Url(encryptionInput.initializationVector),
|
|
107
|
+
keyEncryption,
|
|
212
108
|
};
|
|
213
109
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
static
|
|
218
|
-
|
|
110
|
+
static async getKeyId(publicKeyJwk) {
|
|
111
|
+
return computeJwkThumbprint({ jwk: publicKeyJwk });
|
|
112
|
+
}
|
|
113
|
+
static validateEncryptionProperty(encryption) {
|
|
114
|
+
const initializationVector = Encoder.base64UrlToBytes(encryption.initializationVector);
|
|
115
|
+
if (initializationVector.byteLength !== AES_CTR_COUNTER_LENGTH_BYTES) {
|
|
116
|
+
throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityEncryptionInitializationVectorInvalid, `A256CTR initializationVector must decode to ${AES_CTR_COUNTER_LENGTH_BYTES} bytes.`);
|
|
117
|
+
}
|
|
118
|
+
for (const entry of encryption.keyEncryption) {
|
|
119
|
+
if (entry.ephemeralPublicKey.kty !== 'OKP' || entry.ephemeralPublicKey.crv !== 'X25519') {
|
|
120
|
+
throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityEncryptionEphemeralPublicKeyInvalid, 'ephemeralPublicKey must be an OKP X25519 public key.');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
static async deriveKek(sharedSecret, keyEncryption) {
|
|
125
|
+
Encryption.validateSharedSecret(sharedSecret);
|
|
126
|
+
const info = Encryption.getKekInfo(keyEncryption);
|
|
127
|
+
return Hkdf.deriveKeyBytes({
|
|
128
|
+
baseKeyBytes: sharedSecret,
|
|
129
|
+
hash: 'SHA-256',
|
|
130
|
+
info,
|
|
131
|
+
length: 256,
|
|
132
|
+
salt: new Uint8Array(),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
static getKekInfo(keyEncryption) {
|
|
136
|
+
if (keyEncryption.derivationScheme === ROLE_AUDIENCE_DERIVATION_SCHEME) {
|
|
137
|
+
return `${KEK_INFO_PREFIX}|roleAudience|${keyEncryption.protocol}|${keyEncryption.role}|${keyEncryption.epoch}|${keyEncryption.keyId}`;
|
|
138
|
+
}
|
|
139
|
+
return `${KEK_INFO_PREFIX}|protocolPath|${keyEncryption.keyId}`;
|
|
140
|
+
}
|
|
141
|
+
static validateContentEncryptionParameters(algorithm, keyBytes, initializationVector) {
|
|
142
|
+
if (algorithm !== ContentEncryptionAlgorithm.A256CTR) {
|
|
143
|
+
throw new Error(`Unsupported content encryption algorithm: ${algorithm}`);
|
|
144
|
+
}
|
|
145
|
+
Encryption.validateContentEncryptionKey(keyBytes);
|
|
146
|
+
if (initializationVector.byteLength !== AES_CTR_COUNTER_LENGTH_BYTES) {
|
|
147
|
+
throw new Error(`A256CTR initializationVector must be ${AES_CTR_COUNTER_LENGTH_BYTES} bytes.`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
static validateContentEncryptionKey(keyBytes) {
|
|
151
|
+
if (keyBytes.byteLength !== AES_256_KEY_LENGTH_BYTES) {
|
|
152
|
+
throw new Error(`A256CTR content encryption key must be ${AES_256_KEY_LENGTH_BYTES} bytes.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
static validateSharedSecret(sharedSecret) {
|
|
156
|
+
if (sharedSecret.every((byte) => byte === 0)) {
|
|
157
|
+
throw new Error('X25519 shared secret MUST NOT be all zeros.');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
static toA256CtrJwk(keyBytes) {
|
|
161
|
+
return { alg: ContentEncryptionAlgorithm.A256CTR, k: Encoder.bytesToBase64Url(keyBytes), kty: 'oct' };
|
|
219
162
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Reads a ReadableStream to completion and returns all bytes concatenated.
|
|
222
|
-
*/
|
|
223
163
|
static async readStream(stream) {
|
|
224
164
|
const reader = stream.getReader();
|
|
225
165
|
const chunks = [];
|
|
@@ -232,5 +172,13 @@ export class Encryption {
|
|
|
232
172
|
}
|
|
233
173
|
return concatBytes(...chunks);
|
|
234
174
|
}
|
|
175
|
+
static toStream(data) {
|
|
176
|
+
return new ReadableStream({
|
|
177
|
+
start(controller) {
|
|
178
|
+
controller.enqueue(data);
|
|
179
|
+
controller.close();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
235
183
|
}
|
|
236
184
|
//# sourceMappingURL=encryption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../../../src/utils/encryption.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../../../src/utils/encryption.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAElF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,CAAN,IAAY,0BAEX;AAFD,WAAY,0BAA0B;IACpC,iDAAmB,CAAA;AACrB,CAAC,EAFW,0BAA0B,KAA1B,0BAA0B,QAErC;AAED,MAAM,CAAN,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,6EAAoD,CAAA;AACtD,CAAC,EAFW,qBAAqB,KAArB,qBAAqB,QAEhC;AAED,MAAM,CAAC,MAAM,+BAA+B,GAAG,cAAc,CAAC;AAE9D,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,eAAe,GAAG,qBAAqB,CAAC,sBAAsB,CAAC;AA2DrE,MAAM,OAAO,UAAU;IACd,MAAM,CAAC,KAAK,CAAC,OAAO,CACzB,SAAqC,EACrC,QAAoB,EACpB,oBAAgC,EAChC,SAAqB;QAErB,UAAU,CAAC,mCAAmC,CAAC,SAAS,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC;QAC1F,OAAO,MAAM,CAAC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;QAC1D,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC,IAAI,EAAW,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,QAAoB;QAC9C,OAAO,EAAE,GAAG,EAAE,0BAA0B,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;IACxG,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,MAAkC;QAChE,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAClC,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,SAAS,CAAC;YACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM;YACR,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,WAAW,CAAC,GAAG,MAAM,CAAC,CAAC;IAChC,CAAC;IAEO,MAAM,CAAC,QAAQ,CAAC,IAAgB;QACtC,OAAO,IAAI,cAAc,CAAa;YACpC,KAAK,CAAC,UAAU;gBACd,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACzB,UAAU,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -4,7 +4,6 @@ import { X25519 } from '@enbox/crypto';
|
|
|
4
4
|
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
|
|
5
5
|
export var KeyDerivationScheme;
|
|
6
6
|
(function (KeyDerivationScheme) {
|
|
7
|
-
KeyDerivationScheme["ProtocolContext"] = "protocolContext";
|
|
8
7
|
KeyDerivationScheme["ProtocolPath"] = "protocolPath";
|
|
9
8
|
})(KeyDerivationScheme || (KeyDerivationScheme = {}));
|
|
10
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hd-key.js","sourceRoot":"","sources":["../../../../src/utils/hd-key.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"hd-key.js","sourceRoot":"","sources":["../../../../src/utils/hd-key.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,CAAN,IAAY,mBAEX;AAFD,WAAY,mBAAmB;IAC7B,oDAA6B,CAAA;AAC/B,CAAC,EAFW,mBAAmB,KAAnB,mBAAmB,QAE9B;AAUD;;GAEG;AACH,MAAM,OAAO,KAAK;IAChB;;;OAGG;IACI,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,WAA8B,EAAE,iBAA2B;QAC9F,MAAM,kBAAkB,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACzG,MAAM,gCAAgC,GAAG,WAAW,CAAC,cAAc,IAAI,EAAE,CAAC;QAC1E,MAAM,sBAAsB,GAAG,MAAM,KAAK,CAAC,qBAAqB,CAAC,kBAAkB,EAAE,i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,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAKtC;QACC,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAAC;QAE7E,MAAM,SAAS,GAAG,kBAAkB,EAAkB,CAAC;QAEvD,mGAAmG;QACnG,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,kBAAkC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;QAEnI,6CAA6C;QAC7C,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,CACrD;YACE,IAAI,EAAG,MAAM;YACb,IAAI,EAAG,aAAa;YACpB,IAAI,EAAG,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,8CAA8C;YACxE,IAAI,EAAG,IAAoB;SAC5B,EACD,YAAY,EACZ,gBAAgB,GAAG,CAAC,CAAC,6BAA6B;SACnD,CAAC;QAEF,0CAA0C;QAC1C,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;QACzD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,yBAAyB,CAAC,YAAsB;QAC7D,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,CAAC,0BAA0B,EAAE,gCAAgC,YAAY,EAAE,CAAC,CAAC;QAC9G,CAAC;IACH,CAAC;CACF"}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Matching fails closed for invalid combinations: `protocolPath` and
|
|
5
5
|
* `contextId` are mutually exclusive, and either field requires `protocol`.
|
|
6
|
-
* `protocol`
|
|
7
|
-
* match
|
|
8
|
-
*
|
|
6
|
+
* `protocol` matches by exact equality. `protocolPath` and `contextId` scopes
|
|
7
|
+
* match subtrees: the target value must equal the scoped value or begin with the
|
|
8
|
+
* scoped value followed by `/`.
|
|
9
9
|
*/
|
|
10
10
|
export class PermissionScopeMatcher {
|
|
11
11
|
/**
|
|
@@ -22,7 +22,7 @@ export class PermissionScopeMatcher {
|
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
if (scope.protocolPath !== undefined) {
|
|
25
|
-
return scope.protocolPath
|
|
25
|
+
return PermissionScopeMatcher.matchesSubtree(scope.protocolPath, target.protocolPath);
|
|
26
26
|
}
|
|
27
27
|
if (scope.contextId !== undefined) {
|
|
28
28
|
return PermissionScopeMatcher.matchesContextId(scope.contextId, target.contextId);
|
|
@@ -30,8 +30,11 @@ export class PermissionScopeMatcher {
|
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
static matchesContextId(scopeContextId, candidateContextId) {
|
|
33
|
-
return
|
|
34
|
-
|
|
33
|
+
return PermissionScopeMatcher.matchesSubtree(scopeContextId, candidateContextId);
|
|
34
|
+
}
|
|
35
|
+
static matchesSubtree(scopeValue, candidateValue) {
|
|
36
|
+
return typeof candidateValue === 'string' &&
|
|
37
|
+
(candidateValue === scopeValue || candidateValue.startsWith(scopeValue + '/'));
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
//# sourceMappingURL=permission-scope.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission-scope.js","sourceRoot":"","sources":["../../../../src/utils/permission-scope.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,MAAM,OAAO,sBAAsB;IACjC;;OAEG;IACI,MAAM,CAAC,OAAO,CAAC,KAAoB,EAAE,MAAqB;QAC/D,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,I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,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QACpF,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,cAAsB,EAAE,kBAA2B;QACjF,OAAO,sBAAsB,CAAC,cAAc,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;IACnF,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,UAAkB,EAAE,cAAuB;QACvE,OAAO,OAAO,cAAc,KAAK,QAAQ;YACvC,CAAC,cAAc,KAAK,UAAU,IAAI,cAAc,CAAC,UAAU,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC;IACnF,CAAC;CACF"}
|
|
@@ -52,7 +52,7 @@ export function getRuleSetAtPath(protocolPath, structure) {
|
|
|
52
52
|
* Class containing Protocol related utility methods.
|
|
53
53
|
*/
|
|
54
54
|
export class Protocols {
|
|
55
|
-
// Implementation dispatches based on argument type
|
|
55
|
+
// Implementation dispatches based on argument type.
|
|
56
56
|
static async deriveAndInjectPublicEncryptionKeys(protocolDefinition, rootKeyIdOrKeyDeriver, privateJwk) {
|
|
57
57
|
// clone before modify
|
|
58
58
|
const clone = JSON.parse(JSON.stringify(protocolDefinition));
|
|
@@ -60,6 +60,9 @@ export class Protocols {
|
|
|
60
60
|
// Callback-based path
|
|
61
61
|
const keyDeriver = rootKeyIdOrKeyDeriver;
|
|
62
62
|
const basePath = [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol];
|
|
63
|
+
clone.$keyAgreement = {
|
|
64
|
+
publicKeyJwk: await keyDeriver.derivePublicKey(basePath),
|
|
65
|
+
};
|
|
63
66
|
async function injectKeysViaCallback(ruleSet, parentPath) {
|
|
64
67
|
for (const key in ruleSet) {
|
|
65
68
|
if (!key.startsWith('$')) {
|
|
@@ -72,10 +75,7 @@ export class Protocols {
|
|
|
72
75
|
continue;
|
|
73
76
|
}
|
|
74
77
|
const publicKeyJwk = await keyDeriver.derivePublicKey(currentPath);
|
|
75
|
-
childRuleSet.$
|
|
76
|
-
rootKeyId: keyDeriver.rootKeyId,
|
|
77
|
-
publicKeyJwk,
|
|
78
|
-
};
|
|
78
|
+
childRuleSet.$keyAgreement = { publicKeyJwk };
|
|
79
79
|
await injectKeysViaCallback(childRuleSet, currentPath);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -83,12 +83,12 @@ export class Protocols {
|
|
|
83
83
|
await injectKeysViaCallback(clone.structure, basePath);
|
|
84
84
|
return clone;
|
|
85
85
|
}
|
|
86
|
-
// Raw-key path
|
|
86
|
+
// Raw-key path
|
|
87
87
|
const rootKeyId = rootKeyIdOrKeyDeriver;
|
|
88
|
-
// a function that recursively creates and adds `$
|
|
88
|
+
// a function that recursively creates and adds `$keyAgreement` property to every rule set
|
|
89
89
|
async function addEncryptionProperty(ruleSet, parentKey) {
|
|
90
90
|
for (const key in ruleSet) {
|
|
91
|
-
// if we encounter a nested rule set (a property name that doesn't begin with '$'), recursively inject the `$
|
|
91
|
+
// if we encounter a nested rule set (a property name that doesn't begin with '$'), recursively inject the `$keyAgreement` property
|
|
92
92
|
if (!key.startsWith('$')) {
|
|
93
93
|
const derivedPrivateKey = await HdKey.derivePrivateKey(parentKey, [key]);
|
|
94
94
|
const childRuleSet = ruleSet[key];
|
|
@@ -99,7 +99,7 @@ export class Protocols {
|
|
|
99
99
|
continue;
|
|
100
100
|
}
|
|
101
101
|
const publicKeyJwk = await X25519.getPublicKey({ key: derivedPrivateKey.derivedPrivateKey });
|
|
102
|
-
childRuleSet.$
|
|
102
|
+
childRuleSet.$keyAgreement = { publicKeyJwk };
|
|
103
103
|
await addEncryptionProperty(childRuleSet, derivedPrivateKey);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -111,6 +111,9 @@ export class Protocols {
|
|
|
111
111
|
rootKeyId
|
|
112
112
|
};
|
|
113
113
|
const protocolLevelDerivedKey = await HdKey.derivePrivateKey(rootKey, [KeyDerivationScheme.ProtocolPath, protocolDefinition.protocol]);
|
|
114
|
+
clone.$keyAgreement = {
|
|
115
|
+
publicKeyJwk: await X25519.getPublicKey({ key: protocolLevelDerivedKey.derivedPrivateKey }),
|
|
116
|
+
};
|
|
114
117
|
await addEncryptionProperty(clone.structure, protocolLevelDerivedKey);
|
|
115
118
|
return clone;
|
|
116
119
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocols.js","sourceRoot":"","sources":["../../../../src/utils/protocols.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAYhE;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC3C,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IAEnD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC9C,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAoB,EAAE,SAA6C;IAClG,MAAM,QAAQ,GAAG,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