@@ -14,17 +14,17 @@ import (
1414 "sync"
1515 "time"
1616
17- "golang.org/x/crypto/sha3"
18-
1917 "github.com/ethereum/go-ethereum/crypto"
2018 "github.com/keep-network/keep-core/pkg/bitcoin"
2119 "github.com/keep-network/keep-core/pkg/chain"
2220 "github.com/keep-network/keep-core/pkg/chain/local_v1"
21+ "github.com/keep-network/keep-core/pkg/internal/byteutils"
2322 "github.com/keep-network/keep-core/pkg/operator"
2423 "github.com/keep-network/keep-core/pkg/protocol/group"
2524 "github.com/keep-network/keep-core/pkg/protocol/inactivity"
2625 "github.com/keep-network/keep-core/pkg/subscription"
2726 "github.com/keep-network/keep-core/pkg/tecdsa/dkg"
27+ "golang.org/x/crypto/sha3"
2828)
2929
3030const (
@@ -843,6 +843,40 @@ func buildDepositRequestKey(
843843 return sha256 .Sum256 (append (fundingTxHash [:], buffer ... ))
844844}
845845
846+ func (lc * localChain ) CalculateWalletID (
847+ walletPublicKey * ecdsa.PublicKey ,
848+ ) ([32 ]byte , error ) {
849+ walletPublicKeyBytes , err := convertPubKeyToChainFormat (walletPublicKey )
850+ if err != nil {
851+ return [32 ]byte {}, fmt .Errorf (
852+ "error while converting wallet public key to chain format: [%v]" ,
853+ err ,
854+ )
855+ }
856+
857+ return crypto .Keccak256Hash (walletPublicKeyBytes [:]), nil
858+ }
859+
860+ func convertPubKeyToChainFormat (publicKey * ecdsa.PublicKey ) ([64 ]byte , error ) {
861+ var serialized [64 ]byte
862+
863+ x , err := byteutils .LeftPadTo32Bytes (publicKey .X .Bytes ())
864+ if err != nil {
865+ return serialized , err
866+ }
867+
868+ y , err := byteutils .LeftPadTo32Bytes (publicKey .Y .Bytes ())
869+ if err != nil {
870+ return serialized , err
871+ }
872+
873+ serializedBytes := append (x , y ... )
874+
875+ copy (serialized [:], serializedBytes )
876+
877+ return serialized , nil
878+ }
879+
846880func (lc * localChain ) GetWallet (walletPublicKeyHash [20 ]byte ) (
847881 * WalletChainData ,
848882 error ,
@@ -858,6 +892,23 @@ func (lc *localChain) GetWallet(walletPublicKeyHash [20]byte) (
858892 return walletChainData , nil
859893}
860894
895+ func (lc * localChain ) IsWalletRegistered (EcdsaWalletID [32 ]byte ) (bool , error ) {
896+ lc .walletsMutex .Lock ()
897+ defer lc .walletsMutex .Unlock ()
898+
899+ for _ , walletData := range lc .wallets {
900+ if EcdsaWalletID == walletData .EcdsaWalletID {
901+ if walletData .State == StateClosed ||
902+ walletData .State == StateTerminated {
903+ return false , nil
904+ }
905+ return true , nil
906+ }
907+ }
908+
909+ return false , fmt .Errorf ("wallet not found" )
910+ }
911+
861912func (lc * localChain ) setWallet (
862913 walletPublicKeyHash [20 ]byte ,
863914 walletChainData * WalletChainData ,
@@ -868,6 +919,12 @@ func (lc *localChain) setWallet(
868919 lc .wallets [walletPublicKeyHash ] = walletChainData
869920}
870921
922+ func (lc * localChain ) OnWalletClosed (
923+ handler func (event * WalletClosedEvent ),
924+ ) subscription.EventSubscription {
925+ panic ("unsupported" )
926+ }
927+
871928func (lc * localChain ) ComputeMainUtxoHash (
872929 mainUtxo * bitcoin.UnspentTransactionOutput ,
873930) [32 ]byte {
0 commit comments