@@ -7,11 +7,11 @@ package accesscontrol
77import (
88 "context"
99 "crypto/ecdsa"
10- "crypto/elliptic"
1110 "errors"
1211 "fmt"
1312
1413 "github.com/btcsuite/btcd/btcec/v2"
14+ "github.com/ethereum/go-ethereum/crypto"
1515 "github.com/ethersphere/bee/v2/pkg/file"
1616 "github.com/ethersphere/bee/v2/pkg/swarm"
1717)
@@ -85,7 +85,10 @@ func (g *GranteeListStruct) Add(addList []*ecdsa.PublicKey) error {
8585
8686// Save saves the grantee list to the underlying storage and returns the reference.
8787func (g * GranteeListStruct ) Save (ctx context.Context ) (swarm.Address , error ) {
88- data := serialize (g .grantees )
88+ data , err := serialize (g .grantees )
89+ if err != nil {
90+ return swarm .ZeroAddress , fmt .Errorf ("grantee serialize error: %w" , err )
91+ }
8992 refBytes , err := g .loadSave .Save (ctx , data )
9093 if err != nil {
9194 return swarm .ZeroAddress , fmt .Errorf ("grantee save error: %w" , err )
@@ -140,16 +143,16 @@ func NewGranteeListReference(ctx context.Context, ls file.LoadSaver, reference s
140143 }, nil
141144}
142145
143- func serialize (publicKeys []* ecdsa.PublicKey ) []byte {
146+ func serialize (publicKeys []* ecdsa.PublicKey ) ( []byte , error ) {
144147 b := make ([]byte , 0 , len (publicKeys )* publicKeyLen )
145148 for _ , key := range publicKeys {
146- b = append (b , serializePublicKey (key )... )
149+ // TODO: check if this is the correct way to serialize the public key
150+ // Is this the only curve we support?
151+ // Should we have switch case for different curves?
152+ pubBytes := crypto .S256 ().Marshal (key .X , key .Y )
153+ b = append (b , pubBytes ... )
147154 }
148- return b
149- }
150-
151- func serializePublicKey (pub * ecdsa.PublicKey ) []byte {
152- return elliptic .Marshal (pub .Curve , pub .X , pub .Y )
155+ return b , nil
153156}
154157
155158func deserialize (data []byte ) []* ecdsa.PublicKey {
0 commit comments