@waku/rln
Version:
RLN (Rate Limiting Nullifier) implementation for Waku
53 lines (50 loc) • 2.29 kB
JavaScript
import { commonjsGlobal } from '../../../../_virtual/_commonjsHelpers.js';
import { __exports as checksum$1 } from '../../../../_virtual/checksum.js';
import '../node_modules/ethereum-cryptography/sha256.js';
import { u as utilsExports } from '../node_modules/ethereum-cryptography/utils.js';
import { __exports as sha256 } from '../../../../_virtual/sha256.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(checksum$1, "__esModule", { value: true });
checksum$1.verifyChecksum = checksum$1.checksum = checksum$1.defaultSha256Module = void 0;
const sha256_1 = sha256;
const utils_1 = utilsExports;
// default checksum configuration
function defaultSha256Module() {
return {
function: "sha256",
};
}
checksum$1.defaultSha256Module = defaultSha256Module;
// checksum operations
function checksumData(key, ciphertext) {
return utils_1.concatBytes(key.slice(16), ciphertext);
}
function checksum(mod, key, ciphertext) {
if (mod.function === "sha256") {
return Promise.resolve(sha256_1.sha256(checksumData(key, ciphertext)));
}
else {
throw new Error("Invalid checksum type");
}
}
checksum$1.checksum = checksum;
function verifyChecksum(mod, key, ciphertext) {
return __awaiter(this, void 0, void 0, function* () {
if (mod.function === "sha256") {
return utils_1.equalsBytes(utils_1.hexToBytes(mod.message), sha256_1.sha256(checksumData(key, ciphertext)));
}
else {
throw new Error("Invalid checksum type");
}
});
}
checksum$1.verifyChecksum = verifyChecksum;
export { checksum$1 as default };