@ethereumjs/evm
Version:
JavaScript Ethereum Virtual Machine (EVM) implementation
29 lines • 1.33 kB
JavaScript
import { bytesToUnprefixedHex, hexToBytes } from '@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.
*/
export class RustBN254 {
constructor(rustbn) {
this._rustbn = rustbn;
}
add(input) {
// Using deprecated bytesToUnprefixedHex for performance: rustbn WASM library expects unprefixed hex strings.
const inputStr = bytesToUnprefixedHex(input);
return hexToBytes(this._rustbn.ec_add(inputStr));
}
mul(input) {
// Using deprecated bytesToUnprefixedHex for performance: rustbn WASM library expects unprefixed hex strings.
const inputHex = bytesToUnprefixedHex(input);
return hexToBytes(this._rustbn.ec_mul(inputHex));
}
pairing(input) {
// Using deprecated bytesToUnprefixedHex for performance: rustbn WASM library expects unprefixed hex strings.
const inputStr = bytesToUnprefixedHex(input);
return hexToBytes(this._rustbn.ec_pairing(inputStr));
}
}
//# sourceMappingURL=rustbn.js.map