From ff008f17e847da6f0962010c7dd91b8d8988e9ed Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Fri, 21 Oct 2022 19:10:14 -0700
Subject: [PATCH] Finish implementing ChannelDbCipher methods

---
 go.mod           |  2 +-
 go.sum           |  4 ++--
 wasm/channels.go | 30 ++++++++++++++++++++----------
 wasm_test.go     |  7 ++++---
 4 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/go.mod b/go.mod
index 9f0fa882..24f71d5f 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ require (
 	github.com/hack-pad/go-indexeddb v0.2.0
 	github.com/pkg/errors v0.9.1
 	github.com/spf13/jwalterweatherman v1.1.0
-	gitlab.com/elixxir/client v1.5.1-0.20221022003714-8980452f25e5
+	gitlab.com/elixxir/client v1.5.1-0.20221022020343-af368242bb1e
 	gitlab.com/elixxir/crypto v0.0.7-0.20221022003355-d8a6158b32a7
 	gitlab.com/elixxir/primitives v0.0.3-0.20221017172918-6176818d1aba
 	gitlab.com/xx_network/crypto v0.0.5-0.20221017172404-b384a8d8b171
diff --git a/go.sum b/go.sum
index 9ac20560..1ab9e902 100644
--- a/go.sum
+++ b/go.sum
@@ -616,8 +616,8 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
 github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
 gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40=
 gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
-gitlab.com/elixxir/client v1.5.1-0.20221022003714-8980452f25e5 h1:8SsC+GZYTZBDMn47OpSBc1kRVvFpx0IYZG6B8sL9BzU=
-gitlab.com/elixxir/client v1.5.1-0.20221022003714-8980452f25e5/go.mod h1:a5pLHWVKdwacbyL9yGlV/xP5xHbhC2ycqTbEsDyzjo4=
+gitlab.com/elixxir/client v1.5.1-0.20221022020343-af368242bb1e h1:30XqsYQCvNarkq9GT3wm9UL/o00VPcPzi5hKvha5e4M=
+gitlab.com/elixxir/client v1.5.1-0.20221022020343-af368242bb1e/go.mod h1:a5pLHWVKdwacbyL9yGlV/xP5xHbhC2ycqTbEsDyzjo4=
 gitlab.com/elixxir/comms v0.0.4-0.20221017173926-4eaa6061dfaa h1:/FEpu0N0rAyq74FkvO3uY8BcQoWLSbVPhj/s5QfscZw=
 gitlab.com/elixxir/comms v0.0.4-0.20221017173926-4eaa6061dfaa/go.mod h1:rW7xdbHntP2MoF3q+2+f+IR8OHol94MRyviotfR5rXg=
 gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
diff --git a/wasm/channels.go b/wasm/channels.go
index 8391e2fc..6b0f3fb2 100644
--- a/wasm/channels.go
+++ b/wasm/channels.go
@@ -1290,6 +1290,7 @@ type ChannelDbCipher struct {
 func newChannelDbCipherJS(api *bindings.ChannelDbCipher) map[string]interface{} {
 	c := ChannelDbCipher{api}
 	channelDbCipherMap := map[string]interface{}{
+		"GetID":   js.FuncOf(c.GetID),
 		"Encrypt": js.FuncOf(c.Encrypt),
 		"Decrypt": js.FuncOf(c.Decrypt),
 	}
@@ -1303,12 +1304,12 @@ func newChannelDbCipherJS(api *bindings.ChannelDbCipher) map[string]interface{}
 //  - args[0] - The tracked [Cmix] object ID (int).
 //  - args[1] - The password for storage. This should be the same password
 //    passed into [NewCmix] (Uint8Array).
-//  - args[2] - The maximum size of a payload to be encrypted.
-//    A payload passed into [ChannelDbCipher.Encrypt] that is larger than
-//    this value will result in an error (int).
+//  - args[2] - The maximum size of a payload to be encrypted. A payload passed
+//    into [ChannelDbCipher.Encrypt] that is larger than this value will result
+//    in an error (int).
 //
 // Returns:
-//   - A JavaScript representation of the [ChannelDbCipher].
+//   - JavaScript representation of the [ChannelDbCipher] object.
 //   - Throws a TypeError if creating the cipher fails.
 func NewChannelsDatabaseCipher(_ js.Value, args []js.Value) interface{} {
 	cmixId := args[0].Int()
@@ -1325,13 +1326,22 @@ func NewChannelsDatabaseCipher(_ js.Value, args []js.Value) interface{} {
 	return newChannelDbCipherJS(cipher)
 }
 
+// GetID returns the ID for this [bindings.ChannelDbCipher] in the
+// channelDbCipherTracker.
+//
+// Returns:
+//  - Tracker ID (int).
+func (c *ChannelDbCipher) GetID(js.Value, []js.Value) interface{} {
+	return c.api.GetID()
+}
+
 // Encrypt will encrypt the raw data. It will return a ciphertext. Padding is
 // done on the plaintext so all encrypted data looks uniform at rest.
 //
 // Parameters:
-//  - args[0] - The data to be encrypted (Uint8Array). This must be smaller than the block
-//    size passed into [NewChannelsDatabaseCipher]. If it is larger, this will
-//    return an error.
+//  - args[0] - The data to be encrypted (Uint8Array). This must be smaller than
+//    the block size passed into [NewChannelsDatabaseCipher]. If it is larger,
+//    this will return an error.
 //
 // Returns:
 //   - The ciphertext of the plaintext passed in (Uint8Array).
@@ -1348,9 +1358,9 @@ func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) interface{} {
 
 }
 
-// Decrypt will decrypt the passed in encrypted value. The plaintext will
-// be returned by this function. Any padding will be discarded within
-// this function.
+// Decrypt will decrypt the passed in encrypted value. The plaintext will be
+// returned by this function. Any padding will be discarded within this
+// function.
 //
 // Parameters:
 //  - args[0] - the encrypted data returned by [ChannelDbCipher.Encrypt]
diff --git a/wasm_test.go b/wasm_test.go
index 1b25d222..55a5e6b5 100644
--- a/wasm_test.go
+++ b/wasm_test.go
@@ -25,9 +25,10 @@ func TestPublicFunctions(t *testing.T) {
 	// not implemented.
 	excludeList := map[string]struct{}{
 		// Notifications are not available in the browser
-		"GetNotificationsReport":     {},
-		"RegisterForNotifications":   {},
-		"UnregisterForNotifications": {},
+		"GetNotificationsReport":          {},
+		"RegisterForNotifications":        {},
+		"UnregisterForNotifications":      {},
+		"GetChannelDbCipherTrackerFromID": {},
 
 		// UD not available in the browser
 		"IsRegisteredWithUD":     {},
-- 
GitLab