diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 009f68b17dfca9079974b2997ff1ccfb530274ca..ba4f4a4b7894a65da5d08fefc3473e0823ca8f03 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,7 @@ before_script: - git config --global url."git@$GITLAB_SERVER:".insteadOf "https://gitlab.com/" - git config --global url."git@$GITLAB_SERVER:".insteadOf "https://git.xx.network/" --add - export PATH=$HOME/go/bin:$PATH + - export GOPATH=$HOME/go/bin stages: - test @@ -43,6 +44,13 @@ wasm-test: script: - export PATH=/root/go/bin:$PATH - echo > utils/utils_js.s + - env + # - go install github.com/agnivade/wasmbrowsertest@latest + # - mv ~/go/bin/go_js_wasm_exec ~/go/bin/go_js_wasm_exec.old + # - ln -s ~/go/bin/wasmbrowsertest ~/go/bin/go_js_wasm_exec + - go mod vendor + - unset SSH_PRIVATE_KEY + - unset $(env | grep '=' | awk -F= '{print $1}' | grep -v PATH | grep -v GO | grep -v HOME) - GOOS=js GOARCH=wasm go test ./indexedDb/... -v - GOOS=js GOARCH=wasm go test ./... -v diff --git a/go.mod b/go.mod index cb87442b18463fb130c165fe63925e8cf19adfa8..1379077e000e6fabdf6861c1f9fe9183eb154bc0 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/v4 v4.3.12-0.20230110185314-82ca3757fce2 + gitlab.com/elixxir/client/v4 v4.3.12-0.20230110204625-5e87b36e0b21 gitlab.com/elixxir/crypto v0.0.7-0.20230109232445-64f3e6192c3a gitlab.com/elixxir/primitives v0.0.3-0.20230109222259-f62b2a90b62c gitlab.com/xx_network/crypto v0.0.5-0.20230109222209-557b66d73c33 diff --git a/go.sum b/go.sum index 6ff2022ebe45d1e29bb16baf696a28897a28a9d0..2f9c317d5886266af15f74ce38d69feb9ab6e679 100644 --- a/go.sum +++ b/go.sum @@ -538,8 +538,8 @@ gitlab.com/elixxir/client/v4 v4.3.12-0.20230110005723-f1f098321618 h1:+c0UuBvYLD gitlab.com/elixxir/client/v4 v4.3.12-0.20230110005723-f1f098321618/go.mod h1:03CuoZNfVcZAbD0IrX/FxOMMwaKUWCMeMWE6781ZDIg= gitlab.com/elixxir/client/v4 v4.3.12-0.20230110180417-0d004a4f5e76 h1:bGoexH1EmYQHLwsbIUNAxEnQnUQKnEEApYseN7Bh8jk= gitlab.com/elixxir/client/v4 v4.3.12-0.20230110180417-0d004a4f5e76/go.mod h1:03CuoZNfVcZAbD0IrX/FxOMMwaKUWCMeMWE6781ZDIg= -gitlab.com/elixxir/client/v4 v4.3.12-0.20230110185314-82ca3757fce2 h1:WtaVwWCjdx7eYhE0YfSIqfy1BuuBVAk/fbWdHfYMzpA= -gitlab.com/elixxir/client/v4 v4.3.12-0.20230110185314-82ca3757fce2/go.mod h1:03CuoZNfVcZAbD0IrX/FxOMMwaKUWCMeMWE6781ZDIg= +gitlab.com/elixxir/client/v4 v4.3.12-0.20230110204625-5e87b36e0b21 h1:bhy3C9LwRBvCmMsmVH1n80+yagaQ6ONJniIrHcmw8V0= +gitlab.com/elixxir/client/v4 v4.3.12-0.20230110204625-5e87b36e0b21/go.mod h1:03CuoZNfVcZAbD0IrX/FxOMMwaKUWCMeMWE6781ZDIg= gitlab.com/elixxir/comms v0.0.4-0.20230109184457-e10f20295430 h1:OydFdoBbLz5iFzCiYEb+m8Q2pZjdVVCne4m+MyFAzUc= gitlab.com/elixxir/comms v0.0.4-0.20230109184457-e10f20295430/go.mod h1:aFnxDpIxEEFHdAa2dEeydzo00u/IAcfrqPSEnmeffbY= gitlab.com/elixxir/comms v0.0.4-0.20230109233320-a0c90d3324a0 h1:jMmI+j4P5e+nmf82xKs679M6EzeuUhQJjOwXhXi6Cl0= diff --git a/storage/version.go b/storage/version.go index 9530aca55472b737e1905fe233f70a78689a52b5..d513092819786e1a13a1d36fc52464f5c402df94 100644 --- a/storage/version.go +++ b/storage/version.go @@ -18,7 +18,7 @@ import ( ) // SEMVER is the current semantic version of xxDK WASM. -const SEMVER = "0.1.13" +const SEMVER = "0.1.14" // Storage keys. const ( diff --git a/wasm/channels.go b/wasm/channels.go index d32737321c0efbab9ff732917b185a7b2cfbea99..2535e7c0965eed81a1ac6f939d75812732d16042 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -626,9 +626,9 @@ func GetChannelInfo(_ js.Value, args []js.Value) any { // 1 = private, and 2 = secret. Refer to the comment below for more // information. // -// Returns: -// - The pretty print of the channel (string). -// - Throws a TypeError if generating the channel fails. +// Returns a promise: +// - Resolves to the pretty print of the channel (string). +// - Rejected with an error if generating the channel fails. // // The [broadcast.PrivacyLevel] of a channel indicates the level of channel // information revealed when sharing it via URL. For any channel besides public @@ -640,14 +640,21 @@ func GetChannelInfo(_ js.Value, args []js.Value) any { // description. // - A privacy level of [broadcast.Secret] reveals nothing. func (cm *ChannelsManager) GenerateChannel(_ js.Value, args []js.Value) any { - prettyPrint, err := cm.api.GenerateChannel( - args[0].String(), args[1].String(), args[2].Int()) - if err != nil { - utils.Throw(utils.TypeError, err) - return nil + name := args[0].String() + description := args[1].String() + privacyLevel := args[2].Int() + + promiseFn := func(resolve, reject func(args ...any) js.Value) { + prettyPrint, err := + cm.api.GenerateChannel(name, description, privacyLevel) + if err != nil { + reject(utils.JsTrace(err)) + } else { + resolve(prettyPrint) + } } - return prettyPrint + return utils.CreatePromise(promiseFn) } // JoinChannel joins the given channel. It will return the error diff --git a/wasm/cmix.go b/wasm/cmix.go index cd994706e956c7a3f618cb50aa6d25b83097e73c..88c9853db7654fb065ab91a6fa9b0dc1fcbddd54 100644 --- a/wasm/cmix.go +++ b/wasm/cmix.go @@ -83,19 +83,25 @@ func newCmixJS(api *bindings.Cmix) map[string]any { // - args[2] - Password used for storage (Uint8Array). // - args[3] - Registration code (string). // -// Returns: -// - Throws a TypeError if creating new [Cmix] fails. +// Returns a promise: +// - Resolves on success. +// - Rejected with an error if creating a new cMix client fails. func NewCmix(_ js.Value, args []js.Value) any { + ndfJSON := args[0].String() + storageDir := args[1].String() password := utils.CopyBytesToGo(args[2]) + registrationCode := args[3].String() - err := bindings.NewCmix( - args[0].String(), args[1].String(), password, args[3].String()) - if err != nil { - utils.Throw(utils.TypeError, err) - return nil + promiseFn := func(resolve, reject func(args ...any) js.Value) { + err := bindings.NewCmix(ndfJSON, storageDir, password, registrationCode) + if err != nil { + reject(utils.JsTrace(err)) + } else { + resolve() + } } - return nil + return utils.CreatePromise(promiseFn) } // LoadCmix will load an existing user storage from the storageDir using the