From 89b0a32a69d8060a03fd5cae724240470ce2cd6e Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Wed, 28 Sep 2022 10:14:48 -0700 Subject: [PATCH] Fix comments --- Makefile | 1 + wasm/authenticatedConnection.go | 8 ++++-- wasm/channels.go | 49 ++++++++++++--------------------- wasm/connect.go | 6 ++-- wasm/e2eHandler.go | 4 +-- wasm/follow.go | 3 +- wasm/group.go | 6 ++-- wasm/ndf.go | 6 ++-- 8 files changed, 39 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index ef9bc2a6..c899add2 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ update_release: update_master: GOFLAGS="" go get -d gitlab.com/elixxir/client@master GOFLAGS="" go get gitlab.com/elixxir/crypto@master + GOFLAGS="" go get gitlab.com/elixxir/primitives@master GOFLAGS="" go get gitlab.com/xx_network/primitives@master binary: diff --git a/wasm/authenticatedConnection.go b/wasm/authenticatedConnection.go index 8b2d03f2..c18f48d0 100644 --- a/wasm/authenticatedConnection.go +++ b/wasm/authenticatedConnection.go @@ -68,10 +68,11 @@ func (ac *AuthenticatedConnection) GetId(js.Value, []js.Value) interface{} { // [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). // - Rejected with an error if sending fails. func (ac *AuthenticatedConnection) SendE2E(_ js.Value, args []js.Value) interface{} { - payload := utils.CopyBytesToGo(args[2]) + mt := args[0].Int() + payload := utils.CopyBytesToGo(args[1]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - sendReport, err := ac.api.SendE2E(args[0].Int(), payload) + sendReport, err := ac.api.SendE2E(mt, payload) if err != nil { reject(utils.JsTrace(err)) } else { @@ -135,12 +136,13 @@ func (ac *AuthenticatedConnection) RegisterListener( // - Resolves to a Javascript representation of the [Connection] object. // - Rejected with an error if loading the parameters or connecting fails. func (c *Cmix) ConnectWithAuthentication(_ js.Value, args []js.Value) interface{} { + e2eID := args[0].Int() recipientContact := utils.CopyBytesToGo(args[1]) e2eParamsJSON := utils.CopyBytesToGo(args[2]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { ac, err := c.api.ConnectWithAuthentication( - args[0].Int(), recipientContact, e2eParamsJSON) + e2eID, recipientContact, e2eParamsJSON) if err != nil { reject(utils.JsTrace(err)) } else { diff --git a/wasm/channels.go b/wasm/channels.go index f93a95c5..024d31c0 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -10,7 +10,6 @@ package wasm import ( - "gitlab.com/elixxir/client/channels" "syscall/js" "gitlab.com/elixxir/client/bindings" @@ -135,7 +134,9 @@ type eventModelBuilder struct { build func(args ...interface{}) js.Value } -// Build initializes and returns the event model. +// Build initializes and returns the event model. It wraps a Javascript object +// that has all the methods in [bindings.EventModel] to make it adhere to the Go +// interface [bindings.EventModel]. func (emb *eventModelBuilder) Build(path string) bindings.EventModel { emJs := emb.build(path) return &eventModel{ @@ -233,21 +234,12 @@ func LoadChannelsManager(_ js.Value, args []js.Value) interface{} { // - Resolves to a Javascript representation of the [ChannelsManager] object. // - Rejected with an error if loading indexedDb or the manager fails. func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { + cmixID := args[0].Int() privateIdentity := utils.CopyBytesToGo(args[1]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - emBuilder := func(path string) channels.EventModel { - em, err := indexedDb.NewWasmEventModel(path) - if err != nil { - reject(utils.JsTrace(err)) - return nil - } - - return em - } - cm, err := bindings.NewChannelsManagerGoEventModel( - args[0].Int(), privateIdentity, emBuilder) + cmixID, privateIdentity, indexedDb.NewWasmEventModel) if err != nil { reject(utils.JsTrace(err)) } else { @@ -276,19 +268,12 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { // - Resolves to a Javascript representation of the [ChannelsManager] object. // - Rejected with an error if loading indexedDb or the manager fails. func LoadChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - emBuilder := func(path string) channels.EventModel { - em, err := indexedDb.NewWasmEventModel(path) - if err != nil { - reject(utils.JsTrace(err)) - return nil - } - - return em - } + cmixID := args[0].Int() + storageTag := args[1].String() + promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { cm, err := bindings.LoadChannelsManagerGoEventModel( - args[0].Int(), args[1].String(), emBuilder) + cmixID, storageTag, indexedDb.NewWasmEventModel) if err != nil { reject(utils.JsTrace(err)) } else { @@ -569,15 +554,15 @@ func (ch *ChannelsManager) SendMessage(_ js.Value, args []js.Value) interface{} return utils.CreatePromise(promiseFn) } -// SendReply is used to send a formatted message over a channel. -// Due to the underlying encoding using compression, it isn't possible to define -// the largest payload that can be sent, but it will always be possible to send -// a payload of 766 bytes at minimum. +// SendReply is used to send a formatted message over a channel. Due to the +// underlying encoding using compression, it isn't possible to define the +// largest payload that can be sent, but it will always be possible to send a +// payload of 766 bytes at minimum. // -// If the message ID the reply is sent to does not exist, then the other side -// will post the message as a normal message and not a reply. -// The message will auto delete validUntil after the round it is sent in, -// lasting forever if ValidForever is used. +// If the message ID the reply is sent to is nonexistent, the other side will +// post the message as a normal message and not a reply. The message will auto +// delete validUntil after the round it is sent in, lasting forever if +// [channels.ValidForever] is used. // // Parameters: // - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). diff --git a/wasm/connect.go b/wasm/connect.go index e3bc1331..cd3cce95 100644 --- a/wasm/connect.go +++ b/wasm/connect.go @@ -61,11 +61,12 @@ func (c *Connection) GetId(js.Value, []js.Value) interface{} { // - Resolves to a Javascript representation of the [Connection] object. // - Rejected with an error if loading the parameters or connecting fails. func (c *Cmix) Connect(_ js.Value, args []js.Value) interface{} { + e2eID := args[0].Int() recipientContact := utils.CopyBytesToGo(args[1]) e2eParamsJSON := utils.CopyBytesToGo(args[2]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - api, err := c.api.Connect(args[0].Int(), recipientContact, e2eParamsJSON) + api, err := c.api.Connect(e2eID, recipientContact, e2eParamsJSON) if err != nil { reject(utils.JsTrace(err)) } else { @@ -92,10 +93,11 @@ func (c *Cmix) Connect(_ js.Value, args []js.Value) interface{} { // into [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). // - Rejected with an error if sending fails. func (c *Connection) SendE2E(_ js.Value, args []js.Value) interface{} { + e2eID := args[0].Int() payload := utils.CopyBytesToGo(args[1]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - sendReport, err := c.api.SendE2E(args[0].Int(), payload) + sendReport, err := c.api.SendE2E(e2eID, payload) if err != nil { reject(utils.JsTrace(err)) } else { diff --git a/wasm/e2eHandler.go b/wasm/e2eHandler.go index 1929b353..556f9699 100644 --- a/wasm/e2eHandler.go +++ b/wasm/e2eHandler.go @@ -170,13 +170,13 @@ func (e *E2e) RemoveService(_ js.Value, args []js.Value) interface{} { // into [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). // - Rejected with an error if sending fails. func (e *E2e) SendE2E(_ js.Value, args []js.Value) interface{} { + mt := args[0].Int() recipientId := utils.CopyBytesToGo(args[1]) payload := utils.CopyBytesToGo(args[2]) e2eParams := utils.CopyBytesToGo(args[3]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - sendReport, err := e.api.SendE2E( - args[0].Int(), recipientId, payload, e2eParams) + sendReport, err := e.api.SendE2E(mt, recipientId, payload, e2eParams) if err != nil { reject(utils.JsTrace(err)) } else { diff --git a/wasm/follow.go b/wasm/follow.go index f794aa60..62725063 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -91,8 +91,9 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { // - A promise that resolves if the network is healthy and rejects if the // network is not healthy. func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} { + timeoutMS := args[0].Int() promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - if c.api.WaitForNetwork(args[0].Int()) { + if c.api.WaitForNetwork(timeoutMS) { resolve() } else { reject() diff --git a/wasm/group.go b/wasm/group.go index 31c031af..ebe3b6aa 100644 --- a/wasm/group.go +++ b/wasm/group.go @@ -113,8 +113,9 @@ func (g *GroupChat) MakeGroup(_ js.Value, args []js.Value) interface{} { // into [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). // - Rejected with an error if resending the request fails. func (g *GroupChat) ResendRequest(_ js.Value, args []js.Value) interface{} { + groupId := utils.CopyBytesToGo(args[0]) promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - sendReport, err := g.api.ResendRequest(utils.CopyBytesToGo(args[0])) + sendReport, err := g.api.ResendRequest(groupId) if err != nil { reject(utils.JsTrace(err)) } else { @@ -181,9 +182,10 @@ func (g *GroupChat) LeaveGroup(_ js.Value, args []js.Value) interface{} { func (g *GroupChat) Send(_ js.Value, args []js.Value) interface{} { groupId := utils.CopyBytesToGo(args[0]) message := utils.CopyBytesToGo(args[1]) + tag := args[2].String() promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - sendReport, err := g.api.Send(groupId, message, args[2].String()) + sendReport, err := g.api.Send(groupId, message, tag) if err != nil { reject(utils.JsTrace(err)) } else { diff --git a/wasm/ndf.go b/wasm/ndf.go index 0d99bc9e..8e84254b 100644 --- a/wasm/ndf.go +++ b/wasm/ndf.go @@ -28,9 +28,11 @@ import ( // - Resolves to the JSON of the NDF ([ndf.NetworkDefinition]) (Uint8Array). // - Rejected with an error if downloading fails. func DownloadAndVerifySignedNdfWithUrl(_ js.Value, args []js.Value) interface{} { + url := args[0].String() + cert := args[1].String() + promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { - ndf, err := bindings.DownloadAndVerifySignedNdfWithUrl( - args[0].String(), args[1].String()) + ndf, err := bindings.DownloadAndVerifySignedNdfWithUrl(url, cert) if err != nil { reject(utils.JsTrace(err)) } else { -- GitLab