mirror of
https://github.com/luxfi/crypto.git
synced 2026-07-27 01:54:50 +00:00
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
// Copyright (C) 2020-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package bls
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/crypto"
|
|
)
|
|
|
|
func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
pkBytes := crypto.RandomBytes(PublicKeyLen + 1)
|
|
_, err := PublicKeyFromCompressedBytes(pkBytes)
|
|
require.ErrorIs(err, ErrFailedPublicKeyDecompress)
|
|
}
|
|
|
|
func TestPublicKeyBytes(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
pkBytes, err := base64.StdEncoding.DecodeString("h5qt9SPxaCo+vOx6sn+QkkpP7Y40Yja7SEAs2MGb/mZT7oKTWgLogjy5c4/wWIGC")
|
|
require.NoError(err)
|
|
|
|
pk, err := PublicKeyFromCompressedBytes(pkBytes)
|
|
require.NoError(err)
|
|
|
|
pk2Bytes := PublicKeyToCompressedBytes(pk)
|
|
|
|
require.Equal(pkBytes, pk2Bytes)
|
|
}
|
|
|
|
func TestAggregatePublicKeysNoop(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
pkBytes, err := base64.StdEncoding.DecodeString("h5qt9SPxaCo+vOx6sn+QkkpP7Y40Yja7SEAs2MGb/mZT7oKTWgLogjy5c4/wWIGC")
|
|
require.NoError(err)
|
|
|
|
pk, err := PublicKeyFromCompressedBytes(pkBytes)
|
|
require.NoError(err)
|
|
|
|
aggPK, err := AggregatePublicKeys([]*PublicKey{pk})
|
|
require.NoError(err)
|
|
|
|
aggPKBytes := PublicKeyToCompressedBytes(aggPK)
|
|
require.NoError(err)
|
|
|
|
require.Equal(pk, aggPK)
|
|
require.Equal(pkBytes, aggPKBytes)
|
|
}
|