From 9267e581436db4e6c761f9600243bc4f14aec36e Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 2 Aug 2023 13:11:26 -0400 Subject: [PATCH] feat(api): add GetCommunityPublicKeyFromPrivateKey to api (#3828) --- protocol/messenger_communities.go | 2 +- services/ext/api.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 38475cdbf..23d6719ea 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -2104,7 +2104,7 @@ func (m *Messenger) findCommunityInfoFromDB(communityID string) (*communities.Co } func (m *Messenger) GetCommunityIDFromKey(communityKey string) string { - // Check if the key is a private key + // Check if the key is a private key. strip the 0x at the start privateKey, err := crypto.HexToECDSA(communityKey[2:]) communityID := "" if err != nil { diff --git a/services/ext/api.go b/services/ext/api.go index cece42b10..aaa3ad0e0 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -452,6 +452,12 @@ func (api *PublicAPI) ImportCommunity(ctx context.Context, hexPrivateKey string) return nil, err } return api.service.messenger.ImportCommunity(ctx, privateKey) +} + +// GetCommunityPublicKeyFromPrivateKey gets the community's public key from its private key +func (api *PublicAPI) GetCommunityPublicKeyFromPrivateKey(ctx context.Context, hexPrivateKey string) string { + publicKey := api.service.messenger.GetCommunityIDFromKey(hexPrivateKey) + return publicKey }