@waku/rln
Version:
RLN (Rate Limiting Nullifier) implementation for Waku
66 lines (63 loc) • 2.8 kB
JavaScript
import { commonjsGlobal } from '../../../../_virtual/_commonjsHelpers.js';
import { __exports as cipher } from '../../../../_virtual/cipher.js';
import '../node_modules/ethereum-cryptography/random.js';
import '../node_modules/ethereum-cryptography/aes.js';
import { u as utilsExports } from '../node_modules/ethereum-cryptography/utils.js';
import { __exports as random } from '../../../../_virtual/random.js';
import { __exports as aes } from '../../../../_virtual/aes.js';
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(cipher, "__esModule", { value: true });
var cipherDecrypt_1 = cipher.cipherDecrypt = cipher.cipherEncrypt = cipher.defaultAes128CtrModule = void 0;
const random_1 = random;
const aes_1 = aes;
const utils_1 = utilsExports;
function defaultAes128CtrModule() {
return {
function: "aes-128-ctr",
params: {
iv: utils_1.bytesToHex(random_1.getRandomBytesSync(16)),
},
};
}
cipher.defaultAes128CtrModule = defaultAes128CtrModule;
function cipherEncrypt(mod, key, data) {
return __awaiter(this, void 0, void 0, function* () {
if (mod.function === "aes-128-ctr") {
try {
return yield aes_1.encrypt(data, key, utils_1.hexToBytes(mod.params.iv), mod.function, false);
}
catch (e) {
throw new Error("Unable to encrypt");
}
}
else {
throw new Error("Invalid cipher type");
}
});
}
cipher.cipherEncrypt = cipherEncrypt;
function cipherDecrypt(mod, key) {
return __awaiter(this, void 0, void 0, function* () {
if (mod.function === "aes-128-ctr") {
try {
return yield aes_1.decrypt(utils_1.hexToBytes(mod.message), key, utils_1.hexToBytes(mod.params.iv), mod.function, false);
}
catch (e) {
throw new Error("Unable to decrypt");
}
}
else {
throw new Error("Invalid cipher type");
}
});
}
cipherDecrypt_1 = cipher.cipherDecrypt = cipherDecrypt;
export { cipherDecrypt_1 as cipherDecrypt, cipher as default };