def test_bbs_from_public_key(self): bls_key_pair = BlsKeyPair.generate_g2() bbs_key_pair = BlsKeyPair(bls_key_pair.public_key) self.assertIsNone(bbs_key_pair.secret_key) public_key = bbs_key_pair.get_bbs_key(1) self.assertIsNotNone(public_key) self.assertIsNotNone(bbs_key_pair.public_key) self.assertIsNone(bbs_key_pair.secret_key) self.assertEqual(196, len(public_key.public_key)) self.assertEqual(32, len(bls_key_pair.secret_key))
def test_blind_commitment_single_message(self): key = BlsKeyPair.generate_g2() public_key = key.get_bbs_key(1) commitment = create_blinded_commitment( CreateBlindedCommitmentRequest( public_key=public_key, messages=[IndexedMessage('message_0', 0)], nonce=b'1234')) self.assertIsNotNone(commitment) self.assertIsNotNone(commitment.blinding_factor) self.assertIsNotNone(commitment.blind_sign_context) self.assertIsNotNone(commitment.commitment)
def test_generate_g2_key_with_seed(self): seed = 'just a seed' key_pair = BlsKeyPair.generate_g2(seed) self.assertIsNotNone(key_pair, "Key pair should not be None") self.assertIsNotNone(key_pair.public_key, "Key pair should have public key") self.assertIsNotNone(key_pair.secret_key, "Key pair should have secret key") self.assertTrue(key_pair.is_g2, "Key should be G2 key") self.assertFalse(key_pair.is_g1, "Key should NOT be G1 key") self.assertEqual(BlsKeyPair.secret_key_size(), len(key_pair.secret_key)) self.assertEqual(BlsKeyPair.public_g2_key_size(), len(key_pair.public_key))
def test_sign_single_message(self): bls_key = BlsKeyPair.generate_g2() public_key = bls_key.get_bbs_key(2) messages: List[IndexedMessage] = [ IndexedMessage('message_0', 0), IndexedMessage('message_1', 1) ] nonce = b'12345' commitment = create_blinded_commitment( CreateBlindedCommitmentRequest(public_key, messages, nonce)) blind_signature = blind_sign( BlindSignRequest(bls_key, public_key, commitment.commitment, messages)) self.assertIsNotNone(blind_signature)
def create_bls12381g2_keypair(seed: bytes = None) -> Tuple[bytes, bytes]: """ Create a public and private bls12381g2 keypair from a seed value. Args: seed: Seed for keypair Returns: A tuple of (public key, secret key) """ if not seed: seed = random_seed() try: key_pair = BlsKeyPair.generate_g2(seed) return key_pair.public_key, key_pair.secret_key except (Exception) as error: raise BbsException("Unable to create keypair") from error
def test_bbs_from_secret_key(self): secret_key = BlsKeyPair.generate_g2() public_key = secret_key.get_bbs_key(1) self.assertIsNotNone(public_key) self.assertEqual(196, len(public_key.public_key))