Skip to content

Commit 7220425

Browse files
fix: return comments to encryption file
1 parent 3d68bc2 commit 7220425

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/utils/encryption.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@ import { Readable } from 'readable-stream';
66
// Compress publicKey for message encryption
77
eciesjs.ECIES_CONFIG.isEphemeralKeyCompressed = true;
88

9-
export interface EciesEncryptionOutput {
9+
export type EciesEncryptionOutput = {
1010
ciphertext: Uint8Array;
1111
ephemeralPublicKey: Uint8Array;
1212
initializationVector: Uint8Array;
1313
messageAuthenticationCode: Uint8Array;
14-
}
14+
};
1515

16-
export interface EciesEncryptionInput {
16+
export type EciesEncryptionInput = {
1717
privateKey: Uint8Array;
1818
ephemeralPublicKey: Uint8Array;
1919
initializationVector: Uint8Array;
2020
messageAuthenticationCode: Uint8Array;
2121
ciphertext: Uint8Array;
22-
}
22+
};
2323

2424
/**
2525
* Utility class for performing common, non-DWN specific encryption operations.
2626
*/
2727
export class Encryption {
28+
2829
/**
29-
* Converts a key to base64url encoding
30-
* @param key - Uint8Array to convert
30+
* Encrypts the given plaintext stream using AES-256-CTR algorithm.
3131
*/
32+
3233
public static isEphemeralKeyCompressed: boolean = true; // Set default value
3334

3435
private static toBase64Url(buffer: Buffer): string {
@@ -89,6 +90,11 @@ export class Encryption {
8990
return cipherStream; // Return the cipher stream
9091
}
9192

93+
94+
/**
95+
* Decrypts the given cipher stream using AES-256-CTR algorithm.
96+
*/
97+
9298
public static async aes256CtrDecrypt(
9399
key: Uint8Array,
94100
initializationVector: Uint8Array,
@@ -139,6 +145,7 @@ export class Encryption {
139145
const plaintextBuffer = Buffer.from(plaintext);
140146

141147
const cryptogram = eciesjs.encrypt(publicKey, plaintextBuffer);
148+
// split cryptogram returned into constituent parts
142149

143150
let start = 0;
144151
let end = Encryption.isEphemeralKeyCompressed ? 33 : 65;
@@ -162,6 +169,12 @@ export class Encryption {
162169
};
163170
}
164171

172+
/**
173+
* Decrypt the given plaintext using ECIES (Elliptic Curve Integrated Encryption Scheme)
174+
* with SECP256K1 for the asymmetric calculations, HKDF as the key-derivation function,
175+
* and AES-GCM for the symmetric encryption and MAC algorithms.
176+
*/
177+
165178
public static async eciesSecp256k1Decrypt(
166179
input: EciesEncryptionInput
167180
): Promise<Uint8Array> {
@@ -173,6 +186,9 @@ export class Encryption {
173186
input.ciphertext,
174187
]);
175188

189+
/**
190+
* Expose eciesjs library configuration
191+
*/
176192
return eciesjs.decrypt(privateKeyBuffer, eciesEncryptionOutput);
177193
}
178194
}

src/utils/hd-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import type { PrivateJwk, PublicJwk } from '../types/jose-types.js';
12
import { Encoder } from './encoder.js';
23
import { getWebcryptoSubtle } from '@noble/ciphers/webcrypto';
34
import { Secp256k1 } from './secp256k1.js';
45
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
5-
import type { PrivateJwk, PublicJwk } from '../types/jose-types.js';
66

77
export enum KeyDerivationScheme {
88
/**

0 commit comments

Comments
 (0)