34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
|
/// <reference types="node" />
|
||
|
import { KeyObject } from 'crypto';
|
||
|
declare type KeyPair = {
|
||
|
privateKey: KeyObject;
|
||
|
publicKey: KeyObject;
|
||
|
};
|
||
|
declare type EncryptionContext = {
|
||
|
nonce: Buffer;
|
||
|
passphrase: Buffer;
|
||
|
};
|
||
|
declare type DecryptionContext = EncryptionContext & {
|
||
|
authTag: Buffer;
|
||
|
};
|
||
|
export default class CryptoContext {
|
||
|
_generateNonce(): Promise<Buffer>;
|
||
|
_generateKeyPair(): Promise<KeyPair>;
|
||
|
_generatePassphrase(nonce: Buffer): Promise<Buffer>;
|
||
|
private _saveNonce;
|
||
|
_savePrivateKey(privateKey: KeyObject, nonce: Buffer): Promise<void>;
|
||
|
_savePassphrase(passphrase: Buffer, publicKey: KeyObject): Promise<void>;
|
||
|
_saveAuthTag(authTag: Buffer): Promise<void>;
|
||
|
_loadAuthTag(): Promise<Buffer>;
|
||
|
private _loadNonce;
|
||
|
_loadPrivateKey(nonce: Buffer): Promise<KeyObject>;
|
||
|
_loadPassphrase(privateKey: KeyObject): Promise<Buffer>;
|
||
|
_generateEncryptionKeys(): Promise<EncryptionContext>;
|
||
|
_loadDecryptionKeys(): Promise<DecryptionContext>;
|
||
|
private _createCipher;
|
||
|
private _createDecipher;
|
||
|
encrypt(data: Buffer): Promise<Buffer>;
|
||
|
decrypt(data: Buffer): Promise<Buffer>;
|
||
|
}
|
||
|
export {};
|