Skip to content

Commit ce29749

Browse files
committed
integrate agg changes on crypto
1 parent 05006fc commit ce29749

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

crypto/signing/bls/bls.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bls
22

33
import (
4-
"github.com/multiversx/mx-chain-crypto-go"
4+
crypto "github.com/multiversx/mx-chain-crypto-go"
55
"github.com/multiversx/mx-chain-crypto-go/signing"
66
"github.com/multiversx/mx-chain-crypto-go/signing/mcl"
77
mclMultiSig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/multisig"
@@ -46,5 +46,25 @@ func (b *bls) VerifySignatureShare(publicKey []byte, message []byte, sig []byte)
4646

4747
// VerifyAggregatedSig verifies aggregated signature of BLS MultiSig
4848
func (b *bls) VerifyAggregatedSig(pubKeysSigners [][]byte, message []byte, aggSig []byte) error {
49-
return b.multiSigner.VerifyAggregatedSig(pubKeysSigners, message, aggSig)
49+
pubKeys, err := b.convertBytesToPubKeys(pubKeysSigners)
50+
if err != nil {
51+
return err
52+
}
53+
54+
return b.multiSigner.VerifyAggregatedSig(pubKeys, message, aggSig)
55+
}
56+
57+
func (b *bls) convertBytesToPubKeys(pubKeysBytes [][]byte) ([]crypto.PublicKey, error) {
58+
pubKeys := make([]crypto.PublicKey, 0, len(pubKeysBytes))
59+
60+
for _, pubKeyBytes := range pubKeysBytes {
61+
pk, err := b.keyGenerator.PublicKeyFromByteArray(pubKeyBytes)
62+
if err != nil {
63+
return nil, err
64+
}
65+
66+
pubKeys = append(pubKeys, pk)
67+
}
68+
69+
return pubKeys, nil
5070
}

crypto/signing/bls/bls_test.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717

1818
type multiSignerSetup struct {
1919
privKeys [][]byte
20-
pubKeys [][]byte
20+
pubKeysBytes [][]byte
21+
pubKeys []crypto.PublicKey
2122
partialSignatures [][][]byte
2223
messages []string
2324
aggSignatures [][]byte
@@ -51,19 +52,19 @@ func TestBls_VerifyBLSMultiSig(t *testing.T) {
5152
setupKOSK, multiSignerKOSK := createMultiSigSetupKOSK(uint16(numMessages), numMessages)
5253
setupKOSK.aggSignatures = aggregateSignatures(setupKOSK, multiSignerKOSK)
5354

54-
for i := 0; i < len(setupKOSK.pubKeys); i++ {
55-
fmt.Println(hex.EncodeToString(setupKOSK.pubKeys[i]))
55+
for i := 0; i < len(setupKOSK.pubKeysBytes); i++ {
56+
fmt.Println(hex.EncodeToString(setupKOSK.pubKeysBytes[i]))
5657
}
5758

5859
for i := 0; i < numMessages; i++ {
5960
fmt.Println(setupKOSK.messages[i])
6061
fmt.Println(hex.EncodeToString(setupKOSK.aggSignatures[i]))
6162

62-
assert.Nil(t, b.VerifyAggregatedSig(setupKOSK.pubKeys, []byte(setupKOSK.messages[i]), setupKOSK.aggSignatures[i]))
63+
assert.Nil(t, b.VerifyAggregatedSig(setupKOSK.pubKeysBytes, []byte(setupKOSK.messages[i]), setupKOSK.aggSignatures[i]))
6364
changedSig := make([]byte, len(setupKOSK.aggSignatures[i]))
6465
copy(changedSig, setupKOSK.aggSignatures[i])
6566
changedSig[0] += 1
66-
assert.NotNil(t, b.VerifyAggregatedSig(setupKOSK.pubKeys, []byte(setupKOSK.messages[i]), changedSig))
67+
assert.NotNil(t, b.VerifyAggregatedSig(setupKOSK.pubKeysBytes, []byte(setupKOSK.messages[i]), changedSig))
6768
}
6869
}
6970

@@ -84,26 +85,28 @@ func splitString(t testing.TB, str string) ([]byte, []byte, []byte) {
8485
func createKeysAndMultiSignerBlsKOSK(
8586
grSize uint16,
8687
suite crypto.Suite,
87-
) ([][]byte, [][]byte, crypto.MultiSigner) {
88+
) ([][]byte, []crypto.PublicKey, [][]byte, crypto.MultiSigner) {
8889

89-
kg, privKeys, pubKeys := createMultiSignerSetup(grSize, suite)
90+
kg, pubKeys, privKeys, pubKeysBytes := createMultiSignerSetup(grSize, suite)
9091
llSigner := &llsig.BlsMultiSignerKOSK{}
9192
multiSigner, _ := multisig.NewBLSMultisig(llSigner, kg)
9293

93-
return privKeys, pubKeys, multiSigner
94+
return privKeys, pubKeys, pubKeysBytes, multiSigner
9495
}
9596

96-
func createMultiSignerSetup(grSize uint16, suite crypto.Suite) (crypto.KeyGenerator, [][]byte, [][]byte) {
97+
func createMultiSignerSetup(grSize uint16, suite crypto.Suite) (crypto.KeyGenerator, []crypto.PublicKey, [][]byte, [][]byte) {
9798
kg := signing.NewKeyGenerator(suite)
9899
privKeys := make([][]byte, grSize)
99-
pubKeys := make([][]byte, grSize)
100+
pubKeysBytes := make([][]byte, grSize)
101+
pubKeys := make([]crypto.PublicKey, grSize)
100102

101103
for i := uint16(0); i < grSize; i++ {
102104
sk, pk := kg.GeneratePair()
103105
privKeys[i], _ = sk.ToByteArray()
104-
pubKeys[i], _ = pk.ToByteArray()
106+
pubKeysBytes[i], _ = pk.ToByteArray()
107+
pubKeys[i] = pk
105108
}
106-
return kg, privKeys, pubKeys
109+
return kg, pubKeys, privKeys, pubKeysBytes
107110
}
108111

109112
func createSignaturesShares(privKeys [][]byte, multiSigner crypto.MultiSigner, message []byte) [][]byte {
@@ -119,7 +122,7 @@ func createMultiSigSetupKOSK(numSigners uint16, numMessages int) (*multiSignerSe
119122
var multiSigner crypto.MultiSigner
120123
setup := &multiSignerSetup{}
121124
suite := mcl.NewSuiteBLS12()
122-
setup.privKeys, setup.pubKeys, multiSigner = createKeysAndMultiSignerBlsKOSK(numSigners, suite)
125+
setup.privKeys, setup.pubKeys, setup.pubKeysBytes, multiSigner = createKeysAndMultiSignerBlsKOSK(numSigners, suite)
123126
setup.messages, setup.partialSignatures = createMessagesAndPartialSignatures(numMessages, setup.privKeys, multiSigner)
124127

125128
return setup, multiSigner

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/gogo/protobuf v1.3.2
1010
github.com/mitchellh/mapstructure v1.5.0
1111
github.com/multiversx/mx-chain-core-go v1.4.0
12-
github.com/multiversx/mx-chain-crypto-go v1.3.0
12+
github.com/multiversx/mx-chain-crypto-go v1.3.1-0.20260127130843-3c6c4667127e
1313
github.com/multiversx/mx-chain-logger-go v1.1.0
1414
github.com/multiversx/mx-chain-scenario-go v1.6.0
1515
github.com/multiversx/mx-chain-storage-go v1.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
8585
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
8686
github.com/multiversx/mx-chain-core-go v1.4.0 h1:p6FbfCzvMXF54kpS0B5mrjNWYpq4SEQqo0UvrMF7YVY=
8787
github.com/multiversx/mx-chain-core-go v1.4.0/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
88-
github.com/multiversx/mx-chain-crypto-go v1.3.0 h1:0eK2bkDOMi8VbSPrB1/vGJSYT81IBtfL4zw+C4sWe/k=
89-
github.com/multiversx/mx-chain-crypto-go v1.3.0/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM=
88+
github.com/multiversx/mx-chain-crypto-go v1.3.1-0.20260127130843-3c6c4667127e h1:F3v0GphOgNrGxwYZdMuSr4BznolQApzIfSOv9ys0nYM=
89+
github.com/multiversx/mx-chain-crypto-go v1.3.1-0.20260127130843-3c6c4667127e/go.mod h1:nPIkxxzyTP8IquWKds+22Q2OJ9W7LtusC7cAosz7ojM=
9090
github.com/multiversx/mx-chain-logger-go v1.1.0 h1:97x84A6L4RfCa6YOx1HpAFxZp1cf/WI0Qh112whgZNM=
9191
github.com/multiversx/mx-chain-logger-go v1.1.0/go.mod h1:K9XgiohLwOsNACETMNL0LItJMREuEvTH6NsoXWXWg7g=
9292
github.com/multiversx/mx-chain-scenario-go v1.6.0 h1:cwDFuS1pSc4YXnfiKKDTEb+QDY4fulPQaiRgIebnKxI=

0 commit comments

Comments
 (0)