Skip to content

Commit

Permalink
Merge pull request #549 from onflow/tarak/fix-crypto-type-issue
Browse files Browse the repository at this point in the history
Remove unnecessary conversions
  • Loading branch information
tarakby authored Jan 17, 2024
2 parents 076bd94 + 71c897e commit 7efbc63
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions convert/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
"github.com/onflow/cadence/encoding/ccf"

sdk "github.com/onflow/flow-go-sdk"
sdkcrypto "github.com/onflow/flow-go-sdk/crypto"
"github.com/onflow/flow-go/access"
flowcrypto "github.com/onflow/flow-go/crypto"
flowgo "github.com/onflow/flow-go/model/flow"
)

Expand Down Expand Up @@ -231,47 +229,25 @@ func FlowEventsToSDK(flowEvents []flowgo.Event) ([]sdk.Event, error) {
}

func FlowAccountPublicKeyToSDK(flowPublicKey flowgo.AccountPublicKey, index int) (sdk.AccountKey, error) {
// TODO - Looks like SDK contains copy-paste of code from flow-go
// Once crypto become its own separate library, this can possibly be simplified or not needed
encodedPublicKey := flowPublicKey.PublicKey.Encode()

sdkSignAlgo := flowPublicKey.SignAlgo

sdkPublicKey, err := sdkcrypto.DecodePublicKey(sdkSignAlgo, encodedPublicKey)
if err != nil {
return sdk.AccountKey{}, err
}

sdkHashAlgo := flowPublicKey.HashAlgo

return sdk.AccountKey{
Index: index,
PublicKey: sdkPublicKey,
SigAlgo: sdkSignAlgo,
HashAlgo: sdkHashAlgo,
PublicKey: flowPublicKey.PublicKey,
SigAlgo: flowPublicKey.SignAlgo,
HashAlgo: flowPublicKey.HashAlgo,
Weight: flowPublicKey.Weight,
SequenceNumber: flowPublicKey.SeqNumber,
Revoked: flowPublicKey.Revoked,
}, nil
}

func SDKAccountKeyToFlow(key *sdk.AccountKey) (flowgo.AccountPublicKey, error) {
encodedPublicKey := key.PublicKey.Encode()

flowSignAlgo := key.SigAlgo

flowPublicKey, err := flowcrypto.DecodePublicKey(flowSignAlgo, encodedPublicKey)
if err != nil {
return flowgo.AccountPublicKey{}, err
}

flowhashAlgo := key.HashAlgo

return flowgo.AccountPublicKey{
Index: key.Index,
PublicKey: flowPublicKey,
SignAlgo: flowSignAlgo,
HashAlgo: flowhashAlgo,
PublicKey: key.PublicKey,
SignAlgo: key.SigAlgo,
HashAlgo: key.HashAlgo,
Weight: key.Weight,
SeqNumber: key.SequenceNumber,
Revoked: key.Revoked,
Expand Down

0 comments on commit 7efbc63

Please # to comment.