└── BLSOpen.sol /BLSOpen.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >= 0.6.12; 3 | 4 | import { BLS } from "./hubble-contracts/contracts/libs/BLS.sol"; 5 | 6 | library BLSOpen { 7 | function verifySingle( 8 | uint256[2] memory signature, 9 | uint256[4] memory pubkey, 10 | uint256[2] memory message 11 | ) external view returns (bool) { 12 | uint256[4][] memory pubkeys = new uint256[4][](1); 13 | uint256[2][] memory messages = new uint256[2][](1); 14 | pubkeys[0] = pubkey; 15 | messages[0] = message; 16 | 17 | (bool verified, bool callSuccess) = BLS.verifyMultiple( 18 | signature, 19 | pubkeys, 20 | messages 21 | ); 22 | return callSuccess && verified; 23 | 24 | // // NB: (result, success) opposite of `call` convention (success, result). 25 | // (bool verified, bool callSuccess) = BLS.verifySingle( 26 | // signature, 27 | // pubkey, 28 | // message 29 | // ); 30 | // return callSuccess && verified; 31 | } 32 | 33 | function verifyMultiple( 34 | uint256[2] memory signature, 35 | uint256[4][] memory pubkeys, 36 | uint256[2][] memory messages 37 | ) external view returns (bool) { 38 | (bool verified, bool callSuccess) = BLS.verifyMultiple( 39 | signature, 40 | pubkeys, 41 | messages 42 | ); 43 | return callSuccess && verified; 44 | } 45 | 46 | function hashToPoint( 47 | bytes32 domain, 48 | bytes memory message 49 | ) external view returns (uint256[2] memory) { 50 | return BLS.hashToPoint( 51 | domain, 52 | message 53 | ); 54 | } 55 | 56 | function isZeroBLSKey(uint256[4] memory blsKey) public pure returns (bool) { 57 | bool isZero = true; 58 | for (uint256 i=0; isZero && i<4; i++) { 59 | isZero = (blsKey[i] == 0); 60 | } 61 | return isZero; 62 | } 63 | 64 | } 65 | --------------------------------------------------------------------------------