diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c41159f924cc7f38ff21c065411316bd18fcb8c..e1a8ef567bb5b16fa78d4bf6b5537c5103d45dc9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,24 +49,24 @@ go-test: - go test ./... -v version_check: - stage: version_check - only: - - master - - release - image: $DOCKER_IMAGE - script: - - GITTAG=$(git describe --tags) - - CODEVERS=$(cat utils/version.go | grep "const SEMVER =" | cut -d ' ' -f4 | tr -d '"') - - if [[ $GITTAG != $CODEVERS ]]; then echo "VERSION NUMBER BAD $GITTAG != $CODEVER"; exit -1; fi + stage: version_check + only: + - master + - release + image: $DOCKER_IMAGE + script: + - GITTAG=$(git describe --tags) + - CODEVERS=$(cat utils/version.go | grep "const SEMVER =" | cut -d ' ' -f4 | tr -d '"') + - if [[ $GITTAG != $CODEVERS ]]; then echo "VERSION NUMBER BAD $GITTAG != $CODEVER"; exit -1; fi tag: - stage: build - image: $DOCKER_IMAGE - script: - - git remote add origin_tags git@$GITLAB_SERVER:elixxir/xxdk-wasm.git || true - - GOOS=js GOARCH=wasm go build -ldflags '-w -s' -o release/xxdk.wasm main.go - - git tag $(sha256sum release/xxdk.wasm | awk '{ print $1 }') -f - - git push origin_tags -f --tags + stage: build + image: $DOCKER_IMAGE + script: + - git remote add origin_tags git@$GITLAB_SERVER:elixxir/xxdk-wasm.git || true + - GOOS=js GOARCH=wasm go build -ldflags '-w -s' -o release/xxdk.wasm main.go + - git tag $(sha256sum release/xxdk.wasm | awk '{ print $1 }') -f + - git push origin_tags -f --tags # This pipeline job will attempt to have pkg.go.dev update docs for xxdk-wasm. # diff --git a/cryptobench_test.go b/cryptobench_test.go index dcb8c7e7a51ad97eec9d7a0d2e8faa891a6c1fad..76f9fc166c674992bdb8516bd8b82940ee2fa889 100644 --- a/cryptobench_test.go +++ b/cryptobench_test.go @@ -44,7 +44,7 @@ import ( // if session.Cmp(sessionExpected) != 0 { // t.Errorf("Session key generated on attempt %v incorrect;"+ -// "\n\tExpected: %s \n\tRecieved: %s \n\tPrivate key: %s", i, +// "\n\tExpected: %s \n\tReceived: %s \n\tPrivate key: %s", i, // sessionExpected.TextVerbose(16, 0), // session.TextVerbose(16, 0), // privKey.TextVerbose(16, 0)) @@ -61,21 +61,21 @@ func BenchmarkCreateDHSessionKey(b *testing.B) { g := large.NewInt(2) grp := cyclic.NewGroup(p, g) - pubkeys := make([]*cyclic.Int, b.N) - privkeys := make([]*cyclic.Int, b.N) + pubKeys := make([]*cyclic.Int, b.N) + privKeys := make([]*cyclic.Int, b.N) rng := csprng.NewSystemRNG() for i := 0; i < b.N; i++ { // Creation of two different DH Key Pairs with valid parameters - privkeys[i] = dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, rng) + privKeys[i] = dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, rng) tmpPrivKey := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, rng) - pubkeys[i] = dh.GeneratePublicKey(tmpPrivKey, grp) + pubKeys[i] = dh.GeneratePublicKey(tmpPrivKey, grp) } b.ResetTimer() for i := 0; i < b.N; i++ { - dh.GenerateSessionKey(privkeys[i], pubkeys[i], grp) + dh.GenerateSessionKey(privKeys[i], pubKeys[i], grp) } } diff --git a/indexedDb/implementation_test.go b/indexedDb/implementation_test.go index 865df50f436f8f7d94f0d38ccf7077e8851429a7..511a022b6c6257f6e8c5877c7be914addedd725d 100644 --- a/indexedDb/implementation_test.go +++ b/indexedDb/implementation_test.go @@ -264,7 +264,8 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) { } // Ensure index is unique - txn, err := eventModel.db.Transaction(idb.TransactionReadOnly, messageStoreName) + txn, err := eventModel.db.Transaction( + idb.TransactionReadOnly, messageStoreName) if err != nil { t.Fatal(err) } @@ -276,10 +277,10 @@ func TestWasmModel_receiveHelper_UniqueIndex(t *testing.T) { if err != nil { t.Fatal(err) } - if isUnique, err := idx.Unique(); !isUnique { + if isUnique, err2 := idx.Unique(); !isUnique { t.Fatalf("Index is not unique!") - } else if err != nil { - t.Fatal(err) + } else if err2 != nil { + t.Fatal(err2) } // First message insert should succeed diff --git a/storage/localStorage.go b/storage/localStorage.go index cf7aa2d22aeefb5dbac54c4c0d8ad71a04a6d573..d300e7fbdb02c4427bcb6be03fdd587e35630f82 100644 --- a/storage/localStorage.go +++ b/storage/localStorage.go @@ -38,10 +38,10 @@ type LocalStorage struct { // jsStorage is the global that stores Javascript as window.localStorage. // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage var jsStorage = newLocalStorage(localStorageWasmPrefix) // newLocalStorage creates a new LocalStorage object with the specified prefix. @@ -61,10 +61,10 @@ func GetLocalStorage() *LocalStorage { // os.ErrNotExist if the key does not exist. Underneath, it calls // localStorage.GetItem(). // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-getitem-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-getitem-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem func (ls *LocalStorage) GetItem(keyName string) ([]byte, error) { keyValue := ls.getItem(ls.prefix + keyName) if keyValue.IsNull() { @@ -82,10 +82,10 @@ func (ls *LocalStorage) GetItem(keyName string) ([]byte, error) { // SetItem adds a key's value to local storage given its name. Underneath, it // calls localStorage.SetItem(). // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-setitem-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-setitem-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem func (ls *LocalStorage) SetItem(keyName string, keyValue []byte) { encodedKeyValue := base64.StdEncoding.EncodeToString(keyValue) ls.setItem(ls.prefix+keyName, encodedKeyValue) @@ -95,10 +95,10 @@ func (ls *LocalStorage) SetItem(keyName string, keyValue []byte) { // is no item with the given key, this function does nothing. Underneath, it // calls localStorage.RemoveItem(). // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-removeitem-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-removeitem-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem func (ls *LocalStorage) RemoveItem(keyName string) { ls.removeItem(ls.prefix + keyName) } @@ -106,10 +106,10 @@ func (ls *LocalStorage) RemoveItem(keyName string) { // Clear clears all the keys in storage. Underneath, it calls // localStorage.clear(). // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-clear-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-clear-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Storage/clear func (ls *LocalStorage) Clear() { ls.clear() } @@ -151,10 +151,10 @@ func (ls *LocalStorage) ClearWASM() { // with the given key, this function does nothing. Underneath, it calls // localStorage.key(). // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Storage/key +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Storage/key func (ls *LocalStorage) Key(n int) (string, error) { keyName := ls.key(n) if keyName.IsNull() { @@ -181,10 +181,10 @@ func (ls *LocalStorage) Keys() []string { // Length returns the number of keys in localStorage. Underneath, it accesses // the property localStorage.length. // -// - Specification: -// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key-dev -// - Documentation: -// https://developer.mozilla.org/en-US/docs/Web/API/Storage/length +// - Specification: +// https://html.spec.whatwg.org/multipage/webstorage.html#dom-storage-key-dev +// - Documentation: +// https://developer.mozilla.org/en-US/docs/Web/API/Storage/length func (ls *LocalStorage) Length() int { return ls.length().Int() } diff --git a/storage/password.go b/storage/password.go index 6b838a1fd492d6a4e71b69ce815a21d07195865f..36175e1002dbe3343a32fa41a9af239a9e13a7aa 100644 --- a/storage/password.go +++ b/storage/password.go @@ -83,12 +83,12 @@ const ( // password. // // Parameters: -// - args[0] - The user supplied password (string). +// - args[0] - The user supplied password (string). // // Returns: -// - Internal password (Uint8Array). -// - Throws TypeError on failure. -func GetOrInitPassword(_ js.Value, args []js.Value) interface{} { +// - Internal password (Uint8Array). +// - Throws TypeError on failure. +func GetOrInitPassword(_ js.Value, args []js.Value) any { internalPassword, err := getOrInit(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -101,12 +101,12 @@ func GetOrInitPassword(_ js.Value, args []js.Value) interface{} { // ChangeExternalPassword allows a user to change their external password. // // Parameters: -// - args[0] - The user's old password (string). -// - args[1] - The user's new password (string). +// - args[0] - The user's old password (string). +// - args[1] - The user's new password (string). // // Returns: -// - Throws TypeError on failure. -func ChangeExternalPassword(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError on failure. +func ChangeExternalPassword(_ js.Value, args []js.Value) any { err := changeExternalPassword(args[0].String(), args[1].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -119,11 +119,11 @@ func ChangeExternalPassword(_ js.Value, args []js.Value) interface{} { // VerifyPassword determines if the user-provided password is correct. // // Parameters: -// - args[0] - The user supplied password (string). +// - args[0] - The user supplied password (string). // // Returns: -// - True if the password is correct and false if it is incorrect (boolean). -func VerifyPassword(_ js.Value, args []js.Value) interface{} { +// - True if the password is correct and false if it is incorrect (boolean). +func VerifyPassword(_ js.Value, args []js.Value) any { return verifyPassword(args[0].String()) } @@ -149,7 +149,8 @@ func getOrInit(externalPassword string) ([]byte, error) { // that is used for testing. func changeExternalPassword(oldExternalPassword, newExternalPassword string) error { localStorage := GetLocalStorage() - internalPassword, err := getInternalPassword(oldExternalPassword, localStorage) + internalPassword, err := getInternalPassword( + oldExternalPassword, localStorage) if err != nil { return err } diff --git a/storage/purge.go b/storage/purge.go index deb7577b2ab14ec07604e887d20e00bcfce2b991..025c36cfe7c59a58dd188c08bda1abb55705b5e7 100644 --- a/storage/purge.go +++ b/storage/purge.go @@ -42,15 +42,15 @@ func DecrementNumClientsRunning() { // password is required. // // Parameters: -// - args[0] - Storage directory path (string). This is the same directory path -// passed into [wasm.NewCmix]. +// - args[0] - Storage directory path (string). This is the same directory +// path passed into [wasm.NewCmix]. // - args[1] - The user-supplied password (string). This is the same password // passed into [wasm.NewCmix]. // // Returns: // - Throws a TypeError if the password is incorrect or if not all cMix // followers have been stopped. -func Purge(_ js.Value, args []js.Value) interface{} { +func Purge(_ js.Value, args []js.Value) any { storageDirectory := args[0].String() userPassword := args[1].String() diff --git a/storage/version_test.go b/storage/version_test.go index 596034090ba07fd5bcf71f42b44e16e9517774c5..a8ead72e52a53d9840936a7deb6865d9aa30f201 100644 --- a/storage/version_test.go +++ b/storage/version_test.go @@ -73,8 +73,8 @@ func Test_checkAndStoreVersions(t *testing.T) { } } -// Tests that initOrLoadStoredSemver initialises the correct version on first run -// and returns the same version on subsequent runs. +// Tests that initOrLoadStoredSemver initialises the correct version on first +// run and returns the same version on subsequent runs. func Test_initOrLoadStoredSemver(t *testing.T) { ls := GetLocalStorage() key := "testKey" diff --git a/utils/array.go b/utils/array.go index 5eda91f5d332c091cb6cd93397e21dd42d567b67..3597d0ba9cca229e1141c164d9e1204cf56c117a 100644 --- a/utils/array.go +++ b/utils/array.go @@ -18,23 +18,23 @@ import ( // Uint8ArrayToBase64 encodes an uint8 array to a base 64 string. // // Parameters: -// - args[0] - Javascript 8-bit unsigned integer array (Uint8Array). +// - args[0] - Javascript 8-bit unsigned integer array (Uint8Array). // // Returns: -// - Base 64 encoded string (string). -func Uint8ArrayToBase64(_ js.Value, args []js.Value) interface{} { +// - Base 64 encoded string (string). +func Uint8ArrayToBase64(_ js.Value, args []js.Value) any { return base64.StdEncoding.EncodeToString(CopyBytesToGo(args[0])) } // Base64ToUint8Array decodes a base 64 encoded string to a Uint8Array. // // Parameters: -// - args[0] - Base 64 encoded string (string). +// - args[0] - Base 64 encoded string (string). // // Returns: -// - Javascript 8-bit unsigned integer array (Uint8Array). -// - Throws TypeError if decoding the string fails. -func Base64ToUint8Array(_ js.Value, args []js.Value) interface{} { +// - Javascript 8-bit unsigned integer array (Uint8Array). +// - Throws TypeError if decoding the string fails. +func Base64ToUint8Array(_ js.Value, args []js.Value) any { b, err := base64ToUint8Array(args[0]) if err != nil { Throw(TypeError, err) @@ -58,12 +58,12 @@ func base64ToUint8Array(base64String js.Value) (js.Value, error) { // otherwise. // // Parameters: -// - args[0] - Array A (Uint8Array). -// - args[1] - Array B (Uint8Array). +// - args[0] - Array A (Uint8Array). +// - args[1] - Array B (Uint8Array). // // Returns: -// - If the two arrays are equal (boolean). -func Uint8ArrayEquals(_ js.Value, args []js.Value) interface{} { +// - If the two arrays are equal (boolean). +func Uint8ArrayEquals(_ js.Value, args []js.Value) any { a := CopyBytesToGo(args[0]) b := CopyBytesToGo(args[1]) diff --git a/utils/convert.go b/utils/convert.go index 121112045ebbf573655f68a30235921f53a455c1..0c2d443ecb16b9992b3f87805b4833935bdaeb2a 100644 --- a/utils/convert.go +++ b/utils/convert.go @@ -37,7 +37,7 @@ func JsToJson(value js.Value) string { // JsonToJS converts a JSON bytes input to a [js.Value] of the object subtype. func JsonToJS(inputJson []byte) (js.Value, error) { - var jsObj map[string]interface{} + var jsObj map[string]any err := json.Unmarshal(inputJson, &jsObj) if err != nil { return js.ValueOf(nil), err diff --git a/utils/convert_test.go b/utils/convert_test.go index 9193aa93f91a2a8871de431c4ed2a760eb86531d..8cbbf2555c307c782bb3f52168c12ec307633fd4 100644 --- a/utils/convert_test.go +++ b/utils/convert_test.go @@ -83,14 +83,14 @@ func TestCopyBytesToJSCopyBytesToGo(t *testing.T) { // Tests that JsToJson can convert a Javascript object to JSON that matches the // output of json.Marshal on the Go version of the same object. func TestJsToJson(t *testing.T) { - testObj := map[string]interface{}{ + testObj := map[string]any{ "nil": nil, "bool": true, "int": 1, "float": 1.5, "string": "I am string", - "array": []interface{}{1, 2, 3}, - "object": map[string]interface{}{"int": 5}, + "array": []any{1, 2, 3}, + "object": map[string]any{"int": 5}, } expected, err := json.Marshal(testObj) @@ -116,15 +116,15 @@ func TestJsToJson(t *testing.T) { // Tests that JsonToJS can convert a JSON object with multiple types to a // Javascript object and that all values match. func TestJsonToJS(t *testing.T) { - testObj := map[string]interface{}{ + testObj := map[string]any{ "nil": nil, "bool": true, "int": 1, "float": 1.5, "string": "I am string", "bytes": []byte{1, 2, 3}, - "array": []interface{}{1, 2, 3}, - "object": map[string]interface{}{"int": 5}, + "array": []any{1, 2, 3}, + "object": map[string]any{"int": 5}, } jsonData, err := json.Marshal(testObj) if err != nil { @@ -171,7 +171,7 @@ func TestJsonToJS(t *testing.T) { jsVal.String()) } case "array": - for i, v := range val.([]interface{}) { + for i, v := range val.([]any) { if jsVal.Index(i).Int() != v { t.Errorf("Incorrect value for key %s index %d."+ "\nexpected: %d\nreceived: %d", @@ -179,10 +179,10 @@ func TestJsonToJS(t *testing.T) { } } case "object": - if jsVal.Get("int").Int() != val.(map[string]interface{})["int"] { + if jsVal.Get("int").Int() != val.(map[string]any)["int"] { t.Errorf("Incorrect value for key %s."+ "\nexpected: %d\nreceived: %d", key, - val.(map[string]interface{})["int"], jsVal.Get("int").Int()) + val.(map[string]any)["int"], jsVal.Get("int").Int()) } } } @@ -191,15 +191,15 @@ func TestJsonToJS(t *testing.T) { // Tests that JSON can be converted to a Javascript object via JsonToJS and back // to JSON using JsToJson and matches the original. func TestJsonToJSJsToJson(t *testing.T) { - testObj := map[string]interface{}{ + testObj := map[string]any{ "nil": nil, "bool": true, "int": 1, "float": 1.5, "string": "I am string", "bytes": []byte{1, 2, 3}, - "array": []interface{}{1, 2, 3}, - "object": map[string]interface{}{"int": 5}, + "array": []any{1, 2, 3}, + "object": map[string]any{"int": 5}, } jsonData, err := json.Marshal(testObj) if err != nil { diff --git a/utils/utils.go b/utils/utils.go index c2ee6b41a73b8d65bab18a4c77881f5fccabdf4e..19399f5a62c5f41269739440d0a9948a7c244200 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -41,29 +41,27 @@ var ( // later with only the arguments and without specifying the function name. // // Panics if m is not a function. -func WrapCB(parent js.Value, m string) func(args ...interface{}) js.Value { +func WrapCB(parent js.Value, m string) func(args ...any) js.Value { if parent.Get(m).Type() != js.TypeFunction { // Create the error separate from the print so stack trace is printed err := errors.Errorf("Function %q is not of type %s", m, js.TypeFunction) jww.FATAL.Panicf("%+v", err) } - return func(args ...interface{}) js.Value { - return parent.Call(m, args...) - } + return func(args ...any) js.Value { return parent.Call(m, args...) } } // PromiseFn converts the Javascript Promise construct into Go. // // Call resolve with the return of the function on success. Call reject with an // error on failure. -type PromiseFn func(resolve, reject func(args ...interface{}) js.Value) +type PromiseFn func(resolve, reject func(args ...any) js.Value) // CreatePromise creates a Javascript promise to return the value of a blocking // Go function to Javascript. -func CreatePromise(f PromiseFn) interface{} { +func CreatePromise(f PromiseFn) any { // Create handler for promise (this will be a Javascript function) - handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + handler := js.FuncOf(func(this js.Value, args []js.Value) any { // Spawn a new go routine to perform the blocking function go func(resolve, reject js.Value) { f(resolve.Invoke, reject.Invoke) @@ -81,7 +79,7 @@ func CreatePromise(f PromiseFn) interface{} { func Await(awaitable js.Value) ([]js.Value, []js.Value) { then := make(chan []js.Value) defer close(then) - thenFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + thenFunc := js.FuncOf(func(this js.Value, args []js.Value) any { then <- args return nil }) @@ -89,7 +87,7 @@ func Await(awaitable js.Value) ([]js.Value, []js.Value) { catch := make(chan []js.Value) defer close(catch) - catchFunc := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + catchFunc := js.FuncOf(func(this js.Value, args []js.Value) any { catch <- args return nil }) diff --git a/wasm/authenticatedConnection.go b/wasm/authenticatedConnection.go index 89b2061cbd926a83cfe70cbbedfa95b81f615ef8..3308a9be32e8321c7d80c7fe5558c794407050b0 100644 --- a/wasm/authenticatedConnection.go +++ b/wasm/authenticatedConnection.go @@ -22,12 +22,11 @@ type AuthenticatedConnection struct { } // newAuthenticatedConnectionJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [AuthenticatedConnection] -// structure. +// (map[string]any) that matches the [AuthenticatedConnection] structure. func newAuthenticatedConnectionJS( - api *bindings.AuthenticatedConnection) map[string]interface{} { + api *bindings.AuthenticatedConnection) map[string]any { ac := AuthenticatedConnection{api} - acMap := map[string]interface{}{ + acMap := map[string]any{ "IsAuthenticated": js.FuncOf(ac.IsAuthenticated), "GetId": js.FuncOf(ac.GetId), "SendE2E": js.FuncOf(ac.SendE2E), @@ -42,8 +41,8 @@ func newAuthenticatedConnectionJS( // IsAuthenticated returns true. // // Returns: -// - True (boolean). -func (ac *AuthenticatedConnection) IsAuthenticated(js.Value, []js.Value) interface{} { +// - True (boolean). +func (ac *AuthenticatedConnection) IsAuthenticated(js.Value, []js.Value) any { return ac.api.IsAuthenticated() } @@ -51,8 +50,8 @@ func (ac *AuthenticatedConnection) IsAuthenticated(js.Value, []js.Value) interfa // authenticatedConnectionTracker. // // Returns: -// - Tracker ID (int). -func (ac *AuthenticatedConnection) GetId(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (ac *AuthenticatedConnection) GetId(js.Value, []js.Value) any { return ac.api.GetId() } @@ -60,18 +59,18 @@ func (ac *AuthenticatedConnection) GetId(js.Value, []js.Value) interface{} { // [AuthenticatedConnection]'s [partner.Manager]. // // Parameters: -// - args[0] - Message type from [catalog.MessageType] (int). -// - args[1] - Message payload (Uint8Array). +// - args[0] - Message type from [catalog.MessageType] (int). +// - args[1] - Message payload (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of [bindings.E2ESendReport], which can be passed into -// [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{} { +// - Resolves to the JSON of [bindings.E2ESendReport], which can be passed +// into [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) any { mt := args[0].Int() payload := utils.CopyBytesToGo(args[1]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := ac.api.SendE2E(mt, payload) if err != nil { reject(utils.JsTrace(err)) @@ -87,16 +86,16 @@ func (ac *AuthenticatedConnection) SendE2E(_ js.Value, args []js.Value) interfac // resources. // // Returns: -// - Throws a TypeError if closing fails. -func (ac *AuthenticatedConnection) Close(js.Value, []js.Value) interface{} { +// - Throws a TypeError if closing fails. +func (ac *AuthenticatedConnection) Close(js.Value, []js.Value) any { return ac.api.Close() } // GetPartner returns the [partner.Manager] for this [AuthenticatedConnection]. // // Returns: -// - Marshalled bytes of the partner's [id.ID] (Uint8Array). -func (ac *AuthenticatedConnection) GetPartner(js.Value, []js.Value) interface{} { +// - Marshalled bytes of the partner's [id.ID] (Uint8Array). +func (ac *AuthenticatedConnection) GetPartner(js.Value, []js.Value) any { return utils.CopyBytesToJS(ac.api.GetPartner()) } @@ -104,14 +103,14 @@ func (ac *AuthenticatedConnection) GetPartner(js.Value, []js.Value) interface{} // from the [partner.Manager]. // // Parameters: -// - args[0] - Message type from [catalog.MessageType] (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.Listener] interface. +// - args[0] - Message type from [catalog.MessageType] (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.Listener] interface. // // Returns: -// - Throws a TypeError is registering the listener fails. +// - Throws a TypeError is registering the listener fails. func (ac *AuthenticatedConnection) RegisterListener( - _ js.Value, args []js.Value) interface{} { + _ js.Value, args []js.Value) any { err := ac.api.RegisterListener(args[0].Int(), &listener{utils.WrapCB(args[1], "Hear"), utils.WrapCB(args[1], "Name")}) if err != nil { @@ -127,20 +126,20 @@ func (ac *AuthenticatedConnection) RegisterListener( // with the server, it then authenticates their identity to the server. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the recipient [contact.Contact] -// (Uint8Array). -// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the recipient [contact.Contact] +// (Uint8Array). +// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). // // Returns a promise: -// - 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{} { +// - 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) any { e2eID := args[0].Int() recipientContact := utils.CopyBytesToGo(args[1]) e2eParamsJSON := utils.CopyBytesToGo(args[2]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { ac, err := c.api.ConnectWithAuthentication( e2eID, recipientContact, e2eParamsJSON) if err != nil { diff --git a/wasm/backup.go b/wasm/backup.go index 96812639ac61b7e4c5320ff497c3b5330f7c1d00..9f5e7f6e7b302675ad8a385745dd645473961405 100644 --- a/wasm/backup.go +++ b/wasm/backup.go @@ -25,11 +25,11 @@ type Backup struct { api *bindings.Backup } -// newBackupJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [Backup] structure. -func newBackupJS(api *bindings.Backup) map[string]interface{} { +// newBackupJS creates a new Javascript compatible object (map[string]any) tha +// matches the [Backup] structure. +func newBackupJS(api *bindings.Backup) map[string]any { b := Backup{api} - backupMap := map[string]interface{}{ + backupMap := map[string]any{ "StopBackup": js.FuncOf(b.StopBackup), "IsBackupRunning": js.FuncOf(b.IsBackupRunning), "AddJson": js.FuncOf(b.AddJson), @@ -41,13 +41,13 @@ func newBackupJS(api *bindings.Backup) map[string]interface{} { // updateBackupFunc wraps Javascript callbacks to adhere to the // [bindings.UpdateBackupFunc] interface. type updateBackupFunc struct { - updateBackup func(args ...interface{}) js.Value + updateBackup func(args ...any) js.Value } // UpdateBackup is a function callback that returns new backups. // // Parameters: -// - encryptedBackup - Returns the bytes of the encrypted backup (Uint8Array). +// - encryptedBackup - Returns the bytes of the encrypted backup (Uint8Array). func (ubf *updateBackupFunc) UpdateBackup(encryptedBackup []byte) { ubf.updateBackup(utils.CopyBytesToJS(encryptedBackup)) } @@ -61,16 +61,16 @@ func (ubf *updateBackupFunc) UpdateBackup(encryptedBackup []byte) { // this function should call LoadCmix as normal once this call succeeds. // // Parameters: -// - args[0] - JSON of the NDF ([ndf.NetworkDefinition]) (string). -// - args[1] - Storage directory (string). -// - args[2] - Backup passphrase (string). -// - args[3] - Session password (Uint8Array). -// - args[4] - Backup file contents (Uint8Array). +// - args[0] - JSON of the NDF ([ndf.NetworkDefinition]) (string). +// - args[1] - Storage directory (string). +// - args[2] - Backup passphrase (string). +// - args[3] - Session password (Uint8Array). +// - args[4] - Backup file contents (Uint8Array). // // Returns: -// - JSON of [bindings.BackupReport] (Uint8Array). -// - Throws a TypeError if creating [Cmix] from backup fails. -func NewCmixFromBackup(_ js.Value, args []js.Value) interface{} { +// - JSON of [bindings.BackupReport] (Uint8Array). +// - Throws a TypeError if creating [Cmix] from backup fails. +func NewCmixFromBackup(_ js.Value, args []js.Value) any { ndfJSON := args[0].String() storageDir := args[1].String() backupPassphrase := args[2].String() @@ -94,18 +94,18 @@ func NewCmixFromBackup(_ js.Value, args []js.Value) interface{} { // InitializeBackup creates a bindings-layer [Backup] object. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - ID of [UserDiscovery] object in tracker (int). -// - args[2] - [Backup] passphrase provided by the user (string). Used to -// decrypt the backup. -// - args[3] - The callback to be called when a backup is triggered. Must be -// Javascript object that has functions that implement the -// [bindings.UpdateBackupFunc] interface. +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - ID of [UserDiscovery] object in tracker (int). +// - args[2] - [Backup] passphrase provided by the user (string). Used to +// decrypt the backup. +// - args[3] - The callback to be called when a backup is triggered. Must be +// Javascript object that has functions that implement the +// [bindings.UpdateBackupFunc] interface. // // Returns: -// - Javascript representation of the [Backup] object. -// - Throws a TypeError if initializing the [Backup] fails. -func InitializeBackup(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [Backup] object. +// - Throws a TypeError if initializing the [Backup] fails. +func InitializeBackup(_ js.Value, args []js.Value) any { cb := &updateBackupFunc{utils.WrapCB(args[3], "UpdateBackup")} api, err := bindings.InitializeBackup( args[0].Int(), args[1].Int(), args[2].String(), cb) @@ -124,17 +124,17 @@ func InitializeBackup(_ js.Value, args []js.Value) interface{} { // [InitializeBackup]. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - ID of [UserDiscovery] object in tracker (int). -// - args[2] - The callback to be called when a backup is triggered. Must be -// Javascript object that has functions that implement the -// [bindings.UpdateBackupFunc] interface. This will replace any callback that -// has been passed into [InitializeBackup]. +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - ID of [UserDiscovery] object in tracker (int). +// - args[2] - The callback to be called when a backup is triggered. Must be +// Javascript object that has functions that implement the +// [bindings.UpdateBackupFunc] interface. This will replace any callback +// that has been passed into [InitializeBackup]. // // Returns: -// - Javascript representation of the [Backup] object. -// - Throws a TypeError if initializing the [Backup] fails. -func ResumeBackup(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [Backup] object. +// - Throws a TypeError if initializing the [Backup] fails. +func ResumeBackup(_ js.Value, args []js.Value) any { cb := &updateBackupFunc{utils.WrapCB(args[2], "UpdateBackup")} api, err := bindings.ResumeBackup(args[0].Int(), args[1].Int(), cb) if err != nil { @@ -149,8 +149,8 @@ func ResumeBackup(_ js.Value, args []js.Value) interface{} { // storage. To enable backups again, call [InitializeBackup]. // // Returns: -// - Throws a TypeError if stopping the backup fails. -func (b *Backup) StopBackup(js.Value, []js.Value) interface{} { +// - Throws a TypeError if stopping the backup fails. +func (b *Backup) StopBackup(js.Value, []js.Value) any { err := b.api.StopBackup() if err != nil { utils.Throw(utils.TypeError, err) @@ -164,16 +164,16 @@ func (b *Backup) StopBackup(js.Value, []js.Value) interface{} { // running. Returns false if it has been stopped. // // Returns: -// - If the backup is running (boolean). -func (b *Backup) IsBackupRunning(js.Value, []js.Value) interface{} { +// - If the backup is running (boolean). +func (b *Backup) IsBackupRunning(js.Value, []js.Value) any { return b.api.IsBackupRunning() } // AddJson stores the argument within the [Backup] structure. // // Parameters: -// - args[0] - JSON to store (string). -func (b *Backup) AddJson(_ js.Value, args []js.Value) interface{} { +// - args[0] - JSON to store (string). +func (b *Backup) AddJson(_ js.Value, args []js.Value) any { b.api.AddJson(args[0].String()) return nil } diff --git a/wasm/channels.go b/wasm/channels.go index c6b697c35a9334018adaaee534a7d51a001a5a5f..3f050456837673b96c9cde14e5a528b309a3e2e7 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -31,10 +31,10 @@ type ChannelsManager struct { } // newChannelsManagerJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [ChannelsManager] structure. -func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]interface{} { +// (map[string]any) that matches the [ChannelsManager] structure. +func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]any { cm := ChannelsManager{api} - channelsManagerMap := map[string]interface{}{ + channelsManagerMap := map[string]any{ // Basic Channel API "GetID": js.FuncOf(cm.GetID), "JoinChannel": js.FuncOf(cm.JoinChannel), @@ -69,8 +69,8 @@ func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]interface{} // tracker. // // Returns: -// - Tracker ID (int). -func (ch *ChannelsManager) GetID(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (ch *ChannelsManager) GetID(js.Value, []js.Value) any { return ch.api.GetID() } @@ -79,12 +79,12 @@ func (ch *ChannelsManager) GetID(js.Value, []js.Value) interface{} { // via [GetPublicChannelIdentityFromPrivate]. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). +// - args[0] - ID of [Cmix] object in tracker (int). // // Returns: -// - Marshalled bytes of [channel.PrivateIdentity] (Uint8Array). -// - Throws a TypeError if generating the identity fails. -func GenerateChannelIdentity(_ js.Value, args []js.Value) interface{} { +// - Marshalled bytes of [channel.PrivateIdentity] (Uint8Array). +// - Throws a TypeError if generating the identity fails. +func GenerateChannelIdentity(_ js.Value, args []js.Value) any { pi, err := bindings.GenerateChannelIdentity(args[0].Int()) if err != nil { utils.Throw(utils.TypeError, err) @@ -101,13 +101,13 @@ var identityMap sync.Map // and codeset version. // // Parameters: -// - args[0] - The Ed25519 public key (Uint8Array). -// - args[1] - The version of the codeset used to generate the identity (int). +// - args[0] - The Ed25519 public key (Uint8Array). +// - args[1] - The version of the codeset used to generate the identity (int). // // Returns: -// - JSON of [channel.Identity] (Uint8Array). -// - Throws a TypeError if constructing the identity fails. -func ConstructIdentity(_ js.Value, args []js.Value) interface{} { +// - JSON of [channel.Identity] (Uint8Array). +// - Throws a TypeError if constructing the identity fails. +func ConstructIdentity(_ js.Value, args []js.Value) any { // Note: This function is similar to constructIdentity below except that it // uses a sync.Map backend to increase efficiency for identities that were // already generated in this browser session. @@ -135,13 +135,13 @@ func ConstructIdentity(_ js.Value, args []js.Value) interface{} { // and codeset version. This function is retain for benchmarking purposes. // // Parameters: -// - args[0] - The Ed25519 public key (Uint8Array). -// - args[1] - The version of the codeset used to generate the identity (int). +// - args[0] - The Ed25519 public key (Uint8Array). +// - args[1] - The version of the codeset used to generate the identity (int). // // Returns: -// - JSON of [channel.Identity] (Uint8Array). -// - Throws a TypeError if constructing the identity fails. -func constructIdentity(_ js.Value, args []js.Value) interface{} { +// - JSON of [channel.Identity] (Uint8Array). +// - Throws a TypeError if constructing the identity fails. +func constructIdentity(_ js.Value, args []js.Value) any { identity, err := bindings.ConstructIdentity( utils.CopyBytesToGo(args[0]), args[1].Int()) if err != nil { @@ -156,13 +156,13 @@ func constructIdentity(_ js.Value, args []js.Value) interface{} { // data. // // Parameters: -// - args[0] - The password used to encrypt the identity (string). -// - args[2] - The encrypted data (Uint8Array). +// - args[0] - The password used to encrypt the identity (string). +// - args[2] - The encrypted data (Uint8Array). // // Returns: -// - JSON of [channel.PrivateIdentity] (Uint8Array). -// - Throws a TypeError if importing the identity fails. -func ImportPrivateIdentity(_ js.Value, args []js.Value) interface{} { +// - JSON of [channel.PrivateIdentity] (Uint8Array). +// - Throws a TypeError if importing the identity fails. +func ImportPrivateIdentity(_ js.Value, args []js.Value) any { password := args[0].String() data := utils.CopyBytesToGo(args[1]) @@ -179,13 +179,13 @@ func ImportPrivateIdentity(_ js.Value, args []js.Value) interface{} { // from a bytes version and returns it JSON marshaled. // // Parameters: -// - args[0] - Bytes of the public identity ([channel.Identity]) (Uint8Array). +// - args[0] - Bytes of the public identity ([channel.Identity]) (Uint8Array). // // Returns: -// - JSON of the constructed [channel.Identity] (Uint8Array). -// - Throws a TypeError if unmarshalling the bytes or marshalling the identity -// fails. -func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} { +// - JSON of the constructed [channel.Identity] (Uint8Array). +// - Throws a TypeError if unmarshalling the bytes or marshalling the identity +// fails. +func GetPublicChannelIdentity(_ js.Value, args []js.Value) any { marshaledPublic := utils.CopyBytesToGo(args[0]) pi, err := bindings.GetPublicChannelIdentity(marshaledPublic) if err != nil { @@ -201,14 +201,14 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} { // ([channel.PrivateIdentity]). // // Parameters: -// - args[0] - Bytes of the private identity -// (channel.PrivateIdentity]) (Uint8Array). +// - args[0] - Bytes of the private identity +// (channel.PrivateIdentity]) (Uint8Array). // // Returns: -// - JSON of the public identity ([channel.Identity]) (Uint8Array). -// - Throws a TypeError if unmarshalling the bytes or marshalling the identity -// fails. -func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) interface{} { +// - JSON of the public identity ([channel.Identity]) (Uint8Array). +// - Throws a TypeError if unmarshalling the bytes or marshalling the identity +// fails. +func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) any { marshaledPrivate := utils.CopyBytesToGo(args[0]) identity, err := bindings.GetPublicChannelIdentityFromPrivate(marshaledPrivate) @@ -222,7 +222,7 @@ func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) interface{ // eventModelBuilder adheres to the [bindings.EventModelBuilder] interface. type eventModelBuilder struct { - build func(args ...interface{}) js.Value + build func(args ...any) js.Value } // Build initializes and returns the event model. It wraps a Javascript object @@ -249,18 +249,18 @@ func (emb *eventModelBuilder) Build(path string) bindings.EventModel { // storage tag retrieved by [ChannelsManager.GetStorageTag]. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved -// using [Cmix.GetID]. -// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is -// generated by [GenerateChannelIdentity] (Uint8Array). -// - args[2] - A function that initialises and returns a Javascript object that -// matches the [bindings.EventModel] interface. The function must match the -// Build function in [bindings.EventModelBuilder]. +// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved +// using [Cmix.GetID]. +// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is +// generated by [GenerateChannelIdentity] (Uint8Array). +// - args[2] - A function that initialises and returns a Javascript object +// that matches the [bindings.EventModel] interface. The function must match +// the Build function in [bindings.EventModelBuilder]. // // Returns: -// - Javascript representation of the [ChannelsManager] object. -// - Throws a TypeError if creating the manager fails. -func NewChannelsManager(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [ChannelsManager] object. +// - Throws a TypeError if creating the manager fails. +func NewChannelsManager(_ js.Value, args []js.Value) any { privateIdentity := utils.CopyBytesToGo(args[1]) em := &eventModelBuilder{args[2].Invoke} @@ -282,18 +282,18 @@ func NewChannelsManager(_ js.Value, args []js.Value) interface{} { // [ChannelsManager.GetStorageTag]. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved -// using [Cmix.GetID]. -// - args[1] - The storage tag associated with the previously created channel -// manager and retrieved with [ChannelsManager.GetStorageTag] (string). -// - args[2] - A function that initialises and returns a Javascript object that -// matches the [bindings.EventModel] interface. The function must match the -// Build function in [bindings.EventModelBuilder]. +// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved +// using [Cmix.GetID]. +// - args[1] - The storage tag associated with the previously created channel +// manager and retrieved with [ChannelsManager.GetStorageTag] (string). +// - args[2] - A function that initialises and returns a Javascript object +// that matches the [bindings.EventModel] interface. The function must match +// the Build function in [bindings.EventModelBuilder]. // // Returns: -// - Javascript representation of the [ChannelsManager] object. -// - Throws a TypeError if loading the manager fails. -func LoadChannelsManager(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [ChannelsManager] object. +// - Throws a TypeError if loading the manager fails. +func LoadChannelsManager(_ js.Value, args []js.Value) any { em := &eventModelBuilder{args[2].Invoke} cm, err := bindings.LoadChannelsManager(args[0].Int(), args[1].String(), em) if err != nil { @@ -316,28 +316,29 @@ func LoadChannelsManager(_ js.Value, args []js.Value) interface{} { // This function initialises an indexedDb database. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved -// using [Cmix.GetID]. -// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is -// generated by [GenerateChannelIdentity] (Uint8Array). -// - args[2] - Function that takes in the same parameters as -// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is -// returned as an int and the channelID as a Uint8Array. The row in the -// database that was updated can be found using the UUID. The channel ID is -// provided so that the recipient can filter if they want to the processes -// the update now or not. An "update" bool is present which tells you if the -// row is new or if it is an edited old row. -// - args[3] - ID of [ChannelDbCipher] object in tracker (int). Create this -// object with [NewChannelsDatabaseCipher] and get its id with -// [ChannelDbCipher.GetID]. +// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved +// using [Cmix.GetID]. +// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is +// generated by [GenerateChannelIdentity] (Uint8Array). +// - args[2] - Function that takes in the same parameters as +// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is +// returned as an int and the channelID as a Uint8Array. The row in the +// database that was updated can be found using the UUID. The channel ID is +// provided so that the recipient can filter if they want to the processes +// the update now or not. An "update" bool is present which tells you if the +// row is new or if it is an edited old row. +// - args[3] - ID of [ChannelDbCipher] object in tracker (int). Create this +// object with [NewChannelsDatabaseCipher] and get its id with +// [ChannelDbCipher.GetID]. // // Returns a promise: -// - Resolves to a Javascript representation of the [ChannelsManager] object. -// - Rejected with an error if loading indexedDb or the manager fails. -// - Throws a TypeError if the cipher ID does not correspond to a cipher. -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. +// - Throws a TypeError if the cipher ID does not correspond to a cipher. +func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) any { cmixID := args[0].Int() privateIdentity := utils.CopyBytesToGo(args[1]) + messageReceivedCB := args[2] cipherID := args[3].Int() cipher, err := bindings.GetChannelDbCipherTrackerFromID(cipherID) @@ -345,7 +346,8 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { utils.Throw(utils.TypeError, err) } - return newChannelsManagerWithIndexedDb(cmixID, privateIdentity, args[2], cipher) + return newChannelsManagerWithIndexedDb( + cmixID, privateIdentity, messageReceivedCB, cipher) } // NewChannelsManagerWithIndexedDbUnsafe creates a new [ChannelsManager] from a @@ -361,38 +363,40 @@ func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { // This function initialises an indexedDb database. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved -// using [Cmix.GetID]. -// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is -// generated by [GenerateChannelIdentity] (Uint8Array). -// - args[2] - Function that takes in the same parameters as -// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is -// returned as an int and the channelID as a Uint8Array. The row in the -// database that was updated can be found using the UUID. The channel ID is -// provided so that the recipient can filter if they want to the processes -// the update now or not. An "update" bool is present which tells you if -// the row is new or if it is an edited old row +// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved +// using [Cmix.GetID]. +// - args[1] - Bytes of a private identity ([channel.PrivateIdentity]) that is +// generated by [GenerateChannelIdentity] (Uint8Array). +// - args[2] - Function that takes in the same parameters as +// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is +// returned as an int and the channelID as a Uint8Array. The row in the +// database that was updated can be found using the UUID. The channel ID is +// provided so that the recipient can filter if they want to the processes +// the update now or not. An "update" bool is present which tells you if +// the row is new or if it is an edited old row // // Returns a promise: -// - Resolves to a Javascript representation of the [ChannelsManager] object. -// - Rejected with an error if loading indexedDb or the manager fails. -func NewChannelsManagerWithIndexedDbUnsafe(_ 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 NewChannelsManagerWithIndexedDbUnsafe(_ js.Value, args []js.Value) any { cmixID := args[0].Int() privateIdentity := utils.CopyBytesToGo(args[1]) + messageReceivedCB := args[2] - return newChannelsManagerWithIndexedDb(cmixID, privateIdentity, args[2], nil) + return newChannelsManagerWithIndexedDb( + cmixID, privateIdentity, messageReceivedCB, nil) } func newChannelsManagerWithIndexedDb(cmixID int, privateIdentity []byte, - cb js.Value, cipher *bindings.ChannelDbCipher) interface{} { + cb js.Value, cipher *bindings.ChannelDbCipher) any { - fn := func(uuid uint64, channelID *id.ID, update bool) { + messageReceivedCB := func(uuid uint64, channelID *id.ID, update bool) { cb.Invoke(uuid, utils.CopyBytesToJS(channelID.Marshal()), update) } - model := indexedDb.NewWASMEventModelBuilder(cipher, fn) + model := indexedDb.NewWASMEventModelBuilder(cipher, messageReceivedCB) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { cm, err := bindings.NewChannelsManagerGoEventModel( cmixID, privateIdentity, model) if err != nil { @@ -414,28 +418,29 @@ func newChannelsManagerWithIndexedDb(cmixID int, privateIdentity []byte, // [ChannelsManager.GetStorageTag]. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved -// using [Cmix.GetID]. -// - args[1] - The storage tag associated with the previously created channel -// manager and retrieved with [ChannelsManager.GetStorageTag] (string). -// - args[2] - Function that takes in the same parameters as -// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is -// returned as an int and the channelID as a Uint8Array. The row in the -// database that was updated can be found using the UUID. The channel ID is -// provided so that the recipient can filter if they want to the processes -// the update now or not. An "update" bool is present which tells you if the -// row is new or if it is an edited old row. -// - args[3] - ID of [ChannelDbCipher] object in tracker (int). Create this -// object with [NewChannelsDatabaseCipher] and get its id with -// [ChannelDbCipher.GetID]. +// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved +// using [Cmix.GetID]. +// - args[1] - The storage tag associated with the previously created channel +// manager and retrieved with [ChannelsManager.GetStorageTag] (string). +// - args[2] - Function that takes in the same parameters as +// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is +// returned as an int and the channelID as a Uint8Array. The row in the +// database that was updated can be found using the UUID. The channel ID is +// provided so that the recipient can filter if they want to the processes +// the update now or not. An "update" bool is present which tells you if the +// row is new or if it is an edited old row. +// - args[3] - ID of [ChannelDbCipher] object in tracker (int). Create this +// object with [NewChannelsDatabaseCipher] and get its id with +// [ChannelDbCipher.GetID]. // // Returns a promise: -// - Resolves to a Javascript representation of the [ChannelsManager] object. -// - Rejected with an error if loading indexedDb or the manager fails. -// - Throws a TypeError if the cipher ID does not correspond to a cipher. -func LoadChannelsManagerWithIndexedDb(_ 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. +// - Throws a TypeError if the cipher ID does not correspond to a cipher. +func LoadChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) any { cmixID := args[0].Int() storageTag := args[1].String() + messageReceivedCB := args[2] cipherID := args[3].Int() cipher, err := bindings.GetChannelDbCipherTrackerFromID(cipherID) @@ -443,7 +448,8 @@ func LoadChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { utils.Throw(utils.TypeError, err) } - return loadChannelsManagerWithIndexedDb(cmixID, storageTag, args[2], cipher) + return loadChannelsManagerWithIndexedDb( + cmixID, storageTag, messageReceivedCB, cipher) } // LoadChannelsManagerWithIndexedDbUnsafe loads an existing [ChannelsManager] @@ -457,37 +463,39 @@ func LoadChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) interface{} { // [ChannelsManager.GetStorageTag]. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved -// using [Cmix.GetID]. -// - args[1] - The storage tag associated with the previously created channel -// manager and retrieved with [ChannelsManager.GetStorageTag] (string). -// - args[2] - Function that takes in the same parameters as -// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is -// returned as an int and the channelID as a Uint8Array. The row in the -// database that was updated can be found using the UUID. The channel ID is -// provided so that the recipient can filter if they want to the processes -// the update now or not. An "update" bool is present which tells you if -// the row is new or if it is an edited old row +// - args[0] - ID of [Cmix] object in tracker (int). This can be retrieved +// using [Cmix.GetID]. +// - args[1] - The storage tag associated with the previously created channel +// manager and retrieved with [ChannelsManager.GetStorageTag] (string). +// - args[2] - Function that takes in the same parameters as +// [indexedDb.MessageReceivedCallback]. On the Javascript side, the UUID is +// returned as an int and the channelID as a Uint8Array. The row in the +// database that was updated can be found using the UUID. The channel ID is +// provided so that the recipient can filter if they want to the processes +// the update now or not. An "update" bool is present which tells you if +// the row is new or if it is an edited old row // // Returns a promise: -// - Resolves to a Javascript representation of the [ChannelsManager] object. -// - Rejected with an error if loading indexedDb or the manager fails. -func LoadChannelsManagerWithIndexedDbUnsafe(_ 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 LoadChannelsManagerWithIndexedDbUnsafe(_ js.Value, args []js.Value) any { cmixID := args[0].Int() storageTag := args[1].String() + messageReceivedCB := args[2] - return loadChannelsManagerWithIndexedDb(cmixID, storageTag, args[2], nil) + return loadChannelsManagerWithIndexedDb( + cmixID, storageTag, messageReceivedCB, nil) } func loadChannelsManagerWithIndexedDb(cmixID int, storageTag string, - cb js.Value, cipher *bindings.ChannelDbCipher) interface{} { - fn := func(uuid uint64, channelID *id.ID, updated bool) { + cb js.Value, cipher *bindings.ChannelDbCipher) any { + messageReceivedCB := func(uuid uint64, channelID *id.ID, updated bool) { cb.Invoke(uuid, utils.CopyBytesToJS(channelID.Marshal()), updated) } - model := indexedDb.NewWASMEventModelBuilder(cipher, fn) + model := indexedDb.NewWASMEventModelBuilder(cipher, messageReceivedCB) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { cm, err := bindings.LoadChannelsManagerGoEventModel( cmixID, storageTag, model) if err != nil { @@ -509,34 +517,34 @@ func loadChannelsManagerWithIndexedDb(cmixID int, storageTag string, // longer than __ and can only use ______ characters. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - The name of the new channel (string). The name must be between 3 -// and 24 characters inclusive. It can only include upper and lowercase -// unicode letters, digits 0 through 9, and underscores (_). It cannot be -// changed once a channel is created. -// - args[2] - The description of a channel (string). The description is -// optional but cannot be longer than 144 characters and can include all -// unicode characters. It cannot be changed once a channel is created. -// - args[3] - The [broadcast.PrivacyLevel] of the channel (int). 0 = public, -// 1 = private, and 2 = secret. Refer to the comment below for more -// information. +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - The name of the new channel (string). The name must be between +// 3 and 24 characters inclusive. It can only include upper and lowercase +// unicode letters, digits 0 through 9, and underscores (_). It cannot be +// changed once a channel is created. +// - args[2] - The description of a channel (string). The description is +// optional but cannot be longer than 144 characters and can include all +// unicode characters. It cannot be changed once a channel is created. +// - args[3] - The [broadcast.PrivacyLevel] of the channel (int). 0 = public, +// 1 = private, and 2 = secret. Refer to the comment below for more +// information. // // Returns: -// - JSON of [bindings.ChannelGeneration], which describes a generated channel. -// It contains both the public channel info and the private key for the -// channel in PEM format (Uint8Array). -// - Throws a TypeError if generating the channel fails. +// - JSON of [bindings.ChannelGeneration], which describes a generated +// channel. It contains both the public channel info and the private key for +// the channel in PEM format (Uint8Array). +// - Throws a TypeError 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 // channels, the secret information is encrypted and a password is required to // share and join a channel. -// - A privacy level of [broadcast.Public] reveals all the information -// including the name, description, privacy level, public key and salt. -// - A privacy level of [broadcast.Private] reveals only the name and -// description. -// - A privacy level of [broadcast.Secret] reveals nothing. -func GenerateChannel(_ js.Value, args []js.Value) interface{} { +// - A privacy level of [broadcast.Public] reveals all the information +// including the name, description, privacy level, public key and salt. +// - A privacy level of [broadcast.Private] reveals only the name and +// description. +// - A privacy level of [broadcast.Secret] reveals nothing. +func GenerateChannel(_ js.Value, args []js.Value) any { gen, err := bindings.GenerateChannel( args[0].Int(), args[1].String(), args[2].String(), args[3].Int()) if err != nil { @@ -553,15 +561,16 @@ func GenerateChannel(_ js.Value, args []js.Value) interface{} { // NOTE: This function is unsafe and only for debugging purposes only. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - The [id.ID] of the channel in base 64 encoding (string). +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - The [id.ID] of the channel in base 64 encoding (string). // // Returns: -// - The PEM file of the private key (string). -// - Throws a TypeError if retrieving the [Cmix] object or the private key -// fails. -func GetSavedChannelPrivateKeyUNSAFE(_ js.Value, args []js.Value) interface{} { - privKey, err := bindings.GetSavedChannelPrivateKeyUNSAFE(args[0].Int(), args[1].String()) +// - The PEM file of the private key (string). +// - Throws a TypeError if retrieving the [Cmix] object or the private key +// fails. +func GetSavedChannelPrivateKeyUNSAFE(_ js.Value, args []js.Value) any { + privKey, err := bindings.GetSavedChannelPrivateKeyUNSAFE( + args[0].Int(), args[1].String()) if err != nil { utils.Throw(utils.TypeError, err) return nil @@ -575,12 +584,12 @@ func GetSavedChannelPrivateKeyUNSAFE(_ js.Value, args []js.Value) interface{} { // of a channel URL, use [GetShareUrlType]. // // Parameters: -// - args[0] - The channel's share URL (string). Should be received from -// another user or generated via [ChannelsManager.GetShareURL]. +// - args[0] - The channel's share URL (string). Should be received from +// another user or generated via [ChannelsManager.GetShareURL]. // // Returns: -// - The channel pretty print (string). -func DecodePublicURL(_ js.Value, args []js.Value) interface{} { +// - The channel pretty print (string). +func DecodePublicURL(_ js.Value, args []js.Value) any { c, err := bindings.DecodePublicURL(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -595,14 +604,14 @@ func DecodePublicURL(_ js.Value, args []js.Value) interface{} { // URLs. To get the privacy level of a channel URL, use [GetShareUrlType]. // // Parameters: -// - args[0] - The channel's share URL (string). Should be received from -// another user or generated via [ChannelsManager.GetShareURL]. -// - args[1] - The password needed to decrypt the secret data in the URL -// (string). +// - args[0] - The channel's share URL (string). Should be received from +// another user or generated via [ChannelsManager.GetShareURL]. +// - args[1] - The password needed to decrypt the secret data in the URL +// (string). // // Returns: -// - The channel pretty print (string) -func DecodePrivateURL(_ js.Value, args []js.Value) interface{} { +// - The channel pretty print (string) +func DecodePrivateURL(_ js.Value, args []js.Value) any { c, err := bindings.DecodePrivateURL(args[0].String(), args[1].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -615,24 +624,25 @@ func DecodePrivateURL(_ js.Value, args []js.Value) interface{} { // GetChannelJSON returns the JSON of the channel for the given pretty print. // // Parameters: -// - args[0] - The pretty print of the channel (string). +// - args[0] - The pretty print of the channel (string). // // Returns: -// - JSON of the [broadcast.Channel] object (Uint8Array). +// - JSON of the [broadcast.Channel] object (Uint8Array). // // Example JSON of [broadcast.Channel]: -// { -// "ReceptionID": "Ja/+Jh+1IXZYUOn+IzE3Fw/VqHOscomD0Q35p4Ai//kD", -// "Name": "My_Channel", -// "Description": "Here is information about my channel.", -// "Salt": "+tlrU/htO6rrV3UFDfpQALUiuelFZ+Cw9eZCwqRHk+g=", -// "RsaPubKeyHash": "PViT1mYkGBj6AYmE803O2RpA7BX24EjgBdldu3pIm4o=", -// "RsaPubKeyLength": 5, -// "RSASubPayloads": 1, -// "Secret": "JxZt/wPx2luoPdHY6jwbXqNlKnixVU/oa9DgypZOuyI=", -// "Level": 0 -// } -func GetChannelJSON(_ js.Value, args []js.Value) interface{} { +// +// { +// "ReceptionID": "Ja/+Jh+1IXZYUOn+IzE3Fw/VqHOscomD0Q35p4Ai//kD", +// "Name": "My_Channel", +// "Description": "Here is information about my channel.", +// "Salt": "+tlrU/htO6rrV3UFDfpQALUiuelFZ+Cw9eZCwqRHk+g=", +// "RsaPubKeyHash": "PViT1mYkGBj6AYmE803O2RpA7BX24EjgBdldu3pIm4o=", +// "RsaPubKeyLength": 5, +// "RSASubPayloads": 1, +// "Secret": "JxZt/wPx2luoPdHY6jwbXqNlKnixVU/oa9DgypZOuyI=", +// "Level": 0 +// } +func GetChannelJSON(_ js.Value, args []js.Value) any { c, err := bindings.GetChannelJSON(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -645,16 +655,17 @@ func GetChannelJSON(_ js.Value, args []js.Value) interface{} { // GetChannelInfo returns the info about a channel from its public description. // // Parameters: -// - args[0] - The pretty print of the channel (string). +// - args[0] - The pretty print of the channel (string). // // The pretty print will be of the format: -// <Speakeasy-v3:Test_Channel|description:Channel description.|level:Public|created:1666718081766741100|secrets:+oHcqDbJPZaT3xD5NcdLY8OjOMtSQNKdKgLPmr7ugdU=|rCI0wr01dHFStjSFMvsBzFZClvDIrHLL5xbCOPaUOJ0=|493|1|7cBhJxVfQxWo+DypOISRpeWdQBhuQpAZtUbQHjBm8NQ=> +// +// <Speakeasy-v3:Test_Channel|description:Channel description.|level:Public|created:1666718081766741100|secrets:+oHcqDbJPZaT3xD5NcdLY8OjOMtSQNKdKgLPmr7ugdU=|rCI0wr01dHFStjSFMvsBzFZClvDIrHLL5xbCOPaUOJ0=|493|1|7cBhJxVfQxWo+DypOISRpeWdQBhuQpAZtUbQHjBm8NQ=> // // Returns: -// - JSON of [bindings.ChannelInfo], which describes all relevant channel info -// (Uint8Array). -// - Throws a TypeError if getting the channel info fails. -func GetChannelInfo(_ js.Value, args []js.Value) interface{} { +// - JSON of [bindings.ChannelInfo], which describes all relevant channel info +// (Uint8Array). +// - Throws a TypeError if getting the channel info fails. +func GetChannelInfo(_ js.Value, args []js.Value) any { ci, err := bindings.GetChannelInfo(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -668,17 +679,18 @@ func GetChannelInfo(_ js.Value, args []js.Value) interface{} { // been joined. // // Parameters: -// - args[0] - A portable channel string. Should be received from another user -// or generated via [GenerateChannel] (string). +// - args[0] - A portable channel string. Should be received from another user +// or generated via [GenerateChannel] (string). // // The pretty print will be of the format: -// <Speakeasy-v3:Test_Channel|description:Channel description.|level:Public|created:1666718081766741100|secrets:+oHcqDbJPZaT3xD5NcdLY8OjOMtSQNKdKgLPmr7ugdU=|rCI0wr01dHFStjSFMvsBzFZClvDIrHLL5xbCOPaUOJ0=|493|1|7cBhJxVfQxWo+DypOISRpeWdQBhuQpAZtUbQHjBm8NQ=> +// +// <Speakeasy-v3:Test_Channel|description:Channel description.|level:Public|created:1666718081766741100|secrets:+oHcqDbJPZaT3xD5NcdLY8OjOMtSQNKdKgLPmr7ugdU=|rCI0wr01dHFStjSFMvsBzFZClvDIrHLL5xbCOPaUOJ0=|493|1|7cBhJxVfQxWo+DypOISRpeWdQBhuQpAZtUbQHjBm8NQ=> // // Returns: -// - JSON of [bindings.ChannelInfo], which describes all relevant channel info -// (Uint8Array). -// - Throws a TypeError if joining the channel fails. -func (ch *ChannelsManager) JoinChannel(_ js.Value, args []js.Value) interface{} { +// - JSON of [bindings.ChannelInfo], which describes all relevant channel info +// (Uint8Array). +// - Throws a TypeError if joining the channel fails. +func (ch *ChannelsManager) JoinChannel(_ js.Value, args []js.Value) any { ci, err := ch.api.JoinChannel(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -691,15 +703,16 @@ func (ch *ChannelsManager) JoinChannel(_ js.Value, args []js.Value) interface{} // GetChannels returns the IDs of all channels that have been joined. // // Returns: -// - JSON of an array of marshalled [id.ID] (Uint8Array). -// - Throws a TypeError if getting the channels fails. +// - JSON of an array of marshalled [id.ID] (Uint8Array). +// - Throws a TypeError if getting the channels fails. // // JSON Example: -// { -// "U4x/lrFkvxuXu59LtHLon1sUhPJSCcnZND6SugndnVID", -// "15tNdkKbYXoMn58NO6VbDMDWFEyIhTWEGsvgcJsHWAgD" -// } -func (ch *ChannelsManager) GetChannels(js.Value, []js.Value) interface{} { +// +// { +// "U4x/lrFkvxuXu59LtHLon1sUhPJSCcnZND6SugndnVID", +// "15tNdkKbYXoMn58NO6VbDMDWFEyIhTWEGsvgcJsHWAgD" +// } +func (ch *ChannelsManager) GetChannels(js.Value, []js.Value) any { channelList, err := ch.api.GetChannels() if err != nil { utils.Throw(utils.TypeError, err) @@ -713,11 +726,11 @@ func (ch *ChannelsManager) GetChannels(js.Value, []js.Value) interface{} { // was not previously joined. // // Parameters: -// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). // // Returns: -// - Throws a TypeError if the channel does not exist. -func (ch *ChannelsManager) LeaveChannel(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the channel does not exist. +func (ch *ChannelsManager) LeaveChannel(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) err := ch.api.LeaveChannel(marshalledChanId) @@ -733,11 +746,11 @@ func (ch *ChannelsManager) LeaveChannel(_ js.Value, args []js.Value) interface{} // memory (~3 weeks) over the event model. // // Parameters: -// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). // // Returns: -// - Throws a TypeError if the replay fails. -func (ch *ChannelsManager) ReplayChannel(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the replay fails. +func (ch *ChannelsManager) ReplayChannel(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) err := ch.api.ReplayChannel(marshalledChanId) @@ -753,6 +766,8 @@ func (ch *ChannelsManager) ReplayChannel(_ js.Value, args []js.Value) interface{ // Channel Share URL // //////////////////////////////////////////////////////////////////////////////// +// ShareURL is returned by GetShareURL containing the sharable URL and a +// password, if the channel is private. type ShareURL struct { URL string `json:"url"` Password string `json:"password"` @@ -776,16 +791,16 @@ type ShareURL struct { // public URLs. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - The URL to append the channel info to (string). -// - args[2] - The maximum number of uses the link can be used (0 for -// unlimited) (int). -// - args[3] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - The URL to append the channel info to (string). +// - args[2] - The maximum number of uses the link can be used (0 for +// unlimited) (int). +// - args[3] - Marshalled bytes of the channel [id.ID] (Uint8Array). // // Returns: -// - JSON of [bindings.ShareURL] (Uint8Array). -// - Throws a TypeError if generating the URL fails. -func (ch *ChannelsManager) GetShareURL(_ js.Value, args []js.Value) interface{} { +// - JSON of [bindings.ShareURL] (Uint8Array). +// - Throws a TypeError if generating the URL fails. +func (ch *ChannelsManager) GetShareURL(_ js.Value, args []js.Value) any { cmixID := args[0].Int() host := args[1].String() maxUses := args[2].Int() @@ -804,17 +819,19 @@ func (ch *ChannelsManager) GetShareURL(_ js.Value, args []js.Value) interface{} // If the URL is an invalid channel URL, an error is returned. // // Parameters: -// - args[0] - The channel share URL (string). +// - args[0] - The channel share URL (string). // // Returns: -// - An int that corresponds to the [broadcast.PrivacyLevel] as outlined below. -// - Throws a TypeError if parsing the URL fails. +// - An int that corresponds to the [broadcast.PrivacyLevel] as outlined +// below. +// - Throws a TypeError if parsing the URL fails. // // Possible returns: -// 0 = public channel -// 1 = private channel -// 2 = secret channel -func GetShareUrlType(_ js.Value, args []js.Value) interface{} { +// +// 0 = public channel +// 1 = private channel +// 2 = secret channel +func GetShareUrlType(_ js.Value, args []js.Value) any { level, err := bindings.GetShareUrlType(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -837,28 +854,29 @@ func GetShareUrlType(_ js.Value, args []js.Value) interface{} { // on the use case. // // Parameters: -// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - args[1] - The message type of the message. This will be a valid -// [channels.MessageType] (int). -// - args[2] - The contents of the message (Uint8Array). -// - args[3] - The lease of the message. This will be how long the message is -// valid until, in milliseconds. As per the [channels.Manager] documentation, -// this has different meanings depending on the use case. These use cases may -// be generic enough that they will not be enumerated here (int). -// - args[4] - JSON of [xxdk.CMIXParams]. If left empty -// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[1] - The message type of the message. This will be a valid +// [channels.MessageType] (int). +// - args[2] - The contents of the message (Uint8Array). +// - args[3] - The lease of the message. This will be how long the message is +// valid until, in milliseconds. As per the [channels.Manager] +// documentation, this has different meanings depending on the use case. +// These use cases may be generic enough that they will not be enumerated +// here (int). +// - args[4] - JSON of [xxdk.CMIXParams]. If left empty +// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). -// - Rejected with an error if sending fails. -func (ch *ChannelsManager) SendGeneric(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). +// - Rejected with an error if sending fails. +func (ch *ChannelsManager) SendGeneric(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) messageType := args[1].Int() message := utils.CopyBytesToGo(args[2]) leaseTimeMS := int64(args[3].Int()) cmixParamsJSON := utils.CopyBytesToGo(args[4]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := ch.api.SendGeneric( marshalledChanId, messageType, message, leaseTimeMS, cmixParamsJSON) if err != nil { @@ -878,22 +896,23 @@ func (ch *ChannelsManager) SendGeneric(_ js.Value, args []js.Value) interface{} // message must be at most 510 bytes long. // // Parameters: -// - args[0] - The PEM-encode admin RSA private key (Uint8Array). -// - args[1] - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - args[2] - The message type of the message. This will be a valid -// [channels.MessageType] (int). -// - args[3] - The contents of the message (Uint8Array). -// - args[4] - The lease of the message. This will be how long the message is -// valid until, in milliseconds. As per the [channels.Manager] documentation, -// this has different meanings depending on the use case. These use cases may -// be generic enough that they will not be enumerated here (int). -// - args[5] - JSON of [xxdk.CMIXParams]. If left empty -// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). +// - args[0] - The PEM-encode admin RSA private key (Uint8Array). +// - args[1] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[2] - The message type of the message. This will be a valid +// [channels.MessageType] (int). +// - args[3] - The contents of the message (Uint8Array). +// - args[4] - The lease of the message. This will be how long the message is +// valid until, in milliseconds. As per the [channels.Manager] +// documentation, this has different meanings depending on the use case. +// These use cases may be generic enough that they will not be enumerated +// here (int). +// - args[5] - JSON of [xxdk.CMIXParams]. If left empty +// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). -// - Rejected with an error if sending fails. -func (ch *ChannelsManager) SendAdminGeneric(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). +// - Rejected with an error if sending fails. +func (ch *ChannelsManager) SendAdminGeneric(_ js.Value, args []js.Value) any { adminPrivateKey := utils.CopyBytesToGo(args[0]) marshalledChanId := utils.CopyBytesToGo(args[1]) messageType := args[2].Int() @@ -901,7 +920,7 @@ func (ch *ChannelsManager) SendAdminGeneric(_ js.Value, args []js.Value) interfa leaseTimeMS := int64(args[4].Int()) cmixParamsJSON := utils.CopyBytesToGo(args[5]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := ch.api.SendAdminGeneric(adminPrivateKey, marshalledChanId, messageType, message, leaseTimeMS, cmixParamsJSON) if err != nil { @@ -923,25 +942,26 @@ func (ch *ChannelsManager) SendAdminGeneric(_ js.Value, args []js.Value) interfa // lasting forever if [channels.ValidForever] is used. // // Parameters: -// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - args[1] - The contents of the message (string). -// - args[2] - The lease of the message. This will be how long the message is -// valid until, in milliseconds. As per the [channels.Manager] documentation, -// this has different meanings depending on the use case. These use cases may -// be generic enough that they will not be enumerated here (int). -// - args[3] - JSON of [xxdk.CMIXParams]. If left empty -// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[1] - The contents of the message (string). +// - args[2] - The lease of the message. This will be how long the message is +// valid until, in milliseconds. As per the [channels.Manager] +// documentation, this has different meanings depending on the use case. +// These use cases may be generic enough that they will not be enumerated +// here (int). +// - args[3] - JSON of [xxdk.CMIXParams]. If left empty +// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). -// - Rejected with an error if sending fails. -func (ch *ChannelsManager) SendMessage(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). +// - Rejected with an error if sending fails. +func (ch *ChannelsManager) SendMessage(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) message := args[1].String() leaseTimeMS := int64(args[2].Int()) cmixParamsJSON := utils.CopyBytesToGo(args[3]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := ch.api.SendMessage( marshalledChanId, message, leaseTimeMS, cmixParamsJSON) if err != nil { @@ -965,33 +985,34 @@ func (ch *ChannelsManager) SendMessage(_ js.Value, args []js.Value) interface{} // [channels.ValidForever] is used. // // Parameters: -// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - args[1] - The contents of the message. The message should be at most 510 -// bytes. This is expected to be Unicode, and thus a string data type is -// expected (string). -// - args[2] - JSON of [channel.MessageID] of the message you wish to reply to. -// This may be found in the [bindings.ChannelSendReport] if replying to your -// own. Alternatively, if reacting to another user's message, you may -// retrieve it via the [bindings.ChannelMessageReceptionCallback] registered -// using RegisterReceiveHandler (Uint8Array). -// - args[3] - The lease of the message. This will be how long the message is -// valid until, in milliseconds. As per the [channels.Manager] documentation, -// this has different meanings depending on the use case. These use cases may -// be generic enough that they will not be enumerated here (int). -// - args[4] - JSON of [xxdk.CMIXParams]. If left empty -// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[1] - The contents of the message. The message should be at most 510 +// bytes. This is expected to be Unicode, and thus a string data type is +// expected (string). +// - args[2] - JSON of [channel.MessageID] of the message you wish to reply +// to. This may be found in the [bindings.ChannelSendReport] if replying to +// your own. Alternatively, if reacting to another user's message, you may +// retrieve it via the [bindings.ChannelMessageReceptionCallback] registered +// using RegisterReceiveHandler (Uint8Array). +// - args[3] - The lease of the message. This will be how long the message is +// valid until, in milliseconds. As per the [channels.Manager] +// documentation, this has different meanings depending on the use case. +// These use cases may be generic enough that they will not be enumerated +// here (int). +// - args[4] - JSON of [xxdk.CMIXParams]. If left empty +// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). -// - Rejected with an error if sending fails. -func (ch *ChannelsManager) SendReply(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). +// - Rejected with an error if sending fails. +func (ch *ChannelsManager) SendReply(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) message := args[1].String() messageToReactTo := utils.CopyBytesToGo(args[2]) leaseTimeMS := int64(args[3].Int()) cmixParamsJSON := utils.CopyBytesToGo(args[4]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := ch.api.SendReply(marshalledChanId, message, messageToReactTo, leaseTimeMS, cmixParamsJSON) if err != nil { @@ -1010,27 +1031,27 @@ func (ch *ChannelsManager) SendReply(_ js.Value, args []js.Value) interface{} { // Users will drop the reaction if they do not recognize the reactTo message. // // Parameters: -// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - args[1] - The user's reaction. This should be a single emoji with no -// other characters. As such, a Unicode string is expected (string). -// - args[2] - JSON of [channel.MessageID] of the message you wish to reply to. -// This may be found in the [bindings.ChannelSendReport] if replying to your -// own. Alternatively, if reacting to another user's message, you may -// retrieve it via the ChannelMessageReceptionCallback registered using -// RegisterReceiveHandler (Uint8Array). -// - args[3] - JSON of [xxdk.CMIXParams]. If left empty -// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[1] - The user's reaction. This should be a single emoji with no +// other characters. As such, a Unicode string is expected (string). +// - args[2] - JSON of [channel.MessageID] of the message you wish to reply +// to. This may be found in the [bindings.ChannelSendReport] if replying to +// your own. Alternatively, if reacting to another user's message, you may +// retrieve it via the ChannelMessageReceptionCallback registered using +// RegisterReceiveHandler (Uint8Array). +// - args[3] - JSON of [xxdk.CMIXParams]. If left empty +// [bindings.GetDefaultCMixParams] will be used internally (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). -// - Rejected with an error if sending fails. -func (ch *ChannelsManager) SendReaction(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of [bindings.ChannelSendReport] (Uint8Array). +// - Rejected with an error if sending fails. +func (ch *ChannelsManager) SendReaction(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) reaction := args[1].String() messageToReactTo := utils.CopyBytesToGo(args[2]) cmixParamsJSON := utils.CopyBytesToGo(args[3]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := ch.api.SendReaction( marshalledChanId, reaction, messageToReactTo, cmixParamsJSON) if err != nil { @@ -1047,9 +1068,9 @@ func (ch *ChannelsManager) SendReaction(_ js.Value, args []js.Value) interface{} // the channel is using. // // Returns: -// - JSON of the [channel.Identity] (Uint8Array). -// - Throws TypeError if marshalling the identity fails. -func (ch *ChannelsManager) GetIdentity(js.Value, []js.Value) interface{} { +// - JSON of the [channel.Identity] (Uint8Array). +// - Throws TypeError if marshalling the identity fails. +func (ch *ChannelsManager) GetIdentity(js.Value, []js.Value) any { i, err := ch.api.GetIdentity() if err != nil { utils.Throw(utils.TypeError, err) @@ -1063,12 +1084,12 @@ func (ch *ChannelsManager) GetIdentity(js.Value, []js.Value) interface{} { // string. // // Parameters: -// - args[0] - Password to encrypt the identity with (string). +// - args[0] - Password to encrypt the identity with (string). // // Returns: -// - JSON of the encrypted private identity (Uint8Array). -// - Throws TypeError if exporting the identity fails. -func (ch *ChannelsManager) ExportPrivateIdentity(_ js.Value, args []js.Value) interface{} { +// - JSON of the encrypted private identity (Uint8Array). +// - Throws TypeError if exporting the identity fails. +func (ch *ChannelsManager) ExportPrivateIdentity(_ js.Value, args []js.Value) any { i, err := ch.api.ExportPrivateIdentity(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -1081,8 +1102,8 @@ func (ch *ChannelsManager) ExportPrivateIdentity(_ js.Value, args []js.Value) in // GetStorageTag returns the storage tag needed to reload the manager. // // Returns: -// - Storage tag (string). -func (ch *ChannelsManager) GetStorageTag(js.Value, []js.Value) interface{} { +// - Storage tag (string). +func (ch *ChannelsManager) GetStorageTag(js.Value, []js.Value) any { return ch.api.GetStorageTag() } @@ -1090,12 +1111,13 @@ func (ch *ChannelsManager) GetStorageTag(js.Value, []js.Value) interface{} { // according to [IsNicknameValid]. // // Parameters: -// - args[0] - The nickname to set (string). -// - args[1] - Marshalled bytes if the channel's [id.ID] (Uint8Array). +// - args[0] - The nickname to set (string). +// - args[1] - Marshalled bytes if the channel's [id.ID] (Uint8Array). // // Returns: -// - Throws TypeError if unmarshalling the ID fails or the nickname is invalid. -func (ch *ChannelsManager) SetNickname(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if unmarshalling the ID fails or the nickname is +// invalid. +func (ch *ChannelsManager) SetNickname(_ js.Value, args []js.Value) any { err := ch.api.SetNickname(args[0].String(), utils.CopyBytesToGo(args[1])) if err != nil { utils.Throw(utils.TypeError, err) @@ -1108,11 +1130,11 @@ func (ch *ChannelsManager) SetNickname(_ js.Value, args []js.Value) interface{} // DeleteNickname deletes the nickname for a given channel. // // Parameters: -// - args[0] - Marshalled bytes if the channel's [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes if the channel's [id.ID] (Uint8Array). // // Returns: -// - Throws TypeError if deleting the nickname fails. -func (ch *ChannelsManager) DeleteNickname(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if deleting the nickname fails. +func (ch *ChannelsManager) DeleteNickname(_ js.Value, args []js.Value) any { err := ch.api.DeleteNickname(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -1126,12 +1148,12 @@ func (ch *ChannelsManager) DeleteNickname(_ js.Value, args []js.Value) interface // there is no nickname set. // // Parameters: -// - args[0] - Marshalled bytes if the channel's [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes if the channel's [id.ID] (Uint8Array). // // Returns: -// - The nickname (string). -// - Throws TypeError if the channel has no nickname set. -func (ch *ChannelsManager) GetNickname(_ js.Value, args []js.Value) interface{} { +// - The nickname (string). +// - Throws TypeError if the channel has no nickname set. +func (ch *ChannelsManager) GetNickname(_ js.Value, args []js.Value) any { nickname, err := ch.api.GetNickname(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -1148,12 +1170,12 @@ func (ch *ChannelsManager) GetNickname(_ js.Value, args []js.Value) interface{} // 2. A nickname must not be shorter than 1 character. // // Parameters: -// - args[0] - Nickname to check (string). +// - args[0] - Nickname to check (string). // // Returns: -// - A Javascript Error object if the nickname is invalid with the reason why. -// - Null if the nickname is valid. -func IsNicknameValid(_ js.Value, args []js.Value) interface{} { +// - A Javascript Error object if the nickname is invalid with the reason why. +// - Null if the nickname is valid. +func IsNicknameValid(_ js.Value, args []js.Value) any { err := bindings.IsNicknameValid(args[0].String()) if err != nil { return utils.JsError(err) @@ -1169,19 +1191,19 @@ func IsNicknameValid(_ js.Value, args []js.Value) interface{} { // channelMessageReceptionCallback wraps Javascript callbacks to adhere to the // [bindings.ChannelMessageReceptionCallback] interface. type channelMessageReceptionCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback returns the context for a channel message. // // Parameters: -// - receivedChannelMessageReport - Returns the JSON of -// [bindings.ReceivedChannelMessageReport] (Uint8Array). -// - err - Returns an error on failure (Error). +// - receivedChannelMessageReport - Returns the JSON of +// [bindings.ReceivedChannelMessageReport] (Uint8Array). +// - err - Returns an error on failure (Error). // // Returns: -// - It must return a unique UUID for the message that it can be referenced by -// later (int). +// - It must return a unique UUID for the message that it can be referenced by +// later (int). func (cmrCB *channelMessageReceptionCallback) Callback( receivedChannelMessageReport []byte, err error) int { uuid := cmrCB.callback( @@ -1198,15 +1220,15 @@ func (cmrCB *channelMessageReceptionCallback) Callback( // return an error on any re-registration. // // Parameters: -// - args[0] - The message type of the message. This will be a valid -// [channels.MessageType] (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.ChannelMessageReceptionCallback] interface. This callback will -// be executed when a channel message of the messageType is received. +// - args[0] - The message type of the message. This will be a valid +// [channels.MessageType] (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.ChannelMessageReceptionCallback] interface. This callback will +// be executed when a channel message of the messageType is received. // // Returns: -// - Throws a TypeError if registering the handler fails. -func (ch *ChannelsManager) RegisterReceiveHandler(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if registering the handler fails. +func (ch *ChannelsManager) RegisterReceiveHandler(_ js.Value, args []js.Value) any { messageType := args[0].Int() listenerCb := &channelMessageReceptionCallback{ utils.WrapCB(args[1], "Callback")} @@ -1227,18 +1249,18 @@ func (ch *ChannelsManager) RegisterReceiveHandler(_ js.Value, args []js.Value) i // eventModel wraps Javascript callbacks to adhere to the [bindings.EventModel] // interface. type eventModel struct { - joinChannel func(args ...interface{}) js.Value - leaveChannel func(args ...interface{}) js.Value - receiveMessage func(args ...interface{}) js.Value - receiveReply func(args ...interface{}) js.Value - receiveReaction func(args ...interface{}) js.Value - updateSentStatus func(args ...interface{}) js.Value + joinChannel func(args ...any) js.Value + leaveChannel func(args ...any) js.Value + receiveMessage func(args ...any) js.Value + receiveReply func(args ...any) js.Value + receiveReaction func(args ...any) js.Value + updateSentStatus func(args ...any) js.Value } // JoinChannel is called whenever a channel is joined locally. // // Parameters: -// - channel - Returns the pretty print representation of a channel (string). +// - channel - Returns the pretty print representation of a channel (string). func (em *eventModel) JoinChannel(channel string) { em.joinChannel(channel) } @@ -1246,7 +1268,7 @@ func (em *eventModel) JoinChannel(channel string) { // LeaveChannel is called whenever a channel is left locally. // // Parameters: -// - ChannelId - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - ChannelId - Marshalled bytes of the channel [id.ID] (Uint8Array). func (em *eventModel) LeaveChannel(channelID []byte) { em.leaveChannel(utils.CopyBytesToJS(channelID)) } @@ -1256,28 +1278,29 @@ func (em *eventModel) LeaveChannel(channelID []byte) { // user of the API to filter such called by message ID. // // Parameters: -// - channelID - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - messageID - The bytes of the [channel.MessageID] of the received message -// (Uint8Array). -// - nickname - The nickname of the sender of the message (string). -// - text - The content of the message (string). -// - pubKey - The sender's Ed25519 public key (Uint8Array). -// - codeset - The codeset version (int). -// - timestamp - Time the message was received; represented as nanoseconds -// since unix epoch (int). -// - lease - The number of nanoseconds that the message is valid for (int). -// - roundId - The ID of the round that the message was received on (int). -// - msgType - The type of message ([channels.MessageType]) to send (int). -// - status - The [channels.SentStatus] of the message (int). +// - channelID - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - messageID - The bytes of the [channel.MessageID] of the received message +// (Uint8Array). +// - nickname - The nickname of the sender of the message (string). +// - text - The content of the message (string). +// - pubKey - The sender's Ed25519 public key (Uint8Array). +// - codeset - The codeset version (int). +// - timestamp - Time the message was received; represented as nanoseconds +// since unix epoch (int). +// - lease - The number of nanoseconds that the message is valid for (int). +// - roundId - The ID of the round that the message was received on (int). +// - msgType - The type of message ([channels.MessageType]) to send (int). +// - status - The [channels.SentStatus] of the message (int). // // Statuses will be enumerated as such: -// Sent = 0 -// Delivered = 1 -// Failed = 2 +// +// Sent = 0 +// Delivered = 1 +// Failed = 2 // // Returns: -// - A non-negative unique UUID for the message that it can be referenced by -// later with [eventModel.UpdateSentStatus]. +// - A non-negative unique UUID for the message that it can be referenced by +// later with [eventModel.UpdateSentStatus]. func (em *eventModel) ReceiveMessage(channelID, messageID []byte, nickname, text string, pubKey []byte, codeset int, timestamp, lease, roundId, msgType, status int64) int64 { @@ -1297,30 +1320,31 @@ func (em *eventModel) ReceiveMessage(channelID, messageID []byte, nickname, // initial message. As a result, it may be important to buffer replies. // // Parameters: -// - channelID - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - messageID - The bytes of the [channel.MessageID] of the received message -// (Uint8Array). -// - reactionTo - The [channel.MessageID] for the message that received a reply -// (Uint8Array). -// - senderUsername - The username of the sender of the message (string). -// - text - The content of the message (string). -// - pubKey - The sender's Ed25519 public key (Uint8Array). -// - codeset - The codeset version (int). -// - timestamp - Time the message was received; represented as nanoseconds -// since unix epoch (int). -// - lease - The number of nanoseconds that the message is valid for (int). -// - roundId - The ID of the round that the message was received on (int). -// - msgType - The type of message ([channels.MessageType]) to send (int). -// - status - The [channels.SentStatus] of the message (int). +// - channelID - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - messageID - The bytes of the [channel.MessageID] of the received message +// (Uint8Array). +// - reactionTo - The [channel.MessageID] for the message that received a +// reply (Uint8Array). +// - senderUsername - The username of the sender of the message (string). +// - text - The content of the message (string). +// - pubKey - The sender's Ed25519 public key (Uint8Array). +// - codeset - The codeset version (int). +// - timestamp - Time the message was received; represented as nanoseconds +// since unix epoch (int). +// - lease - The number of nanoseconds that the message is valid for (int). +// - roundId - The ID of the round that the message was received on (int). +// - msgType - The type of message ([channels.MessageType]) to send (int). +// - status - The [channels.SentStatus] of the message (int). // // Statuses will be enumerated as such: -// Sent = 0 -// Delivered = 1 -// Failed = 2 +// +// Sent = 0 +// Delivered = 1 +// Failed = 2 // // Returns: -// - A non-negative unique UUID for the message that it can be referenced by -// later with [eventModel.UpdateSentStatus]. +// - A non-negative unique UUID for the message that it can be referenced by +// later with [eventModel.UpdateSentStatus]. func (em *eventModel) ReceiveReply(channelID, messageID, reactionTo []byte, senderUsername, text string, pubKey []byte, codeset int, timestamp, lease, roundId, msgType, status int64) int64 { @@ -1340,30 +1364,31 @@ func (em *eventModel) ReceiveReply(channelID, messageID, reactionTo []byte, // initial message. As a result, it may be important to buffer reactions. // // Parameters: -// - channelID - Marshalled bytes of the channel [id.ID] (Uint8Array). -// - messageID - The bytes of the [channel.MessageID] of the received message -// (Uint8Array). -// - reactionTo - The [channel.MessageID] for the message that received a reply -// (Uint8Array). -// - senderUsername - The username of the sender of the message (string). -// - reaction - The contents of the reaction message (string). -// - pubKey - The sender's Ed25519 public key (Uint8Array). -// - codeset - The codeset version (int). -// - timestamp - Time the message was received; represented as nanoseconds -// since unix epoch (int). -// - lease - The number of nanoseconds that the message is valid for (int). -// - roundId - The ID of the round that the message was received on (int). -// - msgType - The type of message ([channels.MessageType]) to send (int). -// - status - The [channels.SentStatus] of the message (int). +// - channelID - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - messageID - The bytes of the [channel.MessageID] of the received message +// (Uint8Array). +// - reactionTo - The [channel.MessageID] for the message that received a +// reply (Uint8Array). +// - senderUsername - The username of the sender of the message (string). +// - reaction - The contents of the reaction message (string). +// - pubKey - The sender's Ed25519 public key (Uint8Array). +// - codeset - The codeset version (int). +// - timestamp - Time the message was received; represented as nanoseconds +// since unix epoch (int). +// - lease - The number of nanoseconds that the message is valid for (int). +// - roundId - The ID of the round that the message was received on (int). +// - msgType - The type of message ([channels.MessageType]) to send (int). +// - status - The [channels.SentStatus] of the message (int). // // Statuses will be enumerated as such: -// Sent = 0 -// Delivered = 1 -// Failed = 2 +// +// Sent = 0 +// Delivered = 1 +// Failed = 2 // // Returns: -// - A non-negative unique UUID for the message that it can be referenced by -// later with [eventModel.UpdateSentStatus]. +// - A non-negative unique UUID for the message that it can be referenced by +// later with [eventModel.UpdateSentStatus]. func (em *eventModel) ReceiveReaction(channelID, messageID, reactionTo []byte, senderUsername, reaction string, pubKey []byte, codeset int, timestamp, lease, roundId, msgType, status int64) int64 { @@ -1379,18 +1404,19 @@ func (em *eventModel) ReceiveReaction(channelID, messageID, reactionTo []byte, // changed. // // Parameters: -// - uuid - The unique identifier for the message (int). -// - messageID - The bytes of the [channel.MessageID] of the received message -// (Uint8Array). -// - timestamp - Time the message was received; represented as nanoseconds -// since unix epoch (int). -// - roundId - The ID of the round that the message was received on (int). -// - status - The [channels.SentStatus] of the message (int). +// - uuid - The unique identifier for the message (int). +// - messageID - The bytes of the [channel.MessageID] of the received message +// (Uint8Array). +// - timestamp - Time the message was received; represented as nanoseconds +// since unix epoch (int). +// - roundId - The ID of the round that the message was received on (int). +// - status - The [channels.SentStatus] of the message (int). // // Statuses will be enumerated as such: -// Sent = 0 -// Delivered = 1 -// Failed = 2 +// +// Sent = 0 +// Delivered = 1 +// Failed = 2 func (em *eventModel) UpdateSentStatus( uuid int64, messageID []byte, timestamp, roundID, status int64) { em.updateSentStatus( @@ -1408,13 +1434,15 @@ type ChannelDbCipher struct { } // newChannelDbCipherJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [ChannelDbCipher] structure. -func newChannelDbCipherJS(api *bindings.ChannelDbCipher) map[string]interface{} { +// (map[string]any) that matches the [ChannelDbCipher] structure. +func newChannelDbCipherJS(api *bindings.ChannelDbCipher) map[string]any { c := ChannelDbCipher{api} - channelDbCipherMap := map[string]interface{}{ - "GetID": js.FuncOf(c.GetID), - "Encrypt": js.FuncOf(c.Encrypt), - "Decrypt": js.FuncOf(c.Decrypt), + channelDbCipherMap := map[string]any{ + "GetID": js.FuncOf(c.GetID), + "Encrypt": js.FuncOf(c.Encrypt), + "Decrypt": js.FuncOf(c.Decrypt), + "MarshalJSON": js.FuncOf(c.MarshalJSON), + "UnmarshalJSON": js.FuncOf(c.UnmarshalJSON), } return channelDbCipherMap @@ -1423,17 +1451,17 @@ func newChannelDbCipherJS(api *bindings.ChannelDbCipher) map[string]interface{} // NewChannelsDatabaseCipher constructs a [ChannelDbCipher] object. // // Parameters: -// - 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[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). // // Returns: // - JavaScript representation of the [ChannelDbCipher] object. // - Throws a TypeError if creating the cipher fails. -func NewChannelsDatabaseCipher(_ js.Value, args []js.Value) interface{} { +func NewChannelsDatabaseCipher(_ js.Value, args []js.Value) any { cmixId := args[0].Int() password := utils.CopyBytesToGo(args[1]) plaintTextBlockSize := args[2].Int() @@ -1452,8 +1480,8 @@ func NewChannelsDatabaseCipher(_ js.Value, args []js.Value) interface{} { // channelDbCipherTracker. // // Returns: -// - Tracker ID (int). -func (c *ChannelDbCipher) GetID(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (c *ChannelDbCipher) GetID(js.Value, []js.Value) any { return c.api.GetID() } @@ -1461,15 +1489,14 @@ func (c *ChannelDbCipher) GetID(js.Value, []js.Value) interface{} { // 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). // - Throws a TypeError if it fails to encrypt the plaintext. -func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) interface{} { - +func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) any { ciphertext, err := c.api.Encrypt(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -1477,7 +1504,6 @@ func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) interface{} { } return utils.CopyBytesToJS(ciphertext) - } // Decrypt will decrypt the passed in encrypted value. The plaintext will be @@ -1485,13 +1511,13 @@ func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) interface{} { // function. // // Parameters: -// - args[0] - the encrypted data returned by [ChannelDbCipher.Encrypt] -// (Uint8Array). +// - args[0] - the encrypted data returned by [ChannelDbCipher.Encrypt] +// (Uint8Array). // // Returns: // - The plaintext of the ciphertext passed in (Uint8Array). // - Throws a TypeError if it fails to encrypt the plaintext. -func (c *ChannelDbCipher) Decrypt(_ js.Value, args []js.Value) interface{} { +func (c *ChannelDbCipher) Decrypt(_ js.Value, args []js.Value) any { plaintext, err := c.api.Decrypt(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -1499,5 +1525,40 @@ func (c *ChannelDbCipher) Decrypt(_ js.Value, args []js.Value) interface{} { } return utils.CopyBytesToJS(plaintext) +} +// MarshalJSON marshals the cipher into valid JSON. +// +// Returns: +// - JSON of the cipher (Uint8Array). +// - Throws a TypeError if marshalling fails. +func (c *ChannelDbCipher) MarshalJSON(js.Value, []js.Value) any { + data, err := c.api.MarshalJSON() + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return utils.CopyBytesToJS(data) +} + +// UnmarshalJSON unmarshalls JSON into the cipher. This function adheres to the +// json.Unmarshaler interface. +// +// Note that this function does not transfer the internal RNG. Use +// [channel.NewCipherFromJSON] to properly reconstruct a cipher from JSON. +// +// Parameters: +// - args[0] - JSON data to unmarshal (Uint8Array). +// +// Returns: +// - JSON of the cipher (Uint8Array). +// - Throws a TypeError if marshalling fails. +func (c *ChannelDbCipher) UnmarshalJSON(_ js.Value, args []js.Value) any { + err := c.api.UnmarshalJSON(utils.CopyBytesToGo(args[0])) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + return nil } diff --git a/wasm/cmix.go b/wasm/cmix.go index fbda07a4f3a9d1d7d9db8b4d96f48b948fc024ce..686ac6c1ef30087e7533317018056103d6f7a6a5 100644 --- a/wasm/cmix.go +++ b/wasm/cmix.go @@ -21,11 +21,11 @@ type Cmix struct { api *bindings.Cmix } -// newCmixJS creates a new Javascript compatible object (map[string]interface{}) -// that matches the [Cmix] structure. -func newCmixJS(api *bindings.Cmix) map[string]interface{} { +// newCmixJS creates a new Javascript compatible object (map[string]any) that +// matches the [Cmix] structure. +func newCmixJS(api *bindings.Cmix) map[string]any { c := Cmix{api} - cmix := map[string]interface{}{ + cmix := map[string]any{ // cmix.go "GetID": js.FuncOf(c.GetID), @@ -53,6 +53,7 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} { "AddHealthCallback": js.FuncOf(c.AddHealthCallback), "RemoveHealthCallback": js.FuncOf(c.RemoveHealthCallback), "RegisterClientErrorCallback": js.FuncOf(c.RegisterClientErrorCallback), + "TrackServicesWithIdentity": js.FuncOf(c.TrackServicesWithIdentity), "TrackServices": js.FuncOf(c.TrackServices), // connect.go @@ -76,14 +77,14 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} { // Users of this function should delete the storage directory on error. // // Parameters: -// - args[0] - NDF JSON ([ndf.NetworkDefinition]) (string). -// - args[1] - Storage directory path (string). -// - args[2] - Password used for storage (Uint8Array). -// - args[3] - Registration code (string). +// - args[0] - NDF JSON ([ndf.NetworkDefinition]) (string). +// - args[1] - Storage directory path (string). +// - args[2] - Password used for storage (Uint8Array). +// - args[3] - Registration code (string). // // Returns: -// - Throws a TypeError if creating new [Cmix] fails. -func NewCmix(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if creating new [Cmix] fails. +func NewCmix(_ js.Value, args []js.Value) any { password := utils.CopyBytesToGo(args[2]) err := bindings.NewCmix( @@ -107,19 +108,19 @@ func NewCmix(_ js.Value, args []js.Value) interface{} { // subprocesses to perform network operations. // // Parameters: -// - args[0] - Storage directory path (string). -// - args[1] - Password used for storage (Uint8Array). -// - args[2] - JSON of [xxdk.CMIXParams] (Uint8Array). +// - args[0] - Storage directory path (string). +// - args[1] - Password used for storage (Uint8Array). +// - args[2] - JSON of [xxdk.CMIXParams] (Uint8Array). // // Returns a promise: -// - Resolves to a Javascript representation of the [Cmix] object. -// - Rejected with an error if loading [Cmix] fails. -func LoadCmix(_ js.Value, args []js.Value) interface{} { +// - Resolves to a Javascript representation of the [Cmix] object. +// - Rejected with an error if loading [Cmix] fails. +func LoadCmix(_ js.Value, args []js.Value) any { storageDir := args[0].String() password := utils.CopyBytesToGo(args[1]) cmixParamsJSON := utils.CopyBytesToGo(args[2]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { net, err := bindings.LoadCmix(storageDir, password, cmixParamsJSON) if err != nil { reject(utils.JsTrace(err)) @@ -134,7 +135,7 @@ func LoadCmix(_ js.Value, args []js.Value) interface{} { // GetID returns the ID for this [bindings.Cmix] in the cmixTracker. // // Returns: -// - Tracker ID (int). -func (c *Cmix) GetID(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (c *Cmix) GetID(js.Value, []js.Value) any { return c.api.GetID() } diff --git a/wasm/connect.go b/wasm/connect.go index be7cbf275a84f7a9af64afdb9bea89a0add74a89..5d8e347dbb34c9adf4f724eee13a3eda43fc4f57 100644 --- a/wasm/connect.go +++ b/wasm/connect.go @@ -21,11 +21,11 @@ type Connection struct { api *bindings.Connection } -// newConnectJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [Connection] structure. -func newConnectJS(api *bindings.Connection) map[string]interface{} { +// newConnectJS creates a new Javascript compatible object (map[string]any) that +// matches the [Connection] structure. +func newConnectJS(api *bindings.Connection) map[string]any { c := Connection{api} - connectionMap := map[string]interface{}{ + connectionMap := map[string]any{ // connect.go "GetId": js.FuncOf(c.GetId), "SendE2E": js.FuncOf(c.SendE2E), @@ -40,8 +40,8 @@ func newConnectJS(api *bindings.Connection) map[string]interface{} { // GetId returns the ID for this [bindings.Connection] in the connectionTracker. // // Returns: -// - Tracker ID (int). -func (c *Connection) GetId(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (c *Connection) GetId(js.Value, []js.Value) any { return c.api.GetId() } @@ -52,20 +52,20 @@ func (c *Connection) GetId(js.Value, []js.Value) interface{} { // [partner.Manager] is confirmed. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the recipient [contact.Contact] -// (Uint8Array). -// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the recipient [contact.Contact] +// (Uint8Array). +// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). // // Returns a promise: -// - 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{} { +// - 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) any { e2eID := args[0].Int() recipientContact := utils.CopyBytesToGo(args[1]) e2eParamsJSON := utils.CopyBytesToGo(args[2]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { api, err := c.api.Connect(e2eID, recipientContact, e2eParamsJSON) if err != nil { reject(utils.JsTrace(err)) @@ -81,22 +81,22 @@ func (c *Cmix) Connect(_ js.Value, args []js.Value) interface{} { // [partner.Manager]. // // Returns: -// - []byte - the JSON marshalled bytes of the E2ESendReport object, which can -// be passed into [Cmix.WaitForRoundResult] to see if the send succeeded. +// - []byte - the JSON marshalled bytes of the E2ESendReport object, which can +// be passed into [Cmix.WaitForRoundResult] to see if the send succeeded. // // Parameters: -// - args[0] - Message type from [catalog.MessageType] (int). -// - args[1] - Message payload (Uint8Array). +// - args[0] - Message type from [catalog.MessageType] (int). +// - args[1] - Message payload (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.E2ESendReport], which can be passed -// 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{} { +// - Resolves to the JSON of the [bindings.E2ESendReport], which can be passed +// 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) any { e2eID := args[0].Int() payload := utils.CopyBytesToGo(args[1]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := c.api.SendE2E(e2eID, payload) if err != nil { reject(utils.JsTrace(err)) @@ -111,8 +111,8 @@ func (c *Connection) SendE2E(_ js.Value, args []js.Value) interface{} { // Close deletes this [Connection]'s [partner.Manager] and releases resources. // // Returns: -// - Throws a TypeError if closing fails. -func (c *Connection) Close(js.Value, []js.Value) interface{} { +// - Throws a TypeError if closing fails. +func (c *Connection) Close(js.Value, []js.Value) any { err := c.api.Close() if err != nil { utils.Throw(utils.TypeError, err) @@ -125,40 +125,40 @@ func (c *Connection) Close(js.Value, []js.Value) interface{} { // GetPartner returns the [partner.Manager] for this [Connection]. // // Returns: -// - Marshalled bytes of the partner's [id.ID] (Uint8Array). -func (c *Connection) GetPartner(js.Value, []js.Value) interface{} { +// - Marshalled bytes of the partner's [id.ID] (Uint8Array). +func (c *Connection) GetPartner(js.Value, []js.Value) any { return utils.CopyBytesToJS(c.api.GetPartner()) } // listener adheres to the [bindings.Listener] interface. type listener struct { - hear func(args ...interface{}) js.Value - name func(args ...interface{}) js.Value + hear func(args ...any) js.Value + name func(args ...any) js.Value } // Hear is called to receive a message in the UI. // // Parameters: -// - item - Returns the JSON of [bindings.Message] (Uint8Array). +// - item - Returns the JSON of [bindings.Message] (Uint8Array). func (l *listener) Hear(item []byte) { l.hear(utils.CopyBytesToJS(item)) } // Name returns a name; used for debugging. // // Returns: -// - Name (string). +// - Name (string). func (l *listener) Name() string { return l.name().String() } // RegisterListener is used for E2E reception and allows for reading data sent // from the [partner.Manager]. // // Parameters: -// - args[0] - message type from [catalog.MessageType] (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.Listener] interface. +// - args[0] - message type from [catalog.MessageType] (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.Listener] interface. // // Returns: -// - Throws a TypeError is registering the listener fails. -func (c *Connection) RegisterListener(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError is registering the listener fails. +func (c *Connection) RegisterListener(_ js.Value, args []js.Value) any { err := c.api.RegisterListener(args[0].Int(), &listener{utils.WrapCB(args[1], "Hear"), utils.WrapCB(args[1], "Name")}) if err != nil { diff --git a/wasm/delivery.go b/wasm/delivery.go index caef7edb6c03fd3969e65fce02540be52c5e2185..327f15223426bf3ac19c4d001806b8e69abdfb9e 100644 --- a/wasm/delivery.go +++ b/wasm/delivery.go @@ -22,9 +22,9 @@ import ( // thread-safe, and as such should only be called on setup. // // Parameters: -// - args[0] - A valid URL that will be used for round look up on any send -// report (string). -func SetDashboardURL(_ js.Value, args []js.Value) interface{} { +// - args[0] - A valid URL that will be used for round look up on any send +// report (string). +func SetDashboardURL(_ js.Value, args []js.Value) any { bindings.SetDashboardURL(args[0].String()) return nil @@ -33,7 +33,7 @@ func SetDashboardURL(_ js.Value, args []js.Value) interface{} { // messageDeliveryCallback wraps Javascript callbacks to adhere to the // [bindings.MessageDeliveryCallback] interface. type messageDeliveryCallback struct { - eventCallback func(args ...interface{}) js.Value + eventCallback func(args ...any) js.Value } // EventCallback gets called on the determination if all events related to a @@ -46,13 +46,13 @@ type messageDeliveryCallback struct { // If timedOut == true, delivered == false && roundResults == nil // // Parameters: -// - delivered - Returns false if any rounds in the round map were -// unsuccessful. Returns true if ALL rounds were successful (boolean). -// - timedOut - Returns true if any of the rounds timed out while being -// monitored. Returns false if all rounds statuses were returned (boolean). -// - roundResults - rounds contains a mapping of all previously requested -// rounds to their respective round results. Marshalled bytes of -// map[[id.Round]][cmix.RoundResult] (Uint8Array). +// - delivered - Returns false if any rounds in the round map were +// unsuccessful. Returns true if ALL rounds were successful (boolean). +// - timedOut - Returns true if any of the rounds timed out while being +// monitored. Returns false if all rounds statuses were returned (boolean). +// - roundResults - rounds contains a mapping of all previously requested +// rounds to their respective round results. Marshalled bytes of +// map[[id.Round]][cmix.RoundResult] (Uint8Array). func (mdc *messageDeliveryCallback) EventCallback( delivered, timedOut bool, roundResults []byte) { mdc.eventCallback(delivered, timedOut, utils.CopyBytesToJS(roundResults)) @@ -71,17 +71,17 @@ func (mdc *messageDeliveryCallback) EventCallback( // send report that inherits a [bindings.RoundsList] object. // // Parameters: -// - args[0] - JSON of [bindings.RoundsList] or JSON of any send report that -// inherits a [bindings.RoundsList] object (Uint8Array). -// - args[1] - Javascript object that has functions that implement the -// [bindings.MessageDeliveryCallback] interface. -// - args[2] - Timeout when the callback will return if no state update occurs, -// in milliseconds (int). +// - args[0] - JSON of [bindings.RoundsList] or JSON of any send report that +// inherits a [bindings.RoundsList] object (Uint8Array). +// - args[1] - Javascript object that has functions that implement the +// [bindings.MessageDeliveryCallback] interface. +// - args[2] - Timeout when the callback will return if no state update +// occurs, in milliseconds (int). // // Returns: -// - Throws a TypeError if the parameters are invalid or getting round results -// fails. -func (c *Cmix) WaitForRoundResult(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the parameters are invalid or getting round results +// fails. +func (c *Cmix) WaitForRoundResult(_ js.Value, args []js.Value) any { roundList := utils.CopyBytesToGo(args[0]) mdc := &messageDeliveryCallback{utils.WrapCB(args[1], "EventCallback")} diff --git a/wasm/dummy.go b/wasm/dummy.go index 24d04c3f8f231e4fc6a76c5e71769921f5830f65..deaf50b592a9866b1517b6f9177918d66052380a 100644 --- a/wasm/dummy.go +++ b/wasm/dummy.go @@ -21,11 +21,11 @@ type DummyTraffic struct { api *bindings.DummyTraffic } -// newDummyTrafficJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [DummyTraffic] structure. -func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]interface{} { +// newDummyTrafficJS creates a new Javascript compatible object (map[string]any) +// that matches the [DummyTraffic] structure. +func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]any { dt := DummyTraffic{newDT} - dtMap := map[string]interface{}{ + dtMap := map[string]any{ "SetStatus": js.FuncOf(dt.SetStatus), "GetStatus": js.FuncOf(dt.GetStatus), } @@ -41,19 +41,19 @@ func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]interface{} { // parameters below. // // Parameters: -// - args[0] - A [Cmix] object ID in the tracker (int). -// - args[1] - The maximum number of the random number of messages sent each -// sending cycle (int). -// - args[2] - The average duration, in milliseconds, to wait between sends -// (int). -// - args[3] - The upper bound of the interval between sending cycles, in -// milliseconds. Sends occur every average send (args[2]) +/- a random -// duration with an upper bound of args[3] (int). +// - args[0] - A [Cmix] object ID in the tracker (int). +// - args[1] - The maximum number of the random number of messages sent each +// sending cycle (int). +// - args[2] - The average duration, in milliseconds, to wait between sends +// (int). +// - args[3] - The upper bound of the interval between sending cycles, in +// milliseconds. Sends occur every average send (args[2]) +/- a random +// duration with an upper bound of args[3] (int). // // Returns: -// - Javascript representation of the DummyTraffic object. -// - Throws a TypeError if creating the manager fails. -func NewDummyTrafficManager(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the DummyTraffic object. +// - Throws a TypeError if creating the manager fails. +func NewDummyTrafficManager(_ js.Value, args []js.Value) any { dt, err := bindings.NewDummyTrafficManager( args[0].Int(), args[1].Int(), args[2].Int(), args[3].Int()) if err != nil { @@ -72,13 +72,13 @@ func NewDummyTrafficManager(_ js.Value, args []js.Value) interface{} { // thread once that operation has completed. // // Parameters: -// - args[0] - Input should be true if you want to send dummy messages and -// false if you want to pause dummy messages (boolean). +// - args[0] - Input should be true if you want to send dummy messages and +// false if you want to pause dummy messages (boolean). // // Returns: -// - Throws a TypeError if the [DummyTraffic.SetStatus] is called too -// frequently, causing the internal status channel to fill. -func (dt *DummyTraffic) SetStatus(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the [DummyTraffic.SetStatus] is called too +// frequently, causing the internal status channel to fill. +func (dt *DummyTraffic) SetStatus(_ js.Value, args []js.Value) any { err := dt.api.SetStatus(args[0].Bool()) if err != nil { utils.Throw(utils.TypeError, err) @@ -99,6 +99,6 @@ func (dt *DummyTraffic) SetStatus(_ js.Value, args []js.Value) interface{} { // - Returns true if sending thread is sending dummy messages and false if // sending thread is paused/stopped and is not sending dummy messages // (boolean). -func (dt *DummyTraffic) GetStatus(js.Value, []js.Value) interface{} { +func (dt *DummyTraffic) GetStatus(js.Value, []js.Value) any { return dt.api.GetStatus() } diff --git a/wasm/e2e.go b/wasm/e2e.go index c8dd7b08606a21b659fadc69f24a3784c3e4eed5..8d8f4ce15fa0c47f71c3bbbeccdf9484a4ccde39 100644 --- a/wasm/e2e.go +++ b/wasm/e2e.go @@ -21,11 +21,11 @@ type E2e struct { api *bindings.E2e } -// newE2eJS creates a new Javascript compatible object (map[string]interface{}) -// that matches the [E2e] structure. -func newE2eJS(api *bindings.E2e) map[string]interface{} { +// newE2eJS creates a new Javascript compatible object (map[string]any) that +// matches the [E2e] structure. +func newE2eJS(api *bindings.E2e) map[string]any { e := E2e{api} - e2eMap := map[string]interface{}{ + e2eMap := map[string]any{ // e2e.go "GetID": js.FuncOf(e.GetID), "GetContact": js.FuncOf(e.GetContact), @@ -71,8 +71,8 @@ func newE2eJS(api *bindings.E2e) map[string]interface{} { // GetID returns the ID for this [E2e] in the [E2e] tracker. // // Returns: -// - Tracker ID (int). -func (e *E2e) GetID(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (e *E2e) GetID(js.Value, []js.Value) any { return e.api.GetID() } @@ -82,16 +82,16 @@ func (e *E2e) GetID(js.Value, []js.Value) interface{} { // default [auth.Callbacks] will be used. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.AuthCallbacks] interface. -// - args[2] - JSON of the [xxdk.ReceptionIdentity] (Uint8Array). -// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.AuthCallbacks] interface. +// - args[2] - JSON of the [xxdk.ReceptionIdentity] (Uint8Array). +// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). // // Returns: -// - Javascript representation of the [E2e] object. -// - Throws a TypeError if logging in fails. -func Login(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [E2e] object. +// - Throws a TypeError if logging in fails. +func Login(_ js.Value, args []js.Value) any { callbacks := newAuthCallbacks(args[1]) identity := utils.CopyBytesToGo(args[2]) e2eParamsJSON := utils.CopyBytesToGo(args[3]) @@ -112,16 +112,16 @@ func Login(_ js.Value, args []js.Value) interface{} { // in here. If callbacks is left nil, a default [auth.Callbacks] will be used. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.AuthCallbacks] interface. -// - args[2] - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). -// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.AuthCallbacks] interface. +// - args[2] - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). +// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). // // Returns: -// - Javascript representation of the [E2e] object. -// - Throws a TypeError if logging in fails. -func LoginEphemeral(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [E2e] object. +// - Throws a TypeError if logging in fails. +func LoginEphemeral(_ js.Value, args []js.Value) any { callbacks := newAuthCallbacks(args[1]) identity := utils.CopyBytesToGo(args[2]) e2eParamsJSON := utils.CopyBytesToGo(args[3]) @@ -140,8 +140,8 @@ func LoginEphemeral(_ js.Value, args []js.Value) interface{} { // [bindings.ReceptionIdentity]. // // Returns: -// - Marshalled bytes of [contact.Contact] (Uint8Array). -func (e *E2e) GetContact(js.Value, []js.Value) interface{} { +// - Marshalled bytes of [contact.Contact] (Uint8Array). +func (e *E2e) GetContact(js.Value, []js.Value) any { return utils.CopyBytesToJS(e.api.GetContact()) } @@ -149,16 +149,16 @@ func (e *E2e) GetContact(js.Value, []js.Value) interface{} { // NDF. // // Returns: -// - User Discovery's address (string). -func (e *E2e) GetUdAddressFromNdf(js.Value, []js.Value) interface{} { +// - User Discovery's address (string). +func (e *E2e) GetUdAddressFromNdf(js.Value, []js.Value) any { return e.api.GetUdAddressFromNdf() } // GetUdCertFromNdf retrieves the User Discovery's TLS certificate from the NDF. // // Returns: -// - Public certificate in PEM format (Uint8Array). -func (e *E2e) GetUdCertFromNdf(js.Value, []js.Value) interface{} { +// - Public certificate in PEM format (Uint8Array). +func (e *E2e) GetUdCertFromNdf(js.Value, []js.Value) any { return utils.CopyBytesToJS(e.api.GetUdCertFromNdf()) } @@ -166,9 +166,9 @@ func (e *E2e) GetUdCertFromNdf(js.Value, []js.Value) interface{} { // within the NDF. // // Returns -// - Marshalled bytes of [contact.Contact] (Uint8Array). -// - Throws a TypeError if the contact file cannot be loaded. -func (e *E2e) GetUdContactFromNdf(js.Value, []js.Value) interface{} { +// - Marshalled bytes of [contact.Contact] (Uint8Array). +// - Throws a TypeError if the contact file cannot be loaded. +func (e *E2e) GetUdContactFromNdf(js.Value, []js.Value) any { b, err := e.api.GetUdContactFromNdf() if err != nil { utils.Throw(utils.TypeError, err) @@ -185,9 +185,9 @@ func (e *E2e) GetUdContactFromNdf(js.Value, []js.Value) interface{} { // authCallbacks wraps Javascript callbacks to adhere to the // [bindings.AuthCallbacks] interface. type authCallbacks struct { - request func(args ...interface{}) js.Value - confirm func(args ...interface{}) js.Value - reset func(args ...interface{}) js.Value + request func(args ...any) js.Value + confirm func(args ...any) js.Value + reset func(args ...any) js.Value } // newAuthCallbacks adds all the callbacks from the Javascript object. @@ -202,12 +202,12 @@ func newAuthCallbacks(value js.Value) *authCallbacks { // Request will be called when an auth Request message is processed. // // Parameters: -// - contact - Returns the marshalled bytes of the [contact.Contact] of the -// sender (Uint8Array). -// - receptionId - Returns the marshalled bytes of the sender's [id.ID] -// (Uint8Array). -// - ephemeralId - Returns the ephemeral ID of the sender (int). -// - roundId - Returns the ID of the round the request was sent on (int). +// - contact - Returns the marshalled bytes of the [contact.Contact] of the +// sender (Uint8Array). +// - receptionId - Returns the marshalled bytes of the sender's [id.ID] +// (Uint8Array). +// - ephemeralId - Returns the ephemeral ID of the sender (int). +// - roundId - Returns the ID of the round the request was sent on (int). func (a *authCallbacks) Request( contact, receptionId []byte, ephemeralId, roundId int64) { if a.request != nil { @@ -219,12 +219,12 @@ func (a *authCallbacks) Request( // Confirm will be called when an auth Confirm message is processed. // // Parameters: -// - contact - Returns the marshalled bytes of the [contact.Contact] of the -// sender (Uint8Array). -// - receptionId - Returns the marshalled bytes of the sender's [id.ID] -// (Uint8Array). -// - ephemeralId - Returns the ephemeral ID of the sender (int). -// - roundId - Returns the ID of the round the confirmation was sent on (int). +// - contact - Returns the marshalled bytes of the [contact.Contact] of the +// sender (Uint8Array). +// - receptionId - Returns the marshalled bytes of the sender's [id.ID] +// (Uint8Array). +// - ephemeralId - Returns the ephemeral ID of the sender (int). +// - roundId - Returns the ID of the round the confirmation was sent on (int). func (a *authCallbacks) Confirm( contact, receptionId []byte, ephemeralId, roundId int64) { if a.confirm != nil { @@ -236,12 +236,12 @@ func (a *authCallbacks) Confirm( // Reset will be called when an auth Reset operation occurs. // // Parameters: -// - contact - Returns the marshalled bytes of the [contact.Contact] of the -// sender (Uint8Array). -// - receptionId - Returns the marshalled bytes of the sender's [id.ID] -// (Uint8Array). -// - ephemeralId - Returns the ephemeral ID of the sender (int). -// - roundId - Returns the ID of the round the reset was sent on (int). +// - contact - Returns the marshalled bytes of the [contact.Contact] of the +// sender (Uint8Array). +// - receptionId - Returns the marshalled bytes of the sender's [id.ID] +// (Uint8Array). +// - ephemeralId - Returns the ephemeral ID of the sender (int). +// - roundId - Returns the ID of the round the reset was sent on (int). func (a *authCallbacks) Reset( contact, receptionId []byte, ephemeralId, roundId int64) { if a.reset != nil { diff --git a/wasm/e2eAuth.go b/wasm/e2eAuth.go index a2627800887ae25989c63d31e2b39efb7a973852..eb69ef75cd17d26b22715d0eba08bf6b5f0fc02a 100644 --- a/wasm/e2eAuth.go +++ b/wasm/e2eAuth.go @@ -33,17 +33,17 @@ import ( // will be auto resent by the cMix client. // // Parameters: -// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). -// - args[1] - JSON of [fact.FactList] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). +// - args[1] - JSON of [fact.FactList] (Uint8Array). // // Returns a promise: -// - Resolves to the ID of the round (int). -// - Rejected with an error if sending the request fails. -func (e *E2e) Request(_ js.Value, args []js.Value) interface{} { +// - Resolves to the ID of the round (int). +// - Rejected with an error if sending the request fails. +func (e *E2e) Request(_ js.Value, args []js.Value) any { partnerContact := utils.CopyBytesToGo(args[0]) factsListJson := utils.CopyBytesToGo(args[1]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { rid, err := e.api.Request(partnerContact, factsListJson) if err != nil { reject(utils.JsTrace(err)) @@ -72,15 +72,15 @@ func (e *E2e) Request(_ js.Value, args []js.Value) interface{} { // If the confirmation must be resent, use [E2e.ReplayConfirm]. // // Parameters: -// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). // // Returns a promise: -// - Resolves to the ID of the round (int). -// - Rejected with an error if sending the confirmation fails. -func (e *E2e) Confirm(_ js.Value, args []js.Value) interface{} { +// - Resolves to the ID of the round (int). +// - Rejected with an error if sending the confirmation fails. +func (e *E2e) Confirm(_ js.Value, args []js.Value) any { partnerContact := utils.CopyBytesToGo(args[0]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { rid, err := e.api.Confirm(partnerContact) if err != nil { reject(utils.JsTrace(err)) @@ -107,15 +107,15 @@ func (e *E2e) Confirm(_ js.Value, args []js.Value) interface{} { // who is already a partner. // // Parameters: -// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). // // Returns a promise: -// - Resolves to the ID of the round (int). -// - Rejected with an error if sending the reset fails. -func (e *E2e) Reset(_ js.Value, args []js.Value) interface{} { +// - Resolves to the ID of the round (int). +// - Rejected with an error if sending the reset fails. +func (e *E2e) Reset(_ js.Value, args []js.Value) any { partnerContact := utils.CopyBytesToGo(args[0]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { rid, err := e.api.Reset(partnerContact) if err != nil { reject(utils.JsTrace(err)) @@ -136,15 +136,15 @@ func (e *E2e) Reset(_ js.Value, args []js.Value) interface{} { // This will not be useful if either side has ratcheted. // // Parameters: -// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). // // Returns a promise: -// - Resolves to the ID of the round (int). -// - Rejected with an error if resending the confirmation fails. -func (e *E2e) ReplayConfirm(_ js.Value, args []js.Value) interface{} { +// - Resolves to the ID of the round (int). +// - Rejected with an error if resending the confirmation fails. +func (e *E2e) ReplayConfirm(_ js.Value, args []js.Value) any { partnerContact := utils.CopyBytesToGo(args[0]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { rid, err := e.api.ReplayConfirm(partnerContact) if err != nil { reject(utils.JsTrace(err)) @@ -158,7 +158,7 @@ func (e *E2e) ReplayConfirm(_ js.Value, args []js.Value) interface{} { // CallAllReceivedRequests will iterate through all pending contact requests and // replay them on the callbacks. -func (e *E2e) CallAllReceivedRequests(js.Value, []js.Value) interface{} { +func (e *E2e) CallAllReceivedRequests(js.Value, []js.Value) any { e.api.CallAllReceivedRequests() return nil } @@ -166,11 +166,11 @@ func (e *E2e) CallAllReceivedRequests(js.Value, []js.Value) interface{} { // DeleteRequest deletes sent or received requests for a specific partner ID. // // Parameters: -// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). // // Returns: -// - Throws TypeError if the deletion fails. -func (e *E2e) DeleteRequest(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if the deletion fails. +func (e *E2e) DeleteRequest(_ js.Value, args []js.Value) any { partnerContact := utils.CopyBytesToGo(args[0]) err := e.api.DeleteRequest(partnerContact) if err != nil { @@ -184,8 +184,8 @@ func (e *E2e) DeleteRequest(_ js.Value, args []js.Value) interface{} { // DeleteAllRequests clears all requests from auth storage. // // Returns: -// - Throws TypeError if the deletion fails. -func (e *E2e) DeleteAllRequests(js.Value, []js.Value) interface{} { +// - Throws TypeError if the deletion fails. +func (e *E2e) DeleteAllRequests(js.Value, []js.Value) any { err := e.api.DeleteAllRequests() if err != nil { utils.Throw(utils.TypeError, err) @@ -198,8 +198,8 @@ func (e *E2e) DeleteAllRequests(js.Value, []js.Value) interface{} { // DeleteSentRequests clears all sent requests from auth storage. // // Returns: -// - Throws TypeError if the deletion fails. -func (e *E2e) DeleteSentRequests(js.Value, []js.Value) interface{} { +// - Throws TypeError if the deletion fails. +func (e *E2e) DeleteSentRequests(js.Value, []js.Value) any { err := e.api.DeleteSentRequests() if err != nil { utils.Throw(utils.TypeError, err) @@ -212,8 +212,8 @@ func (e *E2e) DeleteSentRequests(js.Value, []js.Value) interface{} { // DeleteReceiveRequests clears all received requests from auth storage. // // Returns: -// - Throws TypeError if the deletion fails. -func (e *E2e) DeleteReceiveRequests(js.Value, []js.Value) interface{} { +// - Throws TypeError if the deletion fails. +func (e *E2e) DeleteReceiveRequests(js.Value, []js.Value) any { err := e.api.DeleteReceiveRequests() if err != nil { utils.Throw(utils.TypeError, err) @@ -226,12 +226,12 @@ func (e *E2e) DeleteReceiveRequests(js.Value, []js.Value) interface{} { // GetReceivedRequest returns a contact if there is a received request for it. // // Parameters: -// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [contact.Contact] (Uint8Array). // // Returns: -// - Marshalled bytes of [contact.Contact] (Uint8Array). -// - Throws TypeError if getting the received request fails. -func (e *E2e) GetReceivedRequest(_ js.Value, args []js.Value) interface{} { +// - Marshalled bytes of [contact.Contact] (Uint8Array). +// - Throws TypeError if getting the received request fails. +func (e *E2e) GetReceivedRequest(_ js.Value, args []js.Value) any { partnerContact := utils.CopyBytesToGo(args[0]) c, err := e.api.GetReceivedRequest(partnerContact) if err != nil { @@ -245,14 +245,16 @@ func (e *E2e) GetReceivedRequest(_ js.Value, args []js.Value) interface{} { // VerifyOwnership checks if the received ownership proof is valid. // // Parameters: -// - args[0] - Marshalled bytes of the received [contact.Contact] (Uint8Array). -// - args[1] - Marshalled bytes of the verified [contact.Contact] (Uint8Array). -// - args[2] - ID of [E2e] object in tracker (int). +// - args[0] - Marshalled bytes of the received [contact.Contact] +// (Uint8Array). +// - args[1] - Marshalled bytes of the verified [contact.Contact] +// (Uint8Array). +// - args[2] - ID of [E2e] object in tracker (int). // // Returns: -// - Returns true if the ownership is valid (boolean). -// - Throws TypeError if loading the parameters fails. -func (e *E2e) VerifyOwnership(_ js.Value, args []js.Value) interface{} { +// - Returns true if the ownership is valid (boolean). +// - Throws TypeError if loading the parameters fails. +func (e *E2e) VerifyOwnership(_ js.Value, args []js.Value) any { receivedContact := utils.CopyBytesToGo(args[0]) verifiedContact := utils.CopyBytesToGo(args[1]) isValid, err := e.api.VerifyOwnership( @@ -269,13 +271,13 @@ func (e *E2e) VerifyOwnership(_ js.Value, args []js.Value) interface{} { // callback for the given partner ID. // // Parameters: -// - args[0] - Marshalled bytes of the partner [id.ID] (Uint8Array). -// - args[1] - Javascript object that has functions that implement the -// [bindings.AuthCallbacks] interface. +// - args[0] - Marshalled bytes of the partner [id.ID] (Uint8Array). +// - args[1] - Javascript object that has functions that implement the +// [bindings.AuthCallbacks] interface. // // Returns: -// - Throws TypeError if the [id.ID] cannot be unmarshalled. -func (e *E2e) AddPartnerCallback(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if the [id.ID] cannot be unmarshalled. +func (e *E2e) AddPartnerCallback(_ js.Value, args []js.Value) any { partnerID := utils.CopyBytesToGo(args[0]) callbacks := newAuthCallbacks(args[1]) err := e.api.AddPartnerCallback(partnerID, callbacks) @@ -291,11 +293,11 @@ func (e *E2e) AddPartnerCallback(_ js.Value, args []js.Value) interface{} { // auth callback for the given partner ID. // // Parameters: -// - args[0] - Marshalled bytes of the partner [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [id.ID] (Uint8Array). // // Returns: -// - Throws TypeError if the [id.ID] cannot be unmarshalled. -func (e *E2e) DeletePartnerCallback(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if the [id.ID] cannot be unmarshalled. +func (e *E2e) DeletePartnerCallback(_ js.Value, args []js.Value) any { partnerID := utils.CopyBytesToGo(args[0]) err := e.api.DeletePartnerCallback(partnerID) if err != nil { diff --git a/wasm/e2eHandler.go b/wasm/e2eHandler.go index 556f9699da670662d1a5294c7d7407d02e79304c..bff44e6aa48567e5c6afae5dca439b6fa93a6fa1 100644 --- a/wasm/e2eHandler.go +++ b/wasm/e2eHandler.go @@ -17,19 +17,19 @@ import ( // GetReceptionID returns the marshalled default IDs. // // Returns: -// - Marshalled bytes of [id.ID] (Uint8Array). -func (e *E2e) GetReceptionID(js.Value, []js.Value) interface{} { +// - Marshalled bytes of [id.ID] (Uint8Array). +func (e *E2e) GetReceptionID(js.Value, []js.Value) any { return utils.CopyBytesToJS(e.api.GetReceptionID()) } // DeleteContact removes a partner from [E2e]'s storage. // // Parameters: -// - args[0] - Marshalled bytes of the partner [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes of the partner [id.ID] (Uint8Array). // // Returns: -// - Throws TypeError if deleting the partner fails. -func (e *E2e) DeleteContact(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if deleting the partner fails. +func (e *E2e) DeleteContact(_ js.Value, args []js.Value) any { err := e.api.DeleteContact(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -42,9 +42,9 @@ func (e *E2e) DeleteContact(_ js.Value, args []js.Value) interface{} { // relationship with. // // Returns: -// - JSON of array of [id.ID] (Uint8Array). -// - Throws TypeError if getting partner IDs fails. -func (e *E2e) GetAllPartnerIDs(js.Value, []js.Value) interface{} { +// - JSON of array of [id.ID] (Uint8Array). +// - Throws TypeError if getting partner IDs fails. +func (e *E2e) GetAllPartnerIDs(js.Value, []js.Value) any { partnerIDs, err := e.api.GetAllPartnerIDs() if err != nil { utils.Throw(utils.TypeError, err) @@ -56,8 +56,8 @@ func (e *E2e) GetAllPartnerIDs(js.Value, []js.Value) interface{} { // PayloadSize returns the max payload size for a partitionable E2E message. // // Returns: -// - Max payload size (int). -func (e *E2e) PayloadSize(js.Value, []js.Value) interface{} { +// - Max payload size (int). +func (e *E2e) PayloadSize(js.Value, []js.Value) any { return e.api.PayloadSize() } @@ -65,8 +65,8 @@ func (e *E2e) PayloadSize(js.Value, []js.Value) interface{} { // after the first payload. // // Returns: -// - Max payload size (int). -func (e *E2e) SecondPartitionSize(js.Value, []js.Value) interface{} { +// - Max payload size (int). +func (e *E2e) SecondPartitionSize(js.Value, []js.Value) any { return e.api.SecondPartitionSize() } @@ -74,11 +74,11 @@ func (e *E2e) SecondPartitionSize(js.Value, []js.Value) interface{} { // The first payload is index 0. // // Parameters: -// - args[0] - Payload index (int). +// - args[0] - Payload index (int). // // Returns: -// - Partition payload size (int). -func (e *E2e) PartitionSize(_ js.Value, args []js.Value) interface{} { +// - Partition payload size (int). +func (e *E2e) PartitionSize(_ js.Value, args []js.Value) any { return e.api.PartitionSize(args[0].Int()) } @@ -86,8 +86,8 @@ func (e *E2e) PartitionSize(_ js.Value, args []js.Value) interface{} { // payload. // // Returns: -// - Max partition payload size (int). -func (e *E2e) FirstPartitionSize(js.Value, []js.Value) interface{} { +// - Max partition payload size (int). +func (e *E2e) FirstPartitionSize(js.Value, []js.Value) any { return e.api.FirstPartitionSize() } @@ -95,9 +95,9 @@ func (e *E2e) FirstPartitionSize(js.Value, []js.Value) interface{} { // key. // // Returns: -// - JSON of [cyclic.Int] (Uint8Array). -// - Throws TypeError if getting the key fails. -func (e *E2e) GetHistoricalDHPrivkey(js.Value, []js.Value) interface{} { +// - JSON of [cyclic.Int] (Uint8Array). +// - Throws TypeError if getting the key fails. +func (e *E2e) GetHistoricalDHPrivkey(js.Value, []js.Value) any { privKey, err := e.api.GetHistoricalDHPrivkey() if err != nil { utils.Throw(utils.TypeError, err) @@ -110,9 +110,9 @@ func (e *E2e) GetHistoricalDHPrivkey(js.Value, []js.Value) interface{} { // key. // // Returns: -// - JSON of [cyclic.Int] (Uint8Array). -// - Throws TypeError if getting the key fails. -func (e *E2e) GetHistoricalDHPubkey(js.Value, []js.Value) interface{} { +// - JSON of [cyclic.Int] (Uint8Array). +// - Throws TypeError if getting the key fails. +func (e *E2e) GetHistoricalDHPubkey(js.Value, []js.Value) any { pubKey, err := e.api.GetHistoricalDHPubkey() if err != nil { utils.Throw(utils.TypeError, err) @@ -125,12 +125,12 @@ func (e *E2e) GetHistoricalDHPubkey(js.Value, []js.Value) interface{} { // partner exists, otherwise returns false. // // Parameters: -// - args[0] - Marshalled bytes of [id.ID] (Uint8Array). +// - args[0] - Marshalled bytes of [id.ID] (Uint8Array). // // Returns: -// - Existence of authenticated channel (boolean). -// - Throws TypeError if unmarshalling the ID or getting the channel fails. -func (e *E2e) HasAuthenticatedChannel(_ js.Value, args []js.Value) interface{} { +// - Existence of authenticated channel (boolean). +// - Throws TypeError if unmarshalling the ID or getting the channel fails. +func (e *E2e) HasAuthenticatedChannel(_ js.Value, args []js.Value) any { exists, err := e.api.HasAuthenticatedChannel(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -142,11 +142,11 @@ func (e *E2e) HasAuthenticatedChannel(_ js.Value, args []js.Value) interface{} { // RemoveService removes all services for the given tag. // // Parameters: -// - args[0] - Tag of services to remove (string). +// - args[0] - Tag of services to remove (string). // // Returns: -// - Throws TypeError if removing the services fails. -func (e *E2e) RemoveService(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if removing the services fails. +func (e *E2e) RemoveService(_ js.Value, args []js.Value) any { err := e.api.RemoveService(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -160,22 +160,22 @@ func (e *E2e) RemoveService(_ js.Value, args []js.Value) interface{} { // message type, per the given parameters--encrypted with end-to-end encryption. // // Parameters: -// - args[0] - Message type from [catalog.MessageType] (int). -// - args[1] - Marshalled bytes of [id.ID] (Uint8Array). -// - args[2] - Message payload (Uint8Array). -// - args[3] - JSON [xxdk.E2EParams] (Uint8Array). +// - args[0] - Message type from [catalog.MessageType] (int). +// - args[1] - Marshalled bytes of [id.ID] (Uint8Array). +// - args[2] - Message payload (Uint8Array). +// - args[3] - JSON [xxdk.E2EParams] (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.E2ESendReport], which can be passed -// 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{} { +// - Resolves to the JSON of the [bindings.E2ESendReport], which can be passed +// 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) any { 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) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := e.api.SendE2E(mt, recipientId, payload, e2eParams) if err != nil { reject(utils.JsTrace(err)) @@ -190,19 +190,19 @@ func (e *E2e) SendE2E(_ js.Value, args []js.Value) interface{} { // processor wraps Javascript callbacks to adhere to the [bindings.Processor] // interface. type processor struct { - process func(args ...interface{}) js.Value - string func(args ...interface{}) js.Value + process func(args ...any) js.Value + string func(args ...any) js.Value } // Process decrypts and hands off the message to its internal down stream // message processing system. // // Parameters: -// - message - Returns the message contents (Uint8Array). -// - receptionId - Returns the marshalled bytes of the sender's [id.ID] -// (Uint8Array). -// - ephemeralId - Returns the ephemeral ID of the sender (int). -// - roundId - Returns the ID of the round sent on (int). +// - message - Returns the message contents (Uint8Array). +// - receptionId - Returns the marshalled bytes of the sender's [id.ID] +// (Uint8Array). +// - ephemeralId - Returns the ephemeral ID of the sender (int). +// - roundId - Returns the ID of the round sent on (int). func (p *processor) Process( message, receptionId []byte, ephemeralId, roundId int64) { p.process(utils.CopyBytesToJS(message), utils.CopyBytesToJS(receptionId), @@ -224,13 +224,13 @@ func (p *processor) String() string { // that piggyback on e2e relationships to start communication. // // Parameters: -// - args[0] - tag for the service (string). -// - args[1] - Javascript object that has functions that implement the -// [bindings.Processor] interface. +// - args[0] - tag for the service (string). +// - args[1] - Javascript object that has functions that implement the +// [bindings.Processor] interface. // // Returns: -// - Throws TypeError if registering the service fails. -func (e *E2e) AddService(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if registering the service fails. +func (e *E2e) AddService(_ js.Value, args []js.Value) any { p := &processor{ utils.WrapCB(args[1], "Process"), utils.WrapCB(args[1], "String")} @@ -246,16 +246,16 @@ func (e *E2e) AddService(_ js.Value, args []js.Value) interface{} { // RegisterListener registers a new listener. // // Parameters: -// - args[0] - Marshalled byte of the user [id.ID] who sends messages to this -// user that this function will register a listener for (Uint8Array). -// - args[1] - Message type from [catalog.MessageType] you want to listen for -// (int). -// - args[2] - Javascript object that has functions that implement the -// [bindings.Listener] interface; do not pass nil as the listener. +// - args[0] - Marshalled byte of the user [id.ID] who sends messages to this +// user that this function will register a listener for (Uint8Array). +// - args[1] - Message type from [catalog.MessageType] you want to listen for +// (int). +// - args[2] - Javascript object that has functions that implement the +// [bindings.Listener] interface; do not pass nil as the listener. // // Returns: -// - Throws TypeError if registering the service fails. -func (e *E2e) RegisterListener(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if registering the service fails. +func (e *E2e) RegisterListener(_ js.Value, args []js.Value) any { recipientId := utils.CopyBytesToGo(args[0]) l := &listener{utils.WrapCB(args[2], "Hear"), utils.WrapCB(args[2], "Name")} diff --git a/wasm/errors.go b/wasm/errors.go index f885ca8eb7d20e509ce66c0eaf148c743eef4e69..9299c60e0d9c02e81a1ea54755c26d7be62b87bf 100644 --- a/wasm/errors.go +++ b/wasm/errors.go @@ -26,9 +26,9 @@ import ( // - args[0] - an error returned from the backend (string). // // Returns -// - A user-friendly error message. This should be devoid of technical speak -// but still be meaningful for front-end or back-end teams (string). -func CreateUserFriendlyErrorMessage(_ js.Value, args []js.Value) interface{} { +// - A user-friendly error message. This should be devoid of technical speak +// but still be meaningful for front-end or back-end teams (string). +func CreateUserFriendlyErrorMessage(_ js.Value, args []js.Value) any { return bindings.CreateUserFriendlyErrorMessage(args[0].String()) } @@ -37,19 +37,20 @@ func CreateUserFriendlyErrorMessage(_ js.Value, args []js.Value) interface{} { // messages. // // Parameters: -// - args[0] - Contents of a JSON file whose format conforms to the example -// below (string). +// - args[0] - Contents of a JSON file whose format conforms to the example +// below (string). // // Example Input: -// { -// "Failed to Unmarshal Conversation": "Could not retrieve conversation", -// "Failed to unmarshal SentRequestMap": "Failed to pull up friend requests", -// "cannot create username when network is not health": "Cannot create username, unable to connect to network", -// } +// +// { +// "Failed to Unmarshal Conversation": "Could not retrieve conversation", +// "Failed to unmarshal SentRequestMap": "Failed to pull up friend requests", +// "cannot create username when network is not health": "Cannot create username, unable to connect to network", +// } // // Returns: -// - Throws a TypeError if the JSON cannot be unmarshalled. -func UpdateCommonErrors(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the JSON cannot be unmarshalled. +func UpdateCommonErrors(_ js.Value, args []js.Value) any { err := bindings.UpdateCommonErrors(args[0].String()) if err != nil { utils.Throw(utils.TypeError, err) diff --git a/wasm/fileTransfer.go b/wasm/fileTransfer.go index 6b63d4e59191da21959691a6a4d41a56de342f91..0083a98a78b2544f90b96623b88157b9dd70acb2 100644 --- a/wasm/fileTransfer.go +++ b/wasm/fileTransfer.go @@ -25,11 +25,11 @@ type FileTransfer struct { api *bindings.FileTransfer } -// newFileTransferJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [FileTransfer] structure. -func newFileTransferJS(api *bindings.FileTransfer) map[string]interface{} { +// newFileTransferJS creates a new Javascript compatible object (map[string]any) +// that matches the [FileTransfer] structure. +func newFileTransferJS(api *bindings.FileTransfer) map[string]any { ft := FileTransfer{api} - ftMap := map[string]interface{}{ + ftMap := map[string]any{ // Main functions "Send": js.FuncOf(ft.Send), "Receive": js.FuncOf(ft.Receive), @@ -54,14 +54,14 @@ func newFileTransferJS(api *bindings.FileTransfer) map[string]interface{} { // receiveFileCallback wraps Javascript callbacks to adhere to the // [bindings.ReceiveFileCallback] interface. type receiveFileCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called when a new file transfer is received. // // Parameters: -// - payload - Returns the contents of the message. JSON of -// [bindings.ReceivedFile] (Uint8Array). +// - payload - Returns the contents of the message. JSON of +// [bindings.ReceivedFile] (Uint8Array). func (rfc *receiveFileCallback) Callback(payload []byte) { rfc.callback(utils.CopyBytesToJS(payload)) } @@ -69,18 +69,18 @@ func (rfc *receiveFileCallback) Callback(payload []byte) { // fileTransferSentProgressCallback wraps Javascript callbacks to adhere to the // [bindings.FileTransferSentProgressCallback] interface. type fileTransferSentProgressCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called when a new file transfer is received. // // Parameters: -// - payload - Returns the contents of the message. JSON of [bindings.Progress] -// (Uint8Array). -// - t - Returns a tracker that allows the lookup of the status of any file -// part. It is a Javascript object that matches the functions on -// [FilePartTracker]. -// - err - Returns an error on failure (Error). +// - payload - Returns the contents of the message. JSON of +// [bindings.Progress] (Uint8Array). +// - t - Returns a tracker that allows the lookup of the status of any file +// part. It is a Javascript object that matches the functions on +// [FilePartTracker]. +// - err - Returns an error on failure (Error). func (spc *fileTransferSentProgressCallback) Callback( payload []byte, t *bindings.FilePartTracker, err error) { spc.callback(utils.CopyBytesToJS(payload), newFilePartTrackerJS(t), @@ -90,18 +90,18 @@ func (spc *fileTransferSentProgressCallback) Callback( // fileTransferReceiveProgressCallback wraps Javascript callbacks to adhere to // the [bindings.FileTransferReceiveProgressCallback] interface. type fileTransferReceiveProgressCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called when a file part is sent or an error occurs. // // Parameters: -// - payload - Returns the contents of the message. JSON of [bindings.Progress] -// (Uint8Array). -// - t - Returns a tracker that allows the lookup of the status of any file -// part. It is a Javascript object that matches the functions on -// [FilePartTracker]. -// - err - Returns an error on failure (Error). +// - payload - Returns the contents of the message. JSON of +// [bindings.Progress] (Uint8Array). +// - t - Returns a tracker that allows the lookup of the status of any file +// part. It is a Javascript object that matches the functions on +// [FilePartTracker]. +// - err - Returns an error on failure (Error). func (rpc *fileTransferReceiveProgressCallback) Callback( payload []byte, t *bindings.FilePartTracker, err error) { rpc.callback(utils.CopyBytesToJS(payload), newFilePartTrackerJS(t), @@ -115,17 +115,17 @@ func (rpc *fileTransferReceiveProgressCallback) Callback( // InitFileTransfer creates a bindings-level file transfer manager. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.ReceiveFileCallback] interface. -// - args[2] - JSON of [gitlab.com/elixxir/client/v4/fileTransfer/e2e.Params] -// (Uint8Array). -// - args[3] - JSON of [fileTransfer.Params] (Uint8Array). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.ReceiveFileCallback] interface. +// - args[2] - JSON of [gitlab.com/elixxir/client/v4/fileTransfer/e2e.Params] +// (Uint8Array). +// - args[3] - JSON of [fileTransfer.Params] (Uint8Array). // // Returns: -// - Javascript representation of the [FileTransfer] object. -// - Throws a TypeError initialising the file transfer manager fails. -func InitFileTransfer(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [FileTransfer] object. +// - Throws a TypeError initialising the file transfer manager fails. +func InitFileTransfer(_ js.Value, args []js.Value) any { rfc := &receiveFileCallback{utils.WrapCB(args[1], "Callback")} e2eFileTransferParamsJson := utils.CopyBytesToGo(args[2]) fileTransferParamsJson := utils.CopyBytesToGo(args[3]) @@ -143,24 +143,24 @@ func InitFileTransfer(_ js.Value, args []js.Value) interface{} { // Send is the bindings-level function for sending a file. // // Parameters: -// - args[0] - JSON of [bindings.FileSend] (Uint8Array). -// - args[1] - Marshalled bytes of the recipient [id.ID] (Uint8Array). -// - args[2] - Number of retries allowed (float). -// - args[3] - Javascript object that has functions that implement the -// [bindings.FileTransferSentProgressCallback] interface. -// - args[4] - Duration, in milliseconds, to wait between progress callbacks -// triggering (int). +// - args[0] - JSON of [bindings.FileSend] (Uint8Array). +// - args[1] - Marshalled bytes of the recipient [id.ID] (Uint8Array). +// - args[2] - Number of retries allowed (float). +// - args[3] - Javascript object that has functions that implement the +// [bindings.FileTransferSentProgressCallback] interface. +// - args[4] - Duration, in milliseconds, to wait between progress callbacks +// triggering (int). // // Returns a promise: -// - Resolves to a unique ID for this file transfer (Uint8Array). -// - Rejected with an error if sending fails. -func (f *FileTransfer) Send(_ js.Value, args []js.Value) interface{} { +// - Resolves to a unique ID for this file transfer (Uint8Array). +// - Rejected with an error if sending fails. +func (f *FileTransfer) Send(_ js.Value, args []js.Value) any { payload := utils.CopyBytesToGo(args[0]) recipientID := utils.CopyBytesToGo(args[1]) retry := float32(args[2].Float()) spc := &fileTransferSentProgressCallback{utils.WrapCB(args[3], "Callback")} - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { ftID, err := f.api.Send(payload, recipientID, retry, spc, args[4].Int()) if err != nil { reject(utils.JsTrace(err)) @@ -181,13 +181,13 @@ func (f *FileTransfer) Send(_ js.Value, args []js.Value) interface{} { // file transfer is complete. // // Parameters: -// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). +// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). // // Returns: -// - File contents (Uint8Array). -// - Throws a TypeError the file transfer is incomplete or Receive has already -// been called. -func (f *FileTransfer) Receive(_ js.Value, args []js.Value) interface{} { +// - File contents (Uint8Array). +// - Throws a TypeError the file transfer is incomplete or Receive has already +// been called. +func (f *FileTransfer) Receive(_ js.Value, args []js.Value) any { file, err := f.api.Receive(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -205,11 +205,11 @@ func (f *FileTransfer) Receive(_ js.Value, args []js.Value) interface{} { // reported by the progress callback). // // Parameters: -// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). +// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). // // Returns: -// - Throws a TypeError if the file transfer is incomplete. -func (f *FileTransfer) CloseSend(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the file transfer is incomplete. +func (f *FileTransfer) CloseSend(_ js.Value, args []js.Value) any { err := f.api.CloseSend(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -230,16 +230,16 @@ func (f *FileTransfer) CloseSend(_ js.Value, args []js.Value) interface{} { // called when resuming clients or registering extra callbacks. // // Parameters: -// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). -// - args[1] - Javascript object that has functions that implement the -// [bindings.FileTransferSentProgressCallback] interface. -// - args[2] - Duration, in milliseconds, to wait between progress callbacks -// triggering (int). +// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). +// - args[1] - Javascript object that has functions that implement the +// [bindings.FileTransferSentProgressCallback] interface. +// - args[2] - Duration, in milliseconds, to wait between progress callbacks +// triggering (int). // // Returns: -// - Throws a TypeError if registering the callback fails. +// - Throws a TypeError if registering the callback fails. func (f *FileTransfer) RegisterSentProgressCallback( - _ js.Value, args []js.Value) interface{} { + _ js.Value, args []js.Value) any { tidBytes := utils.CopyBytesToGo(args[0]) spc := &fileTransferSentProgressCallback{utils.WrapCB(args[1], "Callback")} @@ -258,16 +258,16 @@ func (f *FileTransfer) RegisterSentProgressCallback( // This should be done when a new transfer is received on the ReceiveCallback. // // Parameters: -// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). -// - args[1] - Javascript object that has functions that implement the -// [bindings.FileTransferReceiveProgressCallback] interface. -// - args[2] - Duration, in milliseconds, to wait between progress callbacks -// triggering (int). +// - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). +// - args[1] - Javascript object that has functions that implement the +// [bindings.FileTransferReceiveProgressCallback] interface. +// - args[2] - Duration, in milliseconds, to wait between progress callbacks +// triggering (int). // // Returns: -// - Throws a TypeError if registering the callback fails. +// - Throws a TypeError if registering the callback fails. func (f *FileTransfer) RegisterReceivedProgressCallback( - _ js.Value, args []js.Value) interface{} { + _ js.Value, args []js.Value) any { tidBytes := utils.CopyBytesToGo(args[0]) rpc := &fileTransferReceiveProgressCallback{utils.WrapCB(args[1], "Callback")} @@ -288,32 +288,32 @@ func (f *FileTransfer) RegisterReceivedProgressCallback( // MaxFileNameLen returns the max number of bytes allowed for a file name. // // Returns: -// - Max file name length (int). -func (f *FileTransfer) MaxFileNameLen(js.Value, []js.Value) interface{} { +// - Max file name length (int). +func (f *FileTransfer) MaxFileNameLen(js.Value, []js.Value) any { return f.api.MaxFileNameLen() } // MaxFileTypeLen returns the max number of bytes allowed for a file type. // // Returns: -// - Max file type length (int). -func (f *FileTransfer) MaxFileTypeLen(js.Value, []js.Value) interface{} { +// - Max file type length (int). +func (f *FileTransfer) MaxFileTypeLen(js.Value, []js.Value) any { return f.api.MaxFileTypeLen() } // MaxFileSize returns the max number of bytes allowed for a file. // // Returns: -// - Max file size (int). -func (f *FileTransfer) MaxFileSize(js.Value, []js.Value) interface{} { +// - Max file size (int). +func (f *FileTransfer) MaxFileSize(js.Value, []js.Value) any { return f.api.MaxFileSize() } // MaxPreviewSize returns the max number of bytes allowed for a file preview. // // Returns: -// - Max preview size (int). -func (f *FileTransfer) MaxPreviewSize(js.Value, []js.Value) interface{} { +// - Max preview size (int). +func (f *FileTransfer) MaxPreviewSize(js.Value, []js.Value) any { return f.api.MaxPreviewSize() } @@ -328,11 +328,10 @@ type FilePartTracker struct { } // newFilePartTrackerJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [FilePartTracker] -// structure. -func newFilePartTrackerJS(api *bindings.FilePartTracker) map[string]interface{} { +// (map[string]any) that matches the [FilePartTracker] structure. +func newFilePartTrackerJS(api *bindings.FilePartTracker) map[string]any { fpt := FilePartTracker{api} - ftMap := map[string]interface{}{ + ftMap := map[string]any{ "GetPartStatus": js.FuncOf(fpt.GetPartStatus), "GetNumParts": js.FuncOf(fpt.GetNumParts), } @@ -343,24 +342,24 @@ func newFilePartTrackerJS(api *bindings.FilePartTracker) map[string]interface{} // GetPartStatus returns the status of the file part with the given part number. // // The possible values for the status are: -// - 0 < Part does not exist -// - 0 = unsent -// - 1 = arrived (sender has sent a part, and it has arrived) -// - 2 = received (receiver has received a part) +// - 0 < Part does not exist +// - 0 = unsent +// - 1 = arrived (sender has sent a part, and it has arrived) +// - 2 = received (receiver has received a part) // // Parameters: -// - args[0] - Index of part (int). +// - args[0] - Index of part (int). // // Returns: -// - Part status (int). -func (fpt *FilePartTracker) GetPartStatus(_ js.Value, args []js.Value) interface{} { +// - Part status (int). +func (fpt *FilePartTracker) GetPartStatus(_ js.Value, args []js.Value) any { return fpt.api.GetPartStatus(args[0].Int()) } // GetNumParts returns the total number of file parts in the transfer. // // Returns: -// - Number of parts (int). -func (fpt *FilePartTracker) GetNumParts(js.Value, []js.Value) interface{} { +// - Number of parts (int). +func (fpt *FilePartTracker) GetNumParts(js.Value, []js.Value) any { return fpt.api.GetNumParts() } diff --git a/wasm/follow.go b/wasm/follow.go index 684b0ffcc90ffe66fe10d84469fdd473f65d34b3..5cb5b58ba398c452ebd9ed5d13de2af8951f0c32 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -29,32 +29,32 @@ import ( // tracks the network events and hands them off to workers for handling. // - Historical Round Retrieval (/network/rounds/historical.go) // retrieves data about rounds that are too old to be stored by the client. -// - Message Retrieval Worker Group (/network/rounds/retrieve.go) -// requests all messages in a given round from the gateway of the last -// nodes. -// - Message Handling Worker Group (/network/message/handle.go) -// decrypts and partitions messages when signals via the Switchboard. -// - Health Tracker (/network/health), -// via the network instance, tracks the state of the network. -// - Garbled Messages (/network/message/garbled.go) -// can be signaled to check all recent messages that could be decoded. It -// uses a message store on disk for persistence. -// - Critical Messages (/network/message/critical.go) -// ensures all protocol layer mandatory messages are sent. It uses a message -// store on disk for persistence. -// - KeyExchange Trigger (/keyExchange/trigger.go) -// responds to sent rekeys and executes them. +// - Message Retrieval Worker Group (/network/rounds/retrieve.go) +// requests all messages in a given round from the gateway of the last +// nodes. +// - Message Handling Worker Group (/network/message/handle.go) +// decrypts and partitions messages when signals via the Switchboard. +// - Health Tracker (/network/health), +// via the network instance, tracks the state of the network. +// - Garbled Messages (/network/message/garbled.go) +// can be signaled to check all recent messages that could be decoded. It +// uses a message store on disk for persistence. +// - Critical Messages (/network/message/critical.go) +// ensures all protocol layer mandatory messages are sent. It uses a message +// store on disk for persistence. +// - KeyExchange Trigger (/keyExchange/trigger.go) +// responds to sent rekeys and executes them. // - KeyExchange Confirm (/keyExchange/confirm.go) -// responds to confirmations of successful rekey operations. +// responds to confirmations of successful rekey operations. // - Auth Callback (/auth/callback.go) // handles both auth confirm and requests. // // Parameters: -// - args[0] - Timeout when stopping threads in milliseconds (int). +// - args[0] - Timeout when stopping threads in milliseconds (int). // // Returns: -// - Throws a TypeError if starting the network follower fails. -func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if starting the network follower fails. +func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) any { err := c.api.StartNetworkFollower(args[0].Int()) if err != nil { utils.Throw(utils.TypeError, err) @@ -71,9 +71,9 @@ func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} { // most likely be in an unrecoverable state and need to be trashed. // // Returns: -// - Throws a TypeError if the follower is in the wrong state to stop or if it -// fails to stop. -func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { +// - Throws a TypeError if the follower is in the wrong state to stop or if it +// fails to stop. +func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) any { err := c.api.StopNetworkFollower() if err != nil { utils.Throw(utils.TypeError, err) @@ -88,14 +88,14 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { // timeout is reached. It will return true if the network is healthy. // // Parameters: -// - args[0] - Timeout when stopping threads in milliseconds (int). +// - args[0] - Timeout when stopping threads in milliseconds (int). // // Returns a promise: -// - 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{} { +// - 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) any { timeoutMS := args[0].Int() - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { if c.api.WaitForNetwork(timeoutMS) { resolve() } else { @@ -111,32 +111,33 @@ func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} { // at least 70% of the nodes. Returns false otherwise. // // Returns: -// - Returns true if network is ready to send on (boolean). -func (c *Cmix) ReadyToSend(js.Value, []js.Value) interface{} { +// - Returns true if network is ready to send on (boolean). +func (c *Cmix) ReadyToSend(js.Value, []js.Value) any { return c.api.ReadyToSend() } // NetworkFollowerStatus gets the state of the network follower. It returns a // status with the following values: -// Stopped - 0 -// Running - 2000 -// Stopping - 3000 +// +// Stopped - 0 +// Running - 2000 +// Stopping - 3000 // // Returns: -// - Network status code (int). -func (c *Cmix) NetworkFollowerStatus(js.Value, []js.Value) interface{} { +// - Network status code (int). +func (c *Cmix) NetworkFollowerStatus(js.Value, []js.Value) any { return c.api.NetworkFollowerStatus() } // GetNodeRegistrationStatus returns the current state of node registration. // // Returns: -// - JSON of [bindings.NodeRegistrationReport] containing the number of nodes -// that the user is registered with and the number of nodes present in the -// NDF. -// - An error if it cannot get the node registration status. The most likely -// cause is that the network is unhealthy. -func (c *Cmix) GetNodeRegistrationStatus(js.Value, []js.Value) interface{} { +// - JSON of [bindings.NodeRegistrationReport] containing the number of nodes +// that the user is registered with and the number of nodes present in the +// NDF. +// - An error if it cannot get the node registration status. The most likely +// cause is that the network is unhealthy. +func (c *Cmix) GetNodeRegistrationStatus(js.Value, []js.Value) any { b, err := c.api.GetNodeRegistrationStatus() if err != nil { utils.Throw(utils.TypeError, err) @@ -151,13 +152,13 @@ func (c *Cmix) GetNodeRegistrationStatus(js.Value, []js.Value) interface{} { // be a percent (0-1) of node registrations completed. // // Parameters: -// - args[0] - The percentage of nodes required to be registered with to be -// ready. This is a number between 0 and 1 (float64). +// - args[0] - The percentage of nodes required to be registered with to be +// ready. This is a number between 0 and 1 (float64). // // Returns: -// - JSON of [bindings.IsReadyInfo] (Uint8Array). -// - Throws TypeError if getting the information fails. -func (c *Cmix) IsReady(_ js.Value, args []js.Value) interface{} { +// - JSON of [bindings.IsReadyInfo] (Uint8Array). +// - Throws TypeError if getting the information fails. +func (c *Cmix) IsReady(_ js.Value, args []js.Value) any { isReadyInfo, err := c.api.IsReady(args[0].Float()) if err != nil { utils.Throw(utils.TypeError, err) @@ -171,12 +172,12 @@ func (c *Cmix) IsReady(_ js.Value, args []js.Value) interface{} { // resume them. // // Parameters: -// - args[0] - The timeout, in milliseconds, to wait when stopping threads -// before failing (int). +// - args[0] - The timeout, in milliseconds, to wait when stopping threads +// before failing (int). // // Returns: -// - Throws TypeError if pausing fails. -func (c *Cmix) PauseNodeRegistrations(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if pausing fails. +func (c *Cmix) PauseNodeRegistrations(_ js.Value, args []js.Value) any { err := c.api.PauseNodeRegistrations(args[0].Int()) if err != nil { utils.Throw(utils.TypeError, err) @@ -190,13 +191,13 @@ func (c *Cmix) PauseNodeRegistrations(_ js.Value, args []js.Value) interface{} { // registrations up to the initialized maximum. // // Parameters: -// - args[0] - The number of parallel node registrations (int). -// - args[1] - The timeout, in milliseconds, to wait when changing node -// registrations before failing (int). +// - args[0] - The number of parallel node registrations (int). +// - args[1] - The timeout, in milliseconds, to wait when changing node +// registrations before failing (int). // // Returns: -// - Throws TypeError if changing registrations fails. -func (c *Cmix) ChangeNumberOfNodeRegistrations(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if changing registrations fails. +func (c *Cmix) ChangeNumberOfNodeRegistrations(_ js.Value, args []js.Value) any { err := c.api.ChangeNumberOfNodeRegistrations(args[0].Int(), args[1].Int()) if err != nil { utils.Throw(utils.TypeError, err) @@ -214,8 +215,8 @@ func (c *Cmix) ChangeNumberOfNodeRegistrations(_ js.Value, args []js.Value) inte // may not enter the stopped state appropriately. This can be used instead. // // Returns: -// - True if there are running processes (boolean). -func (c *Cmix) HasRunningProcessies(js.Value, []js.Value) interface{} { +// - True if there are running processes (boolean). +func (c *Cmix) HasRunningProcessies(js.Value, []js.Value) any { return c.api.HasRunningProcessies() } @@ -223,8 +224,8 @@ func (c *Cmix) HasRunningProcessies(js.Value, []js.Value) interface{} { // messages can be sent. // // Returns: -// - True if the network is healthy (boolean). -func (c *Cmix) IsHealthy(js.Value, []js.Value) interface{} { +// - True if the network is healthy (boolean). +func (c *Cmix) IsHealthy(js.Value, []js.Value) any { return c.api.IsHealthy() } @@ -233,14 +234,16 @@ func (c *Cmix) IsHealthy(js.Value, []js.Value) interface{} { // conditions if multiple threads are in the process of starting or stopping. // // Returns: -// - JSON of strings (Uint8Array). +// - JSON of strings (Uint8Array). +// - Throws TypeError if getting the processes fails. // // JSON Example: -// { -// "FileTransfer{BatchBuilderThread, FilePartSendingThread#0, FilePartSendingThread#1, FilePartSendingThread#2, FilePartSendingThread#3}", -// "MessageReception Worker 0" -// } -func (c *Cmix) GetRunningProcesses(js.Value, []js.Value) interface{} { +// +// { +// "FileTransfer{BatchBuilderThread, FilePartSendingThread#0, FilePartSendingThread#1, FilePartSendingThread#2, FilePartSendingThread#3}", +// "MessageReception Worker 0" +// } +func (c *Cmix) GetRunningProcesses(js.Value, []js.Value) any { list, err := c.api.GetRunningProcesses() if err != nil { utils.Throw(utils.TypeError, err) @@ -253,26 +256,26 @@ func (c *Cmix) GetRunningProcesses(js.Value, []js.Value) interface{} { // networkHealthCallback adheres to the [bindings.NetworkHealthCallback] // interface. type networkHealthCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback receives notification if network health changes. // // Parameters: -// - health - Returns true if the network is healthy and false otherwise -// (boolean). +// - health - Returns true if the network is healthy and false otherwise +// (boolean). func (nhc *networkHealthCallback) Callback(health bool) { nhc.callback(health) } // AddHealthCallback adds a callback that gets called whenever the network // health changes. Returns a registration ID that can be used to unregister. // // Parameters: -// - args[0] - Javascript object that has functions that implement the -// [bindings.NetworkHealthCallback] interface. +// - args[0] - Javascript object that has functions that implement the +// [bindings.NetworkHealthCallback] interface. // // Returns: -// - A registration ID that can be used to unregister the callback (int). -func (c *Cmix) AddHealthCallback(_ js.Value, args []js.Value) interface{} { +// - A registration ID that can be used to unregister the callback (int). +func (c *Cmix) AddHealthCallback(_ js.Value, args []js.Value) any { return c.api.AddHealthCallback( &networkHealthCallback{utils.WrapCB(args[0], "Callback")}) } @@ -280,15 +283,15 @@ func (c *Cmix) AddHealthCallback(_ js.Value, args []js.Value) interface{} { // RemoveHealthCallback removes a health callback using its registration ID. // // Parameters: -// - args[0] - Callback registration ID (int). -func (c *Cmix) RemoveHealthCallback(_ js.Value, args []js.Value) interface{} { +// - args[0] - Callback registration ID (int). +func (c *Cmix) RemoveHealthCallback(_ js.Value, args []js.Value) any { c.api.RemoveHealthCallback(int64(args[0].Int())) return nil } // clientError adheres to the [bindings.ClientError] interface. type clientError struct { - report func(args ...interface{}) js.Value + report func(args ...any) js.Value } // Report handles errors from the network follower threads. @@ -301,9 +304,9 @@ func (ce *clientError) Report(source, message, trace string) { // StopNetworkFollower. // // Parameters: -// - args[0] - Javascript object that has functions that implement the -// [bindings.ClientError] interface. -func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) interface{} { +// - args[0] - Javascript object that has functions that implement the +// [bindings.ClientError] interface. +func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) any { c.api.RegisterClientErrorCallback( &clientError{utils.WrapCB(args[0], "Report")}) return nil @@ -312,7 +315,7 @@ func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) interfac // trackServicesCallback adheres to the [bindings.TrackServicesCallback] // interface. type trackServicesCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is the callback for [Cmix.TrackServices]. This will pass to the user @@ -321,45 +324,69 @@ type trackServicesCallback struct { // which will be non-null. // // Parameters: -// - marshalData - Returns the JSON of [message.ServiceList] (Uint8Array). -// - err - Returns an error on failure (Error). +// - marshalData - Returns the JSON of [message.ServiceList] (Uint8Array). +// - err - Returns an error on failure (Error). // // Example JSON: -// [ -// { -// "Id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", // bytes of id.ID encoded as base64 string -// "Services": [ -// { -// "Identifier": "AQID", // bytes encoded as base64 string -// "Tag": "TestTag 1", // string -// "Metadata": "BAUG" // bytes encoded as base64 string -// } -// ] -// }, -// { -// "Id": "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", -// "Services": [ -// { -// "Identifier": "AQID", -// "Tag": "TestTag 2", -// "Metadata": "BAUG" -// } -// ] -// }, -// ] +// +// [ +// { +// "Id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", // bytes of id.ID encoded as base64 string +// "Services": [ +// { +// "Identifier": "AQID", // bytes encoded as base64 string +// "Tag": "TestTag 1", // string +// "Metadata": "BAUG" // bytes encoded as base64 string +// } +// ] +// }, +// { +// "Id": "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", +// "Services": [ +// { +// "Identifier": "AQID", +// "Tag": "TestTag 2", +// "Metadata": "BAUG" +// } +// ] +// }, +// ] func (tsc *trackServicesCallback) Callback(marshalData []byte, err error) { tsc.callback(utils.CopyBytesToJS(marshalData), utils.JsTrace(err)) } +// TrackServicesWithIdentity will return via a callback the list of services the +// backend keeps track of for the provided identity. This may be passed into +// other bindings call which may need context on the available services for this +// single identity. This will only return services for the given identity. +// +// Parameters: +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.ClientError] interface. +// +// Returns: +// - Throws TypeError if the [E2e] ID is invalid. +func (c *Cmix) TrackServicesWithIdentity(_ js.Value, args []js.Value) any { + err := c.api.TrackServicesWithIdentity(args[0].Int(), + &trackServicesCallback{utils.WrapCB(args[0], "Callback")}) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return nil +} + // TrackServices will return, via a callback, the list of services that the // backend keeps track of, which is formally referred to as a // [message.ServiceList]. This may be passed into other bindings call that may // need context on the available services for this client. // // Parameters: -// - args[0] - Javascript object that has functions that implement the -// [bindings.TrackServicesCallback] interface. -func (c *Cmix) TrackServices(_ js.Value, args []js.Value) interface{} { +// - args[0] - Javascript object that has functions that implement the +// [bindings.TrackServicesCallback] interface. +func (c *Cmix) TrackServices(_ js.Value, args []js.Value) any { c.api.TrackServices( &trackServicesCallback{utils.WrapCB(args[0], "Callback")}) return nil diff --git a/wasm/group.go b/wasm/group.go index 40aaf8b3c7479765915788c3b0b61e12445175ad..f3e7710a9144ba86fd33322b05c44092dd5c89bc 100644 --- a/wasm/group.go +++ b/wasm/group.go @@ -25,11 +25,11 @@ type GroupChat struct { api *bindings.GroupChat } -// newGroupChatJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [GroupChat] structure. -func newGroupChatJS(api *bindings.GroupChat) map[string]interface{} { +// newGroupChatJS creates a new Javascript compatible object (map[string]any) +// that matches the [GroupChat] structure. +func newGroupChatJS(api *bindings.GroupChat) map[string]any { gc := GroupChat{api} - gcMap := map[string]interface{}{ + gcMap := map[string]any{ "MakeGroup": js.FuncOf(gc.MakeGroup), "ResendRequest": js.FuncOf(gc.ResendRequest), "JoinGroup": js.FuncOf(gc.JoinGroup), @@ -46,16 +46,16 @@ func newGroupChatJS(api *bindings.GroupChat) map[string]interface{} { // NewGroupChat creates a bindings-layer group chat manager. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.GroupRequest] interface. -// - args[2] - Javascript object that has functions that implement the -// [bindings.GroupChatProcessor] interface. +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.GroupRequest] interface. +// - args[2] - Javascript object that has functions that implement the +// [bindings.GroupChatProcessor] interface. // // Returns: -// - Javascript representation of the [GroupChat] object. -// - Throws a TypeError if creating the [GroupChat] fails. -func NewGroupChat(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [GroupChat] object. +// - Throws a TypeError if creating the [GroupChat] fails. +func NewGroupChat(_ js.Value, args []js.Value) any { requestFunc := &groupRequest{utils.WrapCB(args[1], "Callback")} p := &groupChatProcessor{ utils.WrapCB(args[2], "Process"), utils.WrapCB(args[2], "String")} @@ -73,24 +73,24 @@ func NewGroupChat(_ js.Value, args []js.Value) interface{} { // group. // // Parameters: -// - args[0] - JSON of array of [id.ID]; it contains the IDs of members the -// user wants to add to the group (Uint8Array). -// - args[1] - The initial message sent to all members in the group. This is an -// optional parameter and may be nil (Uint8Array). -// - args[2] - The name of the group decided by the creator. This is an -// optional parameter and may be nil. If nil the group will be assigned the -// default name (Uint8Array). +// - args[0] - JSON of array of [id.ID]; it contains the IDs of members the +// user wants to add to the group (Uint8Array). +// - args[1] - The initial message sent to all members in the group. This is +// an optional parameter and may be nil (Uint8Array). +// - args[2] - The name of the group decided by the creator. This is an +// optional parameter and may be nil. If nil the group will be assigned the +// default name (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.GroupReport], which can be passed -// into [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). -// - Rejected with an error if making the group fails. -func (g *GroupChat) MakeGroup(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.GroupReport], which can be passed +// into [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). +// - Rejected with an error if making the group fails. +func (g *GroupChat) MakeGroup(_ js.Value, args []js.Value) any { membershipBytes := utils.CopyBytesToGo(args[0]) message := utils.CopyBytesToGo(args[1]) name := utils.CopyBytesToGo(args[2]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := g.api.MakeGroup(membershipBytes, message, name) if err != nil { reject(utils.JsTrace(err)) @@ -105,16 +105,16 @@ func (g *GroupChat) MakeGroup(_ js.Value, args []js.Value) interface{} { // ResendRequest resends a group request to all members in the group. // // Parameters: -// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This can -// be found in the report returned by [GroupChat.MakeGroup]. +// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This +// can be found in the report returned by [GroupChat.MakeGroup]. // // Returns a promise: -// - Resolves to the JSON of the [bindings.GroupReport], which can be passed -// 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{} { +// - Resolves to the JSON of the [bindings.GroupReport], which can be passed +// 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) any { groupId := utils.CopyBytesToGo(args[0]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := g.api.ResendRequest(groupId) if err != nil { reject(utils.JsTrace(err)) @@ -131,12 +131,12 @@ func (g *GroupChat) ResendRequest(_ js.Value, args []js.Value) interface{} { // with the same trackedGroupId. // // Parameters: -// - args[0] - The result of calling [Group.Serialize] on any [bindings.Group] -// object returned over the bindings (Uint8Array). +// - args[0] - The result of calling [Group.Serialize] on any [bindings.Group] +// object returned over the bindings (Uint8Array). // // Returns: -// - Throws a TypeError if joining the group fails. -func (g *GroupChat) JoinGroup(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if joining the group fails. +func (g *GroupChat) JoinGroup(_ js.Value, args []js.Value) any { err := g.api.JoinGroup(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -149,12 +149,12 @@ func (g *GroupChat) JoinGroup(_ js.Value, args []js.Value) interface{} { // LeaveGroup deletes a group so a user no longer has access. // // Parameters: -// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This can -// be found in the report returned by [GroupChat.MakeGroup]. +// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This +// can be found in the report returned by [GroupChat.MakeGroup]. // // Returns: -// - Throws a TypeError if leaving the group fails. -func (g *GroupChat) LeaveGroup(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if leaving the group fails. +func (g *GroupChat) LeaveGroup(_ js.Value, args []js.Value) any { err := g.api.LeaveGroup(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -167,24 +167,24 @@ func (g *GroupChat) LeaveGroup(_ js.Value, args []js.Value) interface{} { // Send is the bindings-level function for sending to a group. // // Parameters: -// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This can -// be found in the report returned by [GroupChat.MakeGroup]. -// - args[1] - The message that the user wishes to send to the group -// (Uint8Array). -// - args[2] - The tag associated with the message (string). This tag may be -// empty. +// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This +// can be found in the report returned by [GroupChat.MakeGroup]. +// - args[1] - The message that the user wishes to send to the group +// (Uint8Array). +// - args[2] - The tag associated with the message (string). This tag may be +// empty. // // Returns a promise: -// - Resolves to the JSON of the [bindings.GroupSendReport], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - Rejected with an error if sending the message to the group fails. -func (g *GroupChat) Send(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.GroupSendReport], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - Rejected with an error if sending the message to the group fails. +func (g *GroupChat) Send(_ js.Value, args []js.Value) any { groupId := utils.CopyBytesToGo(args[0]) message := utils.CopyBytesToGo(args[1]) tag := args[2].String() - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := g.api.Send(groupId, message, tag) if err != nil { reject(utils.JsTrace(err)) @@ -199,9 +199,9 @@ func (g *GroupChat) Send(_ js.Value, args []js.Value) interface{} { // GetGroups returns a list of group IDs that the user is a member of. // // Returns: -// - JSON of array of [id.ID] representing all group ID's (Uint8Array). -// - Throws a TypeError if getting the groups fails. -func (g *GroupChat) GetGroups(js.Value, []js.Value) interface{} { +// - JSON of array of [id.ID] representing all group ID's (Uint8Array). +// - Throws a TypeError if getting the groups fails. +func (g *GroupChat) GetGroups(js.Value, []js.Value) any { groups, err := g.api.GetGroups() if err != nil { utils.Throw(utils.TypeError, err) @@ -215,13 +215,13 @@ func (g *GroupChat) GetGroups(js.Value, []js.Value) interface{} { // error "failed to find group" is returned. // // Parameters: -// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This can -// be found in the report returned by [GroupChat.MakeGroup]. +// - args[0] - The marshalled bytes of the group [id.ID] (Uint8Array). This +// can be found in the report returned by [GroupChat.MakeGroup]. // // Returns: -// - Javascript representation of the [GroupChat] object. -// - Throws a TypeError if getting the group fails. -func (g *GroupChat) GetGroup(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [GroupChat] object. +// - Throws a TypeError if getting the group fails. +func (g *GroupChat) GetGroup(_ js.Value, args []js.Value) any { grp, err := g.api.GetGroup(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -234,8 +234,8 @@ func (g *GroupChat) GetGroup(_ js.Value, args []js.Value) interface{} { // NumGroups returns the number of groups the user is a part of. // // Returns: -// - Number of groups (int). -func (g *GroupChat) NumGroups(js.Value, []js.Value) interface{} { +// - Number of groups (int). +func (g *GroupChat) NumGroups(js.Value, []js.Value) any { return g.api.NumGroups() } @@ -249,11 +249,11 @@ type Group struct { api *bindings.Group } -// newGroupJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [Group] structure. -func newGroupJS(api *bindings.Group) map[string]interface{} { +// newGroupJS creates a new Javascript compatible object (map[string]any) that +// matches the [Group] structure. +func newGroupJS(api *bindings.Group) map[string]any { g := Group{api} - gMap := map[string]interface{}{ + gMap := map[string]any{ "GetName": js.FuncOf(g.GetName), "GetID": js.FuncOf(g.GetID), "GetInitMessage": js.FuncOf(g.GetInitMessage), @@ -269,24 +269,24 @@ func newGroupJS(api *bindings.Group) map[string]interface{} { // GetName returns the name set by the user for the group. // // Returns: -// - Group name (Uint8Array). -func (g *Group) GetName(js.Value, []js.Value) interface{} { +// - Group name (Uint8Array). +func (g *Group) GetName(js.Value, []js.Value) any { return utils.CopyBytesToJS(g.api.GetName()) } // GetID return the 33-byte unique group ID. This represents the [id.ID] object. // // Returns: -// - Marshalled bytes of the group [id.ID] (Uint8Array). -func (g *Group) GetID(js.Value, []js.Value) interface{} { +// - Marshalled bytes of the group [id.ID] (Uint8Array). +func (g *Group) GetID(js.Value, []js.Value) any { return utils.CopyBytesToJS(g.api.GetID()) } // GetInitMessage returns initial message sent with the group request. // // Returns: -// - Initial group message contents (Uint8Array). -func (g *Group) GetInitMessage(js.Value, []js.Value) interface{} { +// - Initial group message contents (Uint8Array). +func (g *Group) GetInitMessage(js.Value, []js.Value) any { return utils.CopyBytesToJS(g.api.GetInitMessage()) } @@ -294,8 +294,8 @@ func (g *Group) GetInitMessage(js.Value, []js.Value) interface{} { // also the time the group requests were sent. // // Returns: -// - The time the group was created, in nanoseconds (int). -func (g *Group) GetCreatedNano(js.Value, []js.Value) interface{} { +// - The time the group was created, in nanoseconds (int). +func (g *Group) GetCreatedNano(js.Value, []js.Value) any { return g.api.GetCreatedNano() } @@ -303,8 +303,8 @@ func (g *Group) GetCreatedNano(js.Value, []js.Value) interface{} { // also the time the group requests were sent. // // Returns: -// - The time the group was created, in milliseconds (int). -func (g *Group) GetCreatedMS(js.Value, []js.Value) interface{} { +// - The time the group was created, in milliseconds (int). +func (g *Group) GetCreatedMS(js.Value, []js.Value) any { return g.api.GetCreatedMS() } @@ -313,9 +313,9 @@ func (g *Group) GetCreatedMS(js.Value, []js.Value) interface{} { // All subsequent members are ordered by their ID. // // Returns: -// - JSON of [group.Membership] (Uint8Array). -// - Throws a TypeError if marshalling fails. -func (g *Group) GetMembership(js.Value, []js.Value) interface{} { +// - JSON of [group.Membership] (Uint8Array). +// - Throws a TypeError if marshalling fails. +func (g *Group) GetMembership(js.Value, []js.Value) any { membership, err := g.api.GetMembership() if err != nil { utils.Throw(utils.TypeError, err) @@ -328,8 +328,8 @@ func (g *Group) GetMembership(js.Value, []js.Value) interface{} { // Serialize serializes the [Group]. // // Returns: -// - Byte representation of the [Group] (Uint8Array). -func (g *Group) Serialize(js.Value, []js.Value) interface{} { +// - Byte representation of the [Group] (Uint8Array). +func (g *Group) Serialize(js.Value, []js.Value) any { return utils.CopyBytesToJS(g.api.Serialize()) } @@ -337,12 +337,12 @@ func (g *Group) Serialize(js.Value, []js.Value) interface{} { // [bindings.Group] so that its methods can be called. // // Parameters: -// - args[0] - Byte representation of the [bindings.Group] (Uint8Array). +// - args[0] - Byte representation of the [bindings.Group] (Uint8Array). // // Returns: -// - Javascript representation of the [GroupChat] object. -// - Throws a TypeError if getting the group fails. -func DeserializeGroup(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [GroupChat] object. +// - Throws a TypeError if getting the group fails. +func DeserializeGroup(_ js.Value, args []js.Value) any { grp, err := bindings.DeserializeGroup(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -359,13 +359,13 @@ func DeserializeGroup(_ js.Value, args []js.Value) interface{} { // groupRequest wraps Javascript callbacks to adhere to the // [bindings.GroupRequest] interface. type groupRequest struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called when a group request is received. // // Parameters: -// - g - Returns the JSON of [bindings.Group] (Uint8Array). +// - g - Returns the JSON of [bindings.Group] (Uint8Array). func (gr *groupRequest) Callback(g *bindings.Group) { gr.callback(newGroupJS(g)) } @@ -373,22 +373,22 @@ func (gr *groupRequest) Callback(g *bindings.Group) { // groupChatProcessor wraps Javascript callbacks to adhere to the // [bindings.GroupChatProcessor] interface. type groupChatProcessor struct { - process func(args ...interface{}) js.Value - string func(args ...interface{}) js.Value + process func(args ...any) js.Value + string func(args ...any) js.Value } // Process decrypts and hands off the message to its internal down stream // message processing system. // // Parameters: -// - decryptedMessage - Returns the JSON of [bindings.GroupChatMessage] -// (Uint8Array). -// - msg - Returns the marshalled bytes of [format.Message] (Uint8Array). -// - receptionId - Returns the marshalled bytes of the sender's [id.ID] -// (Uint8Array). -// - ephemeralId - Returns the [ephemeral.Id] of the sender (int). -// - roundId - Returns the ID of the round sent on (int). -// - err - Returns an error on failure (Error). +// - decryptedMessage - Returns the JSON of [bindings.GroupChatMessage] +// (Uint8Array). +// - msg - Returns the marshalled bytes of [format.Message] (Uint8Array). +// - receptionId - Returns the marshalled bytes of the sender's [id.ID] +// (Uint8Array). +// - ephemeralId - Returns the [ephemeral.Id] of the sender (int). +// - roundId - Returns the ID of the round sent on (int). +// - err - Returns an error on failure (Error). func (gcp *groupChatProcessor) Process(decryptedMessage, msg, receptionId []byte, ephemeralId, roundId int64, roundURL string, err error) { gcp.process(utils.CopyBytesToJS(decryptedMessage), diff --git a/wasm/identity.go b/wasm/identity.go index 2a97d9004f475ce4444226c33afb68acdd4eb79b..4141b1f1b9dc0b6a2cf0f374b428118b19899363 100644 --- a/wasm/identity.go +++ b/wasm/identity.go @@ -26,13 +26,13 @@ import ( // than the keying material. // // Parameters: -// - args[0] - Storage key (string). -// - args[1] - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). -// - args[2] - ID of [Cmix] object in tracker (int). +// - args[0] - Storage key (string). +// - args[1] - JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). +// - args[2] - ID of [Cmix] object in tracker (int). // // Returns: -// - Throws a TypeError if the identity cannot be stored in storage. -func StoreReceptionIdentity(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if the identity cannot be stored in storage. +func StoreReceptionIdentity(_ js.Value, args []js.Value) any { identity := utils.CopyBytesToGo(args[1]) err := bindings.StoreReceptionIdentity( args[0].String(), identity, args[2].Int()) @@ -49,13 +49,13 @@ func StoreReceptionIdentity(_ js.Value, args []js.Value) interface{} { // given key. // // Parameters: -// - args[0] - Storage key (string). -// - args[1] - ID of [Cmix] object in tracker (int). +// - args[0] - Storage key (string). +// - args[1] - ID of [Cmix] object in tracker (int). // // Returns: -// - JSON of the stored [xxdk.ReceptionIdentity] object (Uint8Array). -// - Throws a TypeError if the identity cannot be retrieved from storage. -func LoadReceptionIdentity(_ js.Value, args []js.Value) interface{} { +// - JSON of the stored [xxdk.ReceptionIdentity] object (Uint8Array). +// - Throws a TypeError if the identity cannot be retrieved from storage. +func LoadReceptionIdentity(_ js.Value, args []js.Value) any { ri, err := bindings.LoadReceptionIdentity(args[0].String(), args[1].Int()) if err != nil { utils.Throw(utils.TypeError, err) @@ -69,10 +69,10 @@ func LoadReceptionIdentity(_ js.Value, args []js.Value) interface{} { // messages. // // Returns a promise: -// - Resolves to the JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). -// - Rejected with an error if creating a new identity fails. -func (c *Cmix) MakeReceptionIdentity(js.Value, []js.Value) interface{} { - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { +// - Resolves to the JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). +// - Rejected with an error if creating a new identity fails. +func (c *Cmix) MakeReceptionIdentity(js.Value, []js.Value) any { + promiseFn := func(resolve, reject func(args ...any) js.Value) { ri, err := c.api.MakeReceptionIdentity() if err != nil { reject(utils.JsTrace(err)) @@ -88,10 +88,10 @@ func (c *Cmix) MakeReceptionIdentity(js.Value, []js.Value) interface{} { // messages. // // Returns a promise: -// - Resolves to the JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). -// - Rejected with an error if creating a new legacy identity fails. -func (c *Cmix) MakeLegacyReceptionIdentity(js.Value, []js.Value) interface{} { - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { +// - Resolves to the JSON of the [xxdk.ReceptionIdentity] object (Uint8Array). +// - Rejected with an error if creating a new legacy identity fails. +func (c *Cmix) MakeLegacyReceptionIdentity(js.Value, []js.Value) any { + promiseFn := func(resolve, reject func(args ...any) js.Value) { ri, err := c.api.MakeLegacyReceptionIdentity() if err != nil { reject(utils.JsTrace(err)) @@ -107,9 +107,9 @@ func (c *Cmix) MakeLegacyReceptionIdentity(js.Value, []js.Value) interface{} { // the xx network. // // Returns: -// - Reception registration validation signature (Uint8Array). +// - Reception registration validation signature (Uint8Array). func (c *Cmix) GetReceptionRegistrationValidationSignature( - js.Value, []js.Value) interface{} { + js.Value, []js.Value) any { return utils.CopyBytesToJS( c.api.GetReceptionRegistrationValidationSignature()) } @@ -122,12 +122,12 @@ func (c *Cmix) GetReceptionRegistrationValidationSignature( // [xxdk.ReceptionIdentity]. // // Parameters: -// - args[0] - JSON of [xxdk.ReceptionIdentity] (Uint8Array). +// - 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{} { +// - Marshalled bytes of [contact.Contact] (string). +// - Throws a TypeError if unmarshalling the identity fails. +func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) any { // Note that this function does not appear in normal bindings identityJSON := utils.CopyBytesToGo(args[0]) identity, err := xxdk.UnmarshalReceptionIdentity(identityJSON) @@ -142,12 +142,12 @@ func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) interface{} { // GetIDFromContact returns the ID in the [contact.Contact] object. // // Parameters: -// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array). // // Returns: -// - Marshalled bytes of [id.ID] (Uint8Array). -// - Throws a TypeError if loading the ID from the contact file fails. -func GetIDFromContact(_ js.Value, args []js.Value) interface{} { +// - Marshalled bytes of [id.ID] (Uint8Array). +// - Throws a TypeError if loading the ID from the contact file fails. +func GetIDFromContact(_ js.Value, args []js.Value) any { cID, err := bindings.GetIDFromContact(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -161,12 +161,12 @@ func GetIDFromContact(_ js.Value, args []js.Value) interface{} { // object. // // Parameters: -// - args[0] - Marshalled [contact.Contact] (string). +// - args[0] - Marshalled [contact.Contact] (string). // // Returns: -// - Bytes of the [cyclic.Int] object (Uint8Array). -// - Throws a TypeError if loading the public key from the contact file fails. -func GetPubkeyFromContact(_ js.Value, args []js.Value) interface{} { +// - Bytes of the [cyclic.Int] object (Uint8Array). +// - Throws a TypeError if loading the public key from the contact file fails. +func GetPubkeyFromContact(_ js.Value, args []js.Value) any { key, err := bindings.GetPubkeyFromContact([]byte(args[0].String())) if err != nil { utils.Throw(utils.TypeError, err) @@ -184,13 +184,13 @@ func GetPubkeyFromContact(_ js.Value, args []js.Value) interface{} { // pass in empty facts in order to clear the facts. // // Parameters: -// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array). -// - args[1] - JSON of [fact.FactList] (Uint8Array). +// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array). +// - args[1] - JSON of [fact.FactList] (Uint8Array). // // Returns: -// - Marshalled bytes of the modified [contact.Contact] (string). -// - Throws a TypeError if loading or modifying the contact fails. -func SetFactsOnContact(_ js.Value, args []js.Value) interface{} { +// - Marshalled bytes of the modified [contact.Contact] (string). +// - Throws a TypeError if loading or modifying the contact fails. +func SetFactsOnContact(_ js.Value, args []js.Value) any { marshaledContact := utils.CopyBytesToGo(args[0]) factListJSON := utils.CopyBytesToGo(args[1]) c, err := bindings.SetFactsOnContact(marshaledContact, factListJSON) @@ -205,12 +205,12 @@ func SetFactsOnContact(_ js.Value, args []js.Value) interface{} { // GetFactsFromContact returns the fact list in the [contact.Contact] object. // // Parameters: -// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array). +// - args[0] - Marshalled bytes of [contact.Contact] (Uint8Array). // // Returns: -// - JSON of [fact.FactList] (Uint8Array). -// - Throws a TypeError if loading the contact fails. -func GetFactsFromContact(_ js.Value, args []js.Value) interface{} { +// - JSON of [fact.FactList] (Uint8Array). +// - Throws a TypeError if loading the contact fails. +func GetFactsFromContact(_ js.Value, args []js.Value) any { fl, err := bindings.GetFactsFromContact(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) diff --git a/wasm/logging.go b/wasm/logging.go index 78eeba4ed3bd4328771f70c1bed2622e51194e63..46358b226f0549e1f05f3bb74c08f66a81a8198e 100644 --- a/wasm/logging.go +++ b/wasm/logging.go @@ -30,6 +30,7 @@ var logListeners []jww.LogListener // messages will be printed). // // Log level options: +// // TRACE - 0 // DEBUG - 1 // INFO - 2 @@ -41,11 +42,11 @@ var logListeners []jww.LogListener // The default log level without updates is INFO. // // Parameters: -// - args[0] - Log level (int). +// - args[0] - Log level (int). // // Returns: -// - Throws TypeError if the log level is invalid. -func LogLevel(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if the log level is invalid. +func LogLevel(_ js.Value, args []js.Value) any { threshold := jww.Threshold(args[0].Int()) if threshold < jww.LevelTrace || threshold > jww.LevelFatal { err := errors.Errorf("log level is not valid: log level: %d", threshold) @@ -85,14 +86,14 @@ func LogLevel(_ js.Value, args []js.Value) interface{} { // LogToFile enables logging to a file that can be downloaded. // // Parameters: -// - args[0] - Log level (int). -// - args[1] - Log file name (string). -// - args[2] - Max log file size, in bytes (int). +// - args[0] - Log level (int). +// - args[1] - Log file name (string). +// - args[2] - Max log file size, in bytes (int). // // Returns: -// - A Javascript representation of the [LogFile] object, which allows -// accessing the contents of the log file and other metadata. -func LogToFile(_ js.Value, args []js.Value) interface{} { +// - A Javascript representation of the [LogFile] object, which allows +// accessing the contents of the log file and other metadata. +func LogToFile(_ js.Value, args []js.Value) any { threshold := jww.Threshold(args[0].Int()) if threshold < jww.LevelTrace || threshold > jww.LevelFatal { err := errors.Errorf("log level is not valid: log level: %d", threshold) @@ -135,21 +136,21 @@ func LogToFile(_ js.Value, args []js.Value) interface{} { // logWriter wraps Javascript callbacks to adhere to the [bindings.LogWriter] // interface. type logWriter struct { - log func(args ...interface{}) js.Value + log func(args ...any) js.Value } // Log returns a log message to pass to the log writer. // // Parameters: -// - s - Log message (string). +// - s - Log message (string). func (lw *logWriter) Log(s string) { lw.log(s) } // RegisterLogWriter registers a callback on which logs are written. // // Parameters: -// - args[0] - a function that accepts a string and writes to a log. It must be -// of the form func(string). -func RegisterLogWriter(_ js.Value, args []js.Value) interface{} { +// - args[0] - a function that accepts a string and writes to a log. It must +// be of the form func(string). +func RegisterLogWriter(_ js.Value, args []js.Value) any { bindings.RegisterLogWriter(&logWriter{args[0].Invoke}) return nil } @@ -157,9 +158,9 @@ func RegisterLogWriter(_ js.Value, args []js.Value) interface{} { // EnableGrpcLogs sets GRPC trace logging. // // Parameters: -// - args[0] - a function that accepts a string and writes to a log. It must be -// of the form func(string). -func EnableGrpcLogs(_ js.Value, args []js.Value) interface{} { +// - args[0] - a function that accepts a string and writes to a log. It must +// be of the form func(string). +func EnableGrpcLogs(_ js.Value, args []js.Value) any { bindings.EnableGrpcLogs(&logWriter{args[0].Invoke}) return nil } @@ -271,10 +272,10 @@ func NewLogFile( }, nil } -// newLogFileJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [LogFile] structure. -func newLogFileJS(lf *LogFile) map[string]interface{} { - logFile := map[string]interface{}{ +// newLogFileJS creates a new Javascript compatible object (map[string]any) that +// matches the [LogFile] structure. +func newLogFileJS(lf *LogFile) map[string]any { + logFile := map[string]any{ "Name": js.FuncOf(lf.Name), "Threshold": js.FuncOf(lf.Threshold), "GetFile": js.FuncOf(lf.GetFile), @@ -298,39 +299,39 @@ func (lf *LogFile) Listen(t jww.Threshold) io.Writer { // Name returns the name of the log file. // // Returns: -// - File name (string). -func (lf *LogFile) Name(js.Value, []js.Value) interface{} { +// - File name (string). +func (lf *LogFile) Name(js.Value, []js.Value) any { return lf.name } // Threshold returns the log level threshold used in the file. // // Returns: -// - Log level (string). -func (lf *LogFile) Threshold(js.Value, []js.Value) interface{} { +// - Log level (string). +func (lf *LogFile) Threshold(js.Value, []js.Value) any { return lf.threshold.String() } // GetFile returns the entire log file. // // Returns: -// - Log file contents (string). -func (lf *LogFile) GetFile(js.Value, []js.Value) interface{} { +// - Log file contents (string). +func (lf *LogFile) GetFile(js.Value, []js.Value) any { return string(lf.b.Bytes()) } // MaxSize returns the max size, in bytes, that the log file is allowed to be. // // Returns: -// - Max file size (int). -func (lf *LogFile) MaxSize(js.Value, []js.Value) interface{} { +// - Max file size (int). +func (lf *LogFile) MaxSize(js.Value, []js.Value) any { return lf.b.Size() } // Size returns the current size, in bytes, written to the log file. // // Returns: -// - Current file size (int). -func (lf *LogFile) Size(js.Value, []js.Value) interface{} { +// - Current file size (int). +func (lf *LogFile) Size(js.Value, []js.Value) any { return lf.b.TotalWritten() } diff --git a/wasm/ndf.go b/wasm/ndf.go index cf79558d5904f18d2f1e01727b6341e058b75e4a..69441fea2c03e5f369a0e9a76a5936b7e43bf67f 100644 --- a/wasm/ndf.go +++ b/wasm/ndf.go @@ -21,17 +21,17 @@ import ( // that may be used to start a client. // // Parameters: -// - args[0] - The URL to download from (string). -// - args[1] - The NDF certificate (string). +// - args[0] - The URL to download from (string). +// - args[1] - The NDF certificate (string). // // Returns a promise: -// - 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{} { +// - Resolves to the JSON of the NDF ([ndf.NetworkDefinition]) (Uint8Array). +// - Rejected with an error if downloading fails. +func DownloadAndVerifySignedNdfWithUrl(_ js.Value, args []js.Value) any { url := args[0].String() cert := args[1].String() - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { ndf, err := bindings.DownloadAndVerifySignedNdfWithUrl(url, cert) if err != nil { reject(utils.JsTrace(err)) diff --git a/wasm/params.go b/wasm/params.go index 0399e7780e6368e1f111d3ae571e439ee6cadb53..01f307c6c029f1643e674fe7b77db44d4830b2fe 100644 --- a/wasm/params.go +++ b/wasm/params.go @@ -20,8 +20,8 @@ import ( // to change cMix settings. // // Returns: -// - JSON of [xxdk.CMIXParams] (Uint8Array). -func GetDefaultCMixParams(js.Value, []js.Value) interface{} { +// - JSON of [xxdk.CMIXParams] (Uint8Array). +func GetDefaultCMixParams(js.Value, []js.Value) any { return utils.CopyBytesToJS(bindings.GetDefaultCMixParams()) } @@ -30,8 +30,8 @@ func GetDefaultCMixParams(js.Value, []js.Value) interface{} { // to change E2E settings. // // Returns: -// - JSON of [xxdk.E2EParams] (Uint8Array). -func GetDefaultE2EParams(js.Value, []js.Value) interface{} { +// - JSON of [xxdk.E2EParams] (Uint8Array). +func GetDefaultE2EParams(js.Value, []js.Value) any { return utils.CopyBytesToJS(bindings.GetDefaultE2EParams()) } @@ -40,8 +40,8 @@ func GetDefaultE2EParams(js.Value, []js.Value) interface{} { // modify the JSON to change file transfer settings. // // Returns: -// - JSON of [fileTransfer.Params] (Uint8Array). -func GetDefaultFileTransferParams(js.Value, []js.Value) interface{} { +// - JSON of [fileTransfer.Params] (Uint8Array). +func GetDefaultFileTransferParams(js.Value, []js.Value) any { return utils.CopyBytesToJS(bindings.GetDefaultFileTransferParams()) } @@ -50,8 +50,8 @@ func GetDefaultFileTransferParams(js.Value, []js.Value) interface{} { // the JSON to change single use settings. // // Returns: -// - JSON of [single.RequestParams] (Uint8Array). -func GetDefaultSingleUseParams(js.Value, []js.Value) interface{} { +// - JSON of [single.RequestParams] (Uint8Array). +func GetDefaultSingleUseParams(js.Value, []js.Value) any { return utils.CopyBytesToJS(bindings.GetDefaultSingleUseParams()) } @@ -60,7 +60,8 @@ func GetDefaultSingleUseParams(js.Value, []js.Value) interface{} { // modify the JSON to change single use settings. // // Returns: -// - JSON of [gitlab.com/elixxir/client/v4/fileTransfer/e2e.Params] (Uint8Array). -func GetDefaultE2eFileTransferParams(js.Value, []js.Value) interface{} { +// - JSON of [gitlab.com/elixxir/client/v4/fileTransfer/e2e.Params] +// (Uint8Array). +func GetDefaultE2eFileTransferParams(js.Value, []js.Value) any { return utils.CopyBytesToJS(bindings.GetDefaultE2eFileTransferParams()) } diff --git a/wasm/restlike.go b/wasm/restlike.go index dffdad2c7867ce9805a4f9b35cad3978f806ce42..0cf802a32bb0c638859c77d1a32fc609cd2994b8 100644 --- a/wasm/restlike.go +++ b/wasm/restlike.go @@ -18,24 +18,24 @@ import ( // RestlikeRequest performs a normal restlike request. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - ID of [Connection] object in tracker (int). -// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). -// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - ID of [Connection] object in tracker (int). +// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). +// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.RestlikeMessage], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - Rejected with an error if parsing the parameters or making the request -// fails. -func RestlikeRequest(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.RestlikeMessage], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - Rejected with an error if parsing the parameters or making the request +// fails. +func RestlikeRequest(_ js.Value, args []js.Value) any { cmixId := args[0].Int() connectionID := args[1].Int() request := utils.CopyBytesToGo(args[2]) e2eParamsJSON := utils.CopyBytesToGo(args[3]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { msg, err := bindings.RestlikeRequest( cmixId, connectionID, request, e2eParamsJSON) if err != nil { @@ -51,24 +51,24 @@ func RestlikeRequest(_ js.Value, args []js.Value) interface{} { // RestlikeRequestAuth performs an authenticated restlike request. // // Parameters: -// - args[0] - ID of [Cmix] object in tracker (int). -// - args[1] - ID of [AuthenticatedConnection] object in tracker (int). -// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). -// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). +// - args[0] - ID of [Cmix] object in tracker (int). +// - args[1] - ID of [AuthenticatedConnection] object in tracker (int). +// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). +// - args[3] - JSON of [xxdk.E2EParams] (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.RestlikeMessage], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - Rejected with an error if parsing the parameters or making the request -// fails. -func RestlikeRequestAuth(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.RestlikeMessage], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - Rejected with an error if parsing the parameters or making the request +// fails. +func RestlikeRequestAuth(_ js.Value, args []js.Value) any { cmixId := args[0].Int() authConnectionID := args[1].Int() request := utils.CopyBytesToGo(args[2]) e2eParamsJSON := utils.CopyBytesToGo(args[3]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { msg, err := bindings.RestlikeRequestAuth( cmixId, authConnectionID, request, e2eParamsJSON) if err != nil { diff --git a/wasm/restlikeSingle.go b/wasm/restlikeSingle.go index 9e0d01e0da63e3ee2279466079c1e836e2750b5a..391e40c01a2711aa630468ae59d06e15b5312bab 100644 --- a/wasm/restlikeSingle.go +++ b/wasm/restlikeSingle.go @@ -18,14 +18,14 @@ import ( // RestlikeCallback wraps Javascript callbacks to adhere to the // [bindings.RestlikeCallback] interface. type restlikeCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback returns the response from an asynchronous restlike request. // // Parameters: -// - payload - JSON of [restlike.Message] (Uint8Array). -// - err - Returns an error on failure (Error). +// - payload - JSON of [restlike.Message] (Uint8Array). +// - err - Returns an error on failure (Error). func (rlc *restlikeCallback) Callback(payload []byte, err error) { rlc.callback(utils.CopyBytesToJS(payload), utils.JsTrace(err)) } @@ -33,24 +33,24 @@ func (rlc *restlikeCallback) Callback(payload []byte, err error) { // RequestRestLike sends a restlike request to a given contact. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the recipient [contact.Contact] -// (Uint8Array). -// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). -// - args[3] - JSON of [single.RequestParams] (Uint8Array). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the recipient [contact.Contact] +// (Uint8Array). +// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). +// - args[3] - JSON of [single.RequestParams] (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.Message], which can be passed into -// [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). -// - Rejected with an error if parsing the parameters or making the request -// fails. -func RequestRestLike(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.Message], which can be passed into +// [Cmix.WaitForRoundResult] to see if the send succeeded (Uint8Array). +// - Rejected with an error if parsing the parameters or making the request +// fails. +func RequestRestLike(_ js.Value, args []js.Value) any { e2eID := args[0].Int() recipient := utils.CopyBytesToGo(args[1]) request := utils.CopyBytesToGo(args[2]) paramsJSON := utils.CopyBytesToGo(args[3]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { msg, err := bindings.RequestRestLike( e2eID, recipient, request, paramsJSON) if err != nil { @@ -70,17 +70,17 @@ func RequestRestLike(_ js.Value, args []js.Value) interface{} { // response when received. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the recipient [contact.Contact] -// (Uint8Array). -// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). -// - args[3] - JSON of [single.RequestParams] (Uint8Array). -// - args[4] - Javascript object that has functions that implement the -// [bindings.RestlikeCallback] interface. +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the recipient [contact.Contact] +// (Uint8Array). +// - args[2] - JSON of [bindings.RestlikeMessage] (Uint8Array). +// - args[3] - JSON of [single.RequestParams] (Uint8Array). +// - args[4] - Javascript object that has functions that implement the +// [bindings.RestlikeCallback] interface. // // Returns: -// - Throws a TypeError if parsing the parameters or making the request fails. -func AsyncRequestRestLike(_ js.Value, args []js.Value) interface{} { +// - Throws a TypeError if parsing the parameters or making the request fails. +func AsyncRequestRestLike(_ js.Value, args []js.Value) any { e2eID := args[0].Int() recipient := utils.CopyBytesToGo(args[1]) request := utils.CopyBytesToGo(args[2]) diff --git a/wasm/secrets.go b/wasm/secrets.go index b094f1760a358ce544967c55d075303eed0268ee..d310fcbcd4cd7e2593ec6d360274ed5cf9eea48c 100644 --- a/wasm/secrets.go +++ b/wasm/secrets.go @@ -19,12 +19,12 @@ import ( // number generator. // // Parameters: -// - args[0] - The size of secret. It should be set to 32, but can be set -// higher in certain cases, but not lower (int). +// - args[0] - The size of secret. It should be set to 32, but can be set +// higher in certain cases, but not lower (int). // // Returns: -// - Secret password (Uint8Array). -func GenerateSecret(_ js.Value, args []js.Value) interface{} { +// - Secret password (Uint8Array). +func GenerateSecret(_ js.Value, args []js.Value) any { secret := bindings.GenerateSecret(args[0].Int()) return utils.CopyBytesToJS(secret) } diff --git a/wasm/single.go b/wasm/single.go index bc2b32dd8651bec48f56bf9cff1d31ad3e057c29..8198bb80fc58de0b21a045c47b39194efd149cfa 100644 --- a/wasm/single.go +++ b/wasm/single.go @@ -22,22 +22,22 @@ import ( // TransmitSingleUse transmits payload to recipient via single-use. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the recipient [contact.Contact] -// (Uint8Array). -// - args[2] - Tag that identifies the single-use message (string). -// - args[3] - Message contents (Uint8Array). -// - args[4] - JSON of [single.RequestParams] (Uint8Array). -// - args[5] - The callback that will be called when a response is received. It -// is a Javascript object that has functions that implement the -// [bindings.SingleUseResponse] interface. +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the recipient [contact.Contact] +// (Uint8Array). +// - args[2] - Tag that identifies the single-use message (string). +// - args[3] - Message contents (Uint8Array). +// - args[4] - JSON of [single.RequestParams] (Uint8Array). +// - args[5] - The callback that will be called when a response is received. +// It is a Javascript object that has functions that implement the +// [bindings.SingleUseResponse] interface. // // Returns a promise: -// - Resolves to the JSON of the [bindings.SingleUseSendReport], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - Rejected with an error if transmission fails. -func TransmitSingleUse(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.SingleUseSendReport], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - Rejected with an error if transmission fails. +func TransmitSingleUse(_ js.Value, args []js.Value) any { e2eID := args[0].Int() recipient := utils.CopyBytesToGo(args[1]) tag := args[2].String() @@ -45,7 +45,7 @@ func TransmitSingleUse(_ js.Value, args []js.Value) interface{} { paramsJSON := utils.CopyBytesToGo(args[4]) responseCB := &singleUseResponse{utils.WrapCB(args[5], "Callback")} - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := bindings.TransmitSingleUse( e2eID, recipient, tag, payload, paramsJSON, responseCB) if err != nil { @@ -62,17 +62,17 @@ func TransmitSingleUse(_ js.Value, args []js.Value) interface{} { // object and SingleUseCallback func. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Tag that identifies the single-use message (string). -// - args[2] - The callback that will be called when a response is received. It -// is a Javascript object that has functions that implement the -// [bindings.SingleUseCallback] interface. +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Tag that identifies the single-use message (string). +// - args[2] - The callback that will be called when a response is received. +// It is a Javascript object that has functions that implement the +// [bindings.SingleUseCallback] interface. // // Returns: -// - Javascript representation of the [Stopper] object, an interface containing -// a function used to stop the listener. -// - Throws a TypeError if listening fails. -func Listen(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [Stopper] object, an interface +// containing a function used to stop the listener. +// - Throws a TypeError if listening fails. +func Listen(_ js.Value, args []js.Value) any { cb := &singleUseCallback{utils.WrapCB(args[2], "Callback")} api, err := bindings.Listen(args[0].Int(), args[1].String(), cb) if err != nil { @@ -93,11 +93,11 @@ type Stopper struct { api bindings.Stopper } -// newStopperJS creates a new Javascript compatible object -// (map[string]interface{}) that matches the [Stopper] structure. -func newStopperJS(api bindings.Stopper) map[string]interface{} { +// newStopperJS creates a new Javascript compatible object (map[string]any) that +// matches the [Stopper] structure. +func newStopperJS(api bindings.Stopper) map[string]any { s := Stopper{api} - stopperMap := map[string]interface{}{ + stopperMap := map[string]any{ "Stop": js.FuncOf(s.Stop), } @@ -105,7 +105,7 @@ func newStopperJS(api bindings.Stopper) map[string]interface{} { } // Stop stops the registered listener. -func (s *Stopper) Stop(js.Value, []js.Value) interface{} { +func (s *Stopper) Stop(js.Value, []js.Value) any { s.api.Stop() return nil } @@ -117,16 +117,16 @@ func (s *Stopper) Stop(js.Value, []js.Value) interface{} { // singleUseCallback wraps Javascript callbacks to adhere to the // [bindings.SingleUseCallback] interface. type singleUseCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called when single-use messages are received. // // Parameters: -// - callbackReport - JSON of [bindings.SingleUseCallbackReport], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - err - Returns an error on failure (Error). +// - callbackReport - JSON of [bindings.SingleUseCallbackReport], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - err - Returns an error on failure (Error). func (suc *singleUseCallback) Callback(callbackReport []byte, err error) { suc.callback(utils.CopyBytesToJS(callbackReport), utils.JsTrace(err)) } @@ -134,16 +134,16 @@ func (suc *singleUseCallback) Callback(callbackReport []byte, err error) { // singleUseResponse wraps Javascript callbacks to adhere to the // [bindings.SingleUseResponse] interface. type singleUseResponse struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback returns the response to a single-use message. // // Parameters: -// - callbackReport - JSON of [bindings.SingleUseCallbackReport], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - err - Returns an error on failure (Error). +// - callbackReport - JSON of [bindings.SingleUseCallbackReport], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - err - Returns an error on failure (Error). func (sur *singleUseResponse) Callback(responseReport []byte, err error) { sur.callback(utils.CopyBytesToJS(responseReport), utils.JsTrace(err)) } diff --git a/wasm/timeNow.go b/wasm/timeNow.go index 0930367d91bba0623d56aaccc55a5f845eda5ca2..627a16b4e344089d782edf435fdcd3225c6c230b 100644 --- a/wasm/timeNow.go +++ b/wasm/timeNow.go @@ -18,7 +18,7 @@ import ( // timeSource wraps Javascript callbacks to adhere to the [netTime.TimeSource] // interface. type timeSource struct { - nowMs func(args ...interface{}) js.Value + nowMs func(args ...any) js.Value } // NowMs returns the current time in milliseconds. @@ -32,9 +32,9 @@ func (ts *timeSource) NowMs() int64 { // may result in a crash. // // Parameters: -// - timeNow is an object which adheres to [netTime.TimeSource]. Specifically, -// this object should a NowMs() method which return a 64-bit integer value. -func SetTimeSource(_ js.Value, args []js.Value) interface{} { +// - timeNow is an object which adheres to [netTime.TimeSource]. Specifically, +// this object should a NowMs() method which return a 64-bit integer value. +func SetTimeSource(_ js.Value, args []js.Value) any { bindings.SetTimeSource(&timeSource{utils.WrapCB(args[0], "NowMs")}) return nil } @@ -43,10 +43,10 @@ func SetTimeSource(_ js.Value, args []js.Value) interface{} { // will have this offset applied to this value. // // Parameters: -// - args[0] - a time by which netTime.Now will be offset. This value may be -// negative or positive. This expects a 64-bit integer value which will -// represent the number in microseconds this offset will be (int). -func SetOffset(_ js.Value, args []js.Value) interface{} { +// - args[0] - a time by which netTime.Now will be offset. This value may be +// negative or positive. This expects a 64-bit integer value which will +// represent the number in microseconds this offset will be (int). +func SetOffset(_ js.Value, args []js.Value) any { bindings.SetOffset(int64(args[0].Int())) return nil } diff --git a/wasm/ud.go b/wasm/ud.go index e18453c7c06016c2c00c14ab0690479f1c6ecb9f..74bc2b11b628a4139040168194af9b6d21009a72 100644 --- a/wasm/ud.go +++ b/wasm/ud.go @@ -25,11 +25,11 @@ type UserDiscovery struct { api *bindings.UserDiscovery } -// newE2eJS creates a new Javascript compatible object (map[string]interface{}) -// that matches the [E2e] structure. -func newUserDiscoveryJS(api *bindings.UserDiscovery) map[string]interface{} { +// newE2eJS creates a new Javascript compatible object (map[string]any) that +// matches the [E2e] structure. +func newUserDiscoveryJS(api *bindings.UserDiscovery) map[string]any { ud := UserDiscovery{api} - udMap := map[string]interface{}{ + udMap := map[string]any{ "GetID": js.FuncOf(ud.GetID), "GetFacts": js.FuncOf(ud.GetFacts), "GetContact": js.FuncOf(ud.GetContact), @@ -45,21 +45,21 @@ func newUserDiscoveryJS(api *bindings.UserDiscovery) map[string]interface{} { // GetID returns the ID for this [UserDiscovery] in the [UserDiscovery] tracker. // // Returns: -// - Tracker ID (int). -func (ud *UserDiscovery) GetID(js.Value, []js.Value) interface{} { +// - Tracker ID (int). +func (ud *UserDiscovery) GetID(js.Value, []js.Value) any { return ud.api.GetID() } // udNetworkStatus wraps Javascript callbacks to adhere to the // [bindings.UdNetworkStatus] interface. type udNetworkStatus struct { - udNetworkStatus func(args ...interface{}) js.Value + udNetworkStatus func(args ...any) js.Value } // UdNetworkStatus returns the status of UD. // // Returns: -// - UD status (int). +// - UD status (int). func (uns *udNetworkStatus) UdNetworkStatus() int { return uns.udNetworkStatus().Int() } @@ -76,31 +76,31 @@ func (uns *udNetworkStatus) UdNetworkStatus() int { // be pulled from the NDF using the bindings. // // Params -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.UdNetworkStatus] interface. This is the network follower -// function wrapped in [bindings.UdNetworkStatus]. -// - args[2] - The username the user wants to register with UD. If the user is -// already registered, this field may be blank (string). -// - args[3] - The registration validation signature; a signature provided by -// the network (i.e., the client registrar). This may be nil; however, UD may -// return an error in some cases (e.g., in a production level environment) -// (Uint8Array). -// - args[4] - The TLS certificate for the UD server this call will connect -// with. You may use the UD server run by the xx network team by using -// [E2e.GetUdCertFromNdf] (Uint8Array). -// - args[5] - Marshalled bytes of the [contact.Contact] of the server this -// call will connect with. You may use the UD server run by the xx network -// team by using [E2e.GetUdContactFromNdf] (Uint8Array). -// - args[6] - the IP address of the UD server this call will connect with. You -// may use the UD server run by the xx network team by using -// [E2e.GetUdAddressFromNdf] (string). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.UdNetworkStatus] interface. This is the network follower +// function wrapped in [bindings.UdNetworkStatus]. +// - args[2] - The username the user wants to register with UD. If the user is +// already registered, this field may be blank (string). +// - args[3] - The registration validation signature; a signature provided by +// the network (i.e., the client registrar). This may be nil; however, UD +// may return an error in some cases (e.g., in a production level +// environment) (Uint8Array). +// - args[4] - The TLS certificate for the UD server this call will connect +// with. You may use the UD server run by the xx network team by using +// [E2e.GetUdCertFromNdf] (Uint8Array). +// - args[5] - Marshalled bytes of the [contact.Contact] of the server this +// call will connect with. You may use the UD server run by the xx network +// team by using [E2e.GetUdContactFromNdf] (Uint8Array). +// - args[6] - the IP address of the UD server this call will connect with. +// You may use the UD server run by the xx network team by using +// [E2e.GetUdAddressFromNdf] (string). // // Returns: -// - Javascript representation of the [UserDiscovery] object that is registered -// to the specified UD service. -// - Throws a TypeError if creating or loading fails. -func NewOrLoadUd(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [UserDiscovery] object that is +// registered to the specified UD service. +// - Throws a TypeError if creating or loading fails. +func NewOrLoadUd(_ js.Value, args []js.Value) any { e2eID := args[0].Int() follower := &udNetworkStatus{utils.WrapCB(args[1], "UdNetworkStatus")} username := args[2].String() @@ -128,25 +128,25 @@ func NewOrLoadUd(_ js.Value, args []js.Value) interface{} { // an error. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Javascript object that has functions that implement the -// [bindings.UdNetworkStatus] interface. This is the network follower -// function wrapped in [bindings.UdNetworkStatus]. -// - args[2] - The TLS certificate for the UD server this call will connect -// with. You may use the UD server run by the xx network team by using -// [E2e.GetUdCertFromNdf] (Uint8Array). -// - args[3] - Marshalled bytes of the [contact.Contact] of the server this -// call will connect with. You may use the UD server run by the xx network -// team by using [E2e.GetUdContactFromNdf] (Uint8Array). -// - args[4] - The IP address of the UD server this call will connect with. You -// may use the UD server run by the xx network team by using -// [E2e.GetUdAddressFromNdf] (string). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.UdNetworkStatus] interface. This is the network follower +// function wrapped in [bindings.UdNetworkStatus]. +// - args[2] - The TLS certificate for the UD server this call will connect +// with. You may use the UD server run by the xx network team by using +// [E2e.GetUdCertFromNdf] (Uint8Array). +// - args[3] - Marshalled bytes of the [contact.Contact] of the server this +// call will connect with. You may use the UD server run by the xx network +// team by using [E2e.GetUdContactFromNdf] (Uint8Array). +// - args[4] - The IP address of the UD server this call will connect with. +// You may use the UD server run by the xx network team by using +// [E2e.GetUdAddressFromNdf] (string). // // Returns: -// - Javascript representation of the [UserDiscovery] object that is loaded -// from backup. -// - Throws a TypeError if getting UD from backup fails. -func NewUdManagerFromBackup(_ js.Value, args []js.Value) interface{} { +// - Javascript representation of the [UserDiscovery] object that is loaded +// from backup. +// - Throws a TypeError if getting UD from backup fails. +func NewUdManagerFromBackup(_ js.Value, args []js.Value) any { e2eID := args[0].Int() follower := &udNetworkStatus{utils.WrapCB(args[1], "UdNetworkStatus")} cert := utils.CopyBytesToGo(args[5]) @@ -168,8 +168,8 @@ func NewUdManagerFromBackup(_ js.Value, args []js.Value) interface{} { // within the Store's registeredFacts map. // // Returns: -// - JSON of [fact.FactList] (Uint8Array). -func (ud *UserDiscovery) GetFacts(js.Value, []js.Value) interface{} { +// - JSON of [fact.FactList] (Uint8Array). +func (ud *UserDiscovery) GetFacts(js.Value, []js.Value) any { return utils.CopyBytesToJS(ud.api.GetFacts()) } @@ -177,9 +177,9 @@ func (ud *UserDiscovery) GetFacts(js.Value, []js.Value) interface{} { // retrieved from the NDF. // // Returns: -// - Marshalled bytes of [contact.Contact] (Uint8Array). -// - Throws TypeError if getting the contact fails. -func (ud *UserDiscovery) GetContact(js.Value, []js.Value) interface{} { +// - Marshalled bytes of [contact.Contact] (Uint8Array). +// - Throws TypeError if getting the contact fails. +func (ud *UserDiscovery) GetContact(js.Value, []js.Value) any { c, err := ud.api.GetContact() if err != nil { utils.Throw(utils.TypeError, err) @@ -195,12 +195,12 @@ func (ud *UserDiscovery) GetContact(js.Value, []js.Value) interface{} { // communications system. // // Parameters: -// - args[0] - Confirmation ID (string). -// - args[1] - Code (string). +// - args[0] - Confirmation ID (string). +// - args[1] - Code (string). // // Returns: -// - Throws TypeError if confirming the fact fails. -func (ud *UserDiscovery) ConfirmFact(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if confirming the fact fails. +func (ud *UserDiscovery) ConfirmFact(_ js.Value, args []js.Value) any { err := ud.api.ConfirmFact(args[0].String(), args[1].String()) if err != nil { utils.Throw(utils.TypeError, err) @@ -220,12 +220,12 @@ func (ud *UserDiscovery) ConfirmFact(_ js.Value, args []js.Value) interface{} { // along with the code to finalize the fact. // // Parameters: -// - args[0] - JSON of [fact.Fact] (Uint8Array). +// - args[0] - JSON of [fact.Fact] (Uint8Array). // // Returns: -// - The confirmation ID (string). -// - Throws TypeError if sending the fact fails. -func (ud *UserDiscovery) SendRegisterFact(_ js.Value, args []js.Value) interface{} { +// - The confirmation ID (string). +// - Throws TypeError if sending the fact fails. +func (ud *UserDiscovery) SendRegisterFact(_ js.Value, args []js.Value) any { confirmationID, err := ud.api.SendRegisterFact(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -240,11 +240,11 @@ func (ud *UserDiscovery) SendRegisterFact(_ js.Value, args []js.Value) interface // be associated with this user. // // Parameters: -// - args[0] - JSON of [fact.Fact] (Uint8Array). +// - args[0] - JSON of [fact.Fact] (Uint8Array). // // Returns: -// - Throws TypeError if deletion fails. -func (ud *UserDiscovery) PermanentDeleteAccount(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if deletion fails. +func (ud *UserDiscovery) PermanentDeleteAccount(_ js.Value, args []js.Value) any { err := ud.api.PermanentDeleteAccount(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -258,11 +258,11 @@ func (ud *UserDiscovery) PermanentDeleteAccount(_ js.Value, args []js.Value) int // passed in is not UD service does not associate this fact with this user. // // Parameters: -// - args[0] - JSON of [fact.Fact] (Uint8Array). +// - args[0] - JSON of [fact.Fact] (Uint8Array). // // Returns: -// - Throws TypeError if removing the fact fails. -func (ud *UserDiscovery) RemoveFact(_ js.Value, args []js.Value) interface{} { +// - Throws TypeError if removing the fact fails. +func (ud *UserDiscovery) RemoveFact(_ js.Value, args []js.Value) any { err := ud.api.RemoveFact(utils.CopyBytesToGo(args[0])) if err != nil { utils.Throw(utils.TypeError, err) @@ -279,16 +279,16 @@ func (ud *UserDiscovery) RemoveFact(_ js.Value, args []js.Value) interface{} { // udLookupCallback wraps Javascript callbacks to adhere to the // [bindings.UdLookupCallback] interface. type udLookupCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called by [LookupUD] to return the contact that matches the // passed in ID. // // Parameters: -// - contactBytes - Marshalled bytes of the [contact.Contact] returned from the -// lookup, or nil if an error occurs (Uint8Array). -// - err - Returns an error on failure (Error). +// - contactBytes - Marshalled bytes of the [contact.Contact] returned from +// the lookup, or nil if an error occurs (Uint8Array). +// - err - Returns an error on failure (Error). func (ulc *udLookupCallback) Callback(contactBytes []byte, err error) { ulc.callback(utils.CopyBytesToJS(contactBytes), utils.JsTrace(err)) } @@ -297,28 +297,28 @@ func (ulc *udLookupCallback) Callback(contactBytes []byte, err error) { // discovery system or returns by the timeout. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the User Discovery's [contact.Contact] -// (Uint8Array). -// - args[2] - Javascript object that has functions that implement the -// [bindings.UdLookupCallback] interface. -// - args[3] - Marshalled bytes of the [id.ID] for the user to look up -// (Uint8Array). -// - args[4] - JSON of [single.RequestParams] (Uint8Array). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the User Discovery's [contact.Contact] +// (Uint8Array). +// - args[2] - Javascript object that has functions that implement the +// [bindings.UdLookupCallback] interface. +// - args[3] - Marshalled bytes of the [id.ID] for the user to look up +// (Uint8Array). +// - args[4] - JSON of [single.RequestParams] (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.SingleUseSendReport], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - Rejected with an error if the lookup fails. -func LookupUD(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.SingleUseSendReport], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - Rejected with an error if the lookup fails. +func LookupUD(_ js.Value, args []js.Value) any { e2eID := args[0].Int() udContact := utils.CopyBytesToGo(args[1]) cb := &udLookupCallback{utils.WrapCB(args[2], "Callback")} lookupId := utils.CopyBytesToGo(args[3]) singleRequestParamsJSON := utils.CopyBytesToGo(args[4]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := bindings.LookupUD( e2eID, udContact, cb, lookupId, singleRequestParamsJSON) if err != nil { @@ -338,23 +338,24 @@ func LookupUD(_ js.Value, args []js.Value) interface{} { // udSearchCallback wraps Javascript callbacks to adhere to the // [bindings.UdSearchCallback] interface. type udSearchCallback struct { - callback func(args ...interface{}) js.Value + callback func(args ...any) js.Value } // Callback is called by [SearchUD] to return a list of [contact.Contact] // objects that match the list of facts passed into [SearchUD]. // // Parameters: -// - contactListJSON - JSON of an array of [contact.Contact], or nil if an -// error occurs (Uint8Array). -// - err - Returns any error that occurred in the search (Error). +// - contactListJSON - JSON of an array of [contact.Contact], or nil if an +// error occurs (Uint8Array). +// - err - Returns any error that occurred in the search (Error). // // JSON Example: -// { -// "<xxc(2)F8dL9EC6gy+RMJuk3R+Au6eGExo02Wfio5cacjBcJRwDEgB7Ugdw/BAr6RkCABkWAFV1c2VybmFtZTA7c4LzV05sG+DMt+rFB0NIJg==xxc>", -// "<xxc(2)eMhAi/pYkW5jCmvKE5ZaTglQb+fTo1D8NxVitr5CCFADEgB7Ugdw/BAr6RoCABkWAFV1c2VybmFtZTE7fElAa7z3IcrYrrkwNjMS2w==xxc>", -// "<xxc(2)d7RJTu61Vy1lDThDMn8rYIiKSe1uXA/RCvvcIhq5Yg4DEgB7Ugdw/BAr6RsCABkWAFV1c2VybmFtZTI7N3XWrxIUpR29atpFMkcR6A==xxc>" -// } +// +// { +// "<xxc(2)F8dL9EC6gy+RMJuk3R+Au6eGExo02Wfio5cacjBcJRwDEgB7Ugdw/BAr6RkCABkWAFV1c2VybmFtZTA7c4LzV05sG+DMt+rFB0NIJg==xxc>", +// "<xxc(2)eMhAi/pYkW5jCmvKE5ZaTglQb+fTo1D8NxVitr5CCFADEgB7Ugdw/BAr6RoCABkWAFV1c2VybmFtZTE7fElAa7z3IcrYrrkwNjMS2w==xxc>", +// "<xxc(2)d7RJTu61Vy1lDThDMn8rYIiKSe1uXA/RCvvcIhq5Yg4DEgB7Ugdw/BAr6RsCABkWAFV1c2VybmFtZTI7N3XWrxIUpR29atpFMkcR6A==xxc>" +// } func (usc *udSearchCallback) Callback(contactListJSON []byte, err error) { usc.callback(utils.CopyBytesToJS(contactListJSON), utils.JsTrace(err)) } @@ -366,25 +367,25 @@ func (usc *udSearchCallback) Callback(contactListJSON []byte, err error) { // where multiple pieces of information is known. // // Parameters: -// - args[0] - ID of [E2e] object in tracker (int). -// - args[1] - Marshalled bytes of the User Discovery's [contact.Contact] -// (Uint8Array). -// - args[2] - JSON of [fact.FactList] (Uint8Array). -// - args[4] - JSON of [single.RequestParams] (Uint8Array). +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Marshalled bytes of the User Discovery's [contact.Contact] +// (Uint8Array). +// - args[2] - JSON of [fact.FactList] (Uint8Array). +// - args[4] - JSON of [single.RequestParams] (Uint8Array). // // Returns a promise: -// - Resolves to the JSON of the [bindings.SingleUseSendReport], which can be -// passed into [Cmix.WaitForRoundResult] to see if the send succeeded -// (Uint8Array). -// - Rejected with an error if the search fails. -func SearchUD(_ js.Value, args []js.Value) interface{} { +// - Resolves to the JSON of the [bindings.SingleUseSendReport], which can be +// passed into [Cmix.WaitForRoundResult] to see if the send succeeded +// (Uint8Array). +// - Rejected with an error if the search fails. +func SearchUD(_ js.Value, args []js.Value) any { e2eID := args[0].Int() udContact := utils.CopyBytesToGo(args[1]) cb := &udSearchCallback{utils.WrapCB(args[2], "Callback")} factListJSON := utils.CopyBytesToGo(args[3]) singleRequestParamsJSON := utils.CopyBytesToGo(args[4]) - promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { + promiseFn := func(resolve, reject func(args ...any) js.Value) { sendReport, err := bindings.SearchUD( e2eID, udContact, cb, factListJSON, singleRequestParamsJSON) if err != nil { diff --git a/wasm/version.go b/wasm/version.go index 6608470e5be05dc83d0dcefff79fd9eb2954aad2..528641b61a5161d308e04a7b6991bde21f801e7c 100644 --- a/wasm/version.go +++ b/wasm/version.go @@ -18,8 +18,8 @@ import ( // GetVersion returns the current xxDK WASM semantic version. // // Returns: -// - Current version (string). -func GetVersion(js.Value, []js.Value) interface{} { +// - Current version (string). +func GetVersion(js.Value, []js.Value) any { return storage.SEMVER } @@ -27,8 +27,8 @@ func GetVersion(js.Value, []js.Value) interface{} { // ([xxdk.SEMVER]). // // Returns: -// - Current version (string). -func GetClientVersion(js.Value, []js.Value) interface{} { +// - Current version (string). +func GetClientVersion(js.Value, []js.Value) any { return bindings.GetVersion() } @@ -36,8 +36,8 @@ func GetClientVersion(js.Value, []js.Value) interface{} { // ([xxdk.GITVERSION]). // // Returns: -// - Git version (string). -func GetClientGitVersion(js.Value, []js.Value) interface{} { +// - Git version (string). +func GetClientGitVersion(js.Value, []js.Value) any { return bindings.GetGitVersion() } @@ -45,7 +45,7 @@ func GetClientGitVersion(js.Value, []js.Value) interface{} { // ([xxdk.DEPENDENCIES]). // // Returns: -// - Dependency list (string). -func GetClientDependencies(js.Value, []js.Value) interface{} { +// - Dependency list (string). +func GetClientDependencies(js.Value, []js.Value) any { return bindings.GetDependencies() }