@hazae41/kdbx
Version:
Rust-like KeePass (KDBX 4) file format for TypeScript
126 lines (123 loc) • 4.5 kB
JavaScript
;
var tslib_es6 = require('../../../../../../node_modules/tslib/tslib.es6.cjs');
var chacha20poly1305 = require('@hazae41/chacha20poly1305');
var cursor = require('@hazae41/cursor');
exports.Cipher = void 0;
(function (Cipher) {
class ArcFourVariant {
constructor() { }
}
Cipher.ArcFourVariant = ArcFourVariant;
(function (ArcFourVariant) {
ArcFourVariant.type = 0x01;
function cloneOrThrow() {
return ArcFourVariant;
}
ArcFourVariant.cloneOrThrow = cloneOrThrow;
function sizeOrThrow() {
return 4;
}
ArcFourVariant.sizeOrThrow = sizeOrThrow;
function writeOrThrow(cursor) {
cursor.writeUint32OrThrow(ArcFourVariant.type, true);
}
ArcFourVariant.writeOrThrow = writeOrThrow;
async function initOrThrow(seed) {
throw new Error("ArcFourVariant is not implemented yet");
}
ArcFourVariant.initOrThrow = initOrThrow;
})(ArcFourVariant = Cipher.ArcFourVariant || (Cipher.ArcFourVariant = {}));
class Salsa20 {
key;
nonce;
constructor(key, nonce) {
this.key = key;
this.nonce = nonce;
}
}
Cipher.Salsa20 = Salsa20;
(function (Salsa20) {
Salsa20.type = 0x02;
function cloneOrThrow() {
return Salsa20;
}
Salsa20.cloneOrThrow = cloneOrThrow;
function sizeOrThrow() {
return 4;
}
Salsa20.sizeOrThrow = sizeOrThrow;
function writeOrThrow(cursor) {
cursor.writeUint32OrThrow(Salsa20.type, true);
}
Salsa20.writeOrThrow = writeOrThrow;
async function initOrThrow(seed) {
throw new Error("Salsa20 is not implemented yet");
}
Salsa20.initOrThrow = initOrThrow;
})(Salsa20 = Cipher.Salsa20 || (Cipher.Salsa20 = {}));
class ChaCha20 {
cipher;
constructor(cipher) {
this.cipher = cipher;
}
[Symbol.dispose]() {
this.cipher[Symbol.dispose]();
}
applyOrThrow(data) {
const { Memory } = chacha20poly1305.ChaCha20Poly1305.get().getOrThrow();
const memory = Memory.importOrThrow(data);
this.cipher.applyOrThrow(memory);
return memory;
}
}
Cipher.ChaCha20 = ChaCha20;
(function (ChaCha20) {
ChaCha20.type = 0x03;
function cloneOrThrow() {
return ChaCha20;
}
ChaCha20.cloneOrThrow = cloneOrThrow;
function sizeOrThrow() {
return 4;
}
ChaCha20.sizeOrThrow = sizeOrThrow;
function writeOrThrow(cursor) {
cursor.writeUint32OrThrow(ChaCha20.type, true);
}
ChaCha20.writeOrThrow = writeOrThrow;
async function initOrThrow(seed) {
const env_1 = { stack: [], error: void 0, hasError: false };
try {
const { Memory, ChaCha20Cipher } = chacha20poly1305.ChaCha20Poly1305.get().getOrThrow();
const hashed = new Uint8Array(await crypto.subtle.digest("SHA-512", seed));
const cursor$1 = new cursor.Cursor(hashed);
const key = tslib_es6.__addDisposableResource(env_1, Memory.importOrThrow(cursor$1.readOrThrow(32)), false);
const nonce = tslib_es6.__addDisposableResource(env_1, Memory.importOrThrow(cursor$1.readOrThrow(12)), false);
const cipher = ChaCha20Cipher.importOrThrow(key, nonce);
return new ChaCha20(cipher);
}
catch (e_1) {
env_1.error = e_1;
env_1.hasError = true;
}
finally {
tslib_es6.__disposeResources(env_1);
}
}
ChaCha20.initOrThrow = initOrThrow;
})(ChaCha20 = Cipher.ChaCha20 || (Cipher.ChaCha20 = {}));
})(exports.Cipher || (exports.Cipher = {}));
(function (Cipher) {
function readOrThrow(cursor) {
const value = cursor.readUint32OrThrow(true);
if (value === Cipher.ArcFourVariant.type)
return Cipher.ArcFourVariant;
if (value === Cipher.Salsa20.type)
return Cipher.Salsa20;
if (value === Cipher.ChaCha20.type)
return Cipher.ChaCha20;
throw new Error();
}
Cipher.readOrThrow = readOrThrow;
})(exports.Cipher || (exports.Cipher = {}));
//# sourceMappingURL=index.cjs.map