@ethereumjs/evm
Version:
JavaScript Ethereum Virtual Machine (EVM) implementation
33 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RustBN254 = void 0;
const util_1 = require("@ethereumjs/util");
/**
* Implementation of the `EVMBN254Interface` using a WASM wrapper https://github.com/ethereumjs/rustbn.js
* around the Parity fork of the Zcash bn pairing cryptography library.
*
* This can be optionally used to replace the build-in Noble implementation (`NobleBN254`) with
* a more performant WASM variant. See EVM `bls` constructor option on how to use.
*/
class RustBN254 {
constructor(rustbn) {
this._rustbn = rustbn;
}
add(input) {
// Using deprecated bytesToUnprefixedHex for performance: rustbn WASM library expects unprefixed hex strings.
const inputStr = (0, util_1.bytesToUnprefixedHex)(input);
return (0, util_1.hexToBytes)(this._rustbn.ec_add(inputStr));
}
mul(input) {
// Using deprecated bytesToUnprefixedHex for performance: rustbn WASM library expects unprefixed hex strings.
const inputHex = (0, util_1.bytesToUnprefixedHex)(input);
return (0, util_1.hexToBytes)(this._rustbn.ec_mul(inputHex));
}
pairing(input) {
// Using deprecated bytesToUnprefixedHex for performance: rustbn WASM library expects unprefixed hex strings.
const inputStr = (0, util_1.bytesToUnprefixedHex)(input);
return (0, util_1.hexToBytes)(this._rustbn.ec_pairing(inputStr));
}
}
exports.RustBN254 = RustBN254;
//# sourceMappingURL=rustbn.js.map