From f595b6b248b20efda0d9c1399007b9e9e1382ae3 Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Thu, 1 Sep 2022 11:14:26 -0700
Subject: [PATCH] Add GetContactFromReceptionIdentity to get the marshalled
 contact bytes from a reception identity

---
 main.go          |  2 ++
 wasm/identity.go | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/main.go b/main.go
index 9f337d87..2294615c 100644
--- a/main.go
+++ b/main.go
@@ -58,6 +58,8 @@ func main() {
 		js.FuncOf(wasm.StoreReceptionIdentity))
 	js.Global().Set("LoadReceptionIdentity",
 		js.FuncOf(wasm.LoadReceptionIdentity))
+	js.Global().Set("GetContactFromReceptionIdentity",
+		js.FuncOf(wasm.GetContactFromReceptionIdentity))
 	js.Global().Set("GetIDFromContact",
 		js.FuncOf(wasm.GetIDFromContact))
 	js.Global().Set("GetPubkeyFromContact",
diff --git a/wasm/identity.go b/wasm/identity.go
index 9ea9ab10..84376900 100644
--- a/wasm/identity.go
+++ b/wasm/identity.go
@@ -11,6 +11,7 @@ package wasm
 
 import (
 	"gitlab.com/elixxir/client/bindings"
+	"gitlab.com/elixxir/client/xxdk"
 	"syscall/js"
 )
 
@@ -109,6 +110,27 @@ func (c *Cmix) GetReceptionRegistrationValidationSignature(
 // Contact Functions                                                          //
 ////////////////////////////////////////////////////////////////////////////////
 
+// GetContactFromReceptionIdentity returns the [contact.Contact] object from the
+// [xxdk.ReceptionIdentity].
+//
+// Parameters:
+//  - args[0] - JSON of [xxdk.ReceptionIdentity] (Uint8Array)
+//
+// Returns:
+//  - Marshalled bytes of [contact.Contact] (string)
+//  - Throws a TypeError if unmarshalling the identity fails
+func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) interface{} {
+	// Note that this function does not appear in normal bindings
+	identityJSON := CopyBytesToGo(args[0])
+	identity, err := xxdk.UnmarshalReceptionIdentity(identityJSON)
+	if err != nil {
+		Throw(TypeError, err)
+		return nil
+	}
+
+	return CopyBytesToJS(identity.GetContact().Marshal())
+}
+
 // GetIDFromContact returns the ID in the [contact.Contact] object.
 //
 // Parameters:
-- 
GitLab