diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 385f857c9c947089bf9018aabca620a02a9727c1..cefd13b84113d1e2a1dc483104c11ea82a7e1819 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,7 +41,8 @@ wasm-test: - go mod vendor - unset SSH_PRIVATE_KEY - unset $(env | grep '=' | awk -F= '{print $1}' | grep -v PATH | grep -v GO | grep -v HOME) - - echo "WASM TESTS DISABLED FOR XX-4522, but will run them just so you can see output" + - rm vendor/gitlab.com/elixxir/wasm-utils/exception/throw_js.s + - mv vendor/gitlab.com/elixxir/wasm-utils/exception/throws.dev vendor/gitlab.com/elixxir/wasm-utils/exception/throws.go - GOOS=js GOARCH=wasm go test ./... -v build: diff --git a/indexedDb/impl/channels/callbacks.go b/indexedDb/impl/channels/callbacks.go index 6fc2235b5515e13e92d4bbf66135bc3647a2b740..e41bf1dd0f95fc7b7073e7b79b129f6c74b348ad 100644 --- a/indexedDb/impl/channels/callbacks.go +++ b/indexedDb/impl/channels/callbacks.go @@ -79,13 +79,12 @@ func (m *manager) newWASMEventModelCB(data []byte) ([]byte, error) { return []byte{}, nil } -// MessageReceived implements [bindings.ChannelUICallbacks.MessageReceived]. -func (m *manager) MessageReceived(uuid int64, channelID []byte, update bool) { +// EventUpdate implements [bindings.ChannelUICallbacks.EventUpdate]. +func (m *manager) EventUpdate(eventType int64, jsonData []byte) { // Package parameters for sending - msg := &wChannels.MessageReceivedCallbackMessage{ - UUID: uuid, - ChannelID: channelID, - Update: update, + msg := &wChannels.EventUpdateCallbackMessage{ + EventType: eventType, + JsonData: jsonData, } data, err := json.Marshal(msg) if err != nil { @@ -94,30 +93,7 @@ func (m *manager) MessageReceived(uuid int64, channelID []byte, update bool) { } // Send it to the main thread - m.wtm.SendMessage(wChannels.MessageReceivedCallbackTag, data) -} - -// MessageDeleted implements [bindings.ChannelUICallbacks.MessageDeleted]. -func (m *manager) MessageDeleted(messageID []byte) { - m.wtm.SendMessage(wChannels.DeletedMessageCallbackTag, messageID) -} - -// UserMuted implements [bindings.ChannelUICallbacks.UserMuted]. -func (m *manager) UserMuted(channelID, pubKey []byte, unmute bool) { - // Package parameters for sending - msg := &wChannels.MuteUserMessage{ - ChannelID: channelID, - PubKey: pubKey, - Unmute: unmute, - } - data, err := json.Marshal(msg) - if err != nil { - jww.ERROR.Printf("Could not JSON marshal %T: %+v", msg, err) - return - } - - // Send it to the main thread - m.wtm.SendMessage(wChannels.MutedUserCallbackTag, data) + m.wtm.SendMessage(wChannels.EventUpdateCallbackTag, data) } // NicknameUpdate implements [bindings.ChannelUICallbacks.NicknameUpdate] diff --git a/indexedDb/impl/channels/implementation_test.go b/indexedDb/impl/channels/implementation_test.go index d13f725d02d33ddbd12cedea8940211fe958890f..cdf17e6f2e63e9990af5acc02f6852ee0459528f 100644 --- a/indexedDb/impl/channels/implementation_test.go +++ b/indexedDb/impl/channels/implementation_test.go @@ -43,13 +43,7 @@ func TestMain(m *testing.M) { } type dummyCbs struct{} - -func (c *dummyCbs) MessageReceived(uuid int64, channelID []byte, update bool) {} -func (c *dummyCbs) UserMuted(channelID []byte, pubKey []byte, unmute bool) {} -func (c *dummyCbs) MessageDeleted(messageId []byte) {} -func (c *dummyCbs) NicknameUpdate(channelIdBytes []byte, nickname string, - exists bool) { -} +func (c *dummyCbs) EventUpdate(int64, []byte) {} // Happy path test for receiving, updating, getting, and deleting a File. func TestWasmModel_ReceiveFile(t *testing.T) { diff --git a/indexedDb/impl/channels/init.go b/indexedDb/impl/channels/init.go index 5454f35913d21572b984e36e3e6771d8a578f566..171175dd6bf4b2ab900068da18c4a10032c8b443 100644 --- a/indexedDb/impl/channels/init.go +++ b/indexedDb/impl/channels/init.go @@ -30,13 +30,13 @@ const currentVersion uint = 1 // The name should be a base64 encoding of the users public key. Returns the // EventModel based on IndexedDb and the database name as reported by IndexedDb. func NewWASMEventModel(databaseName string, encryption cryptoChannel.Cipher, - channelsCbs bindings.ChannelUICallbacks) (channels.EventModel, error) { - return newWASMModel(databaseName, encryption, channelsCbs) + uiCallbacks bindings.ChannelUICallbacks) (channels.EventModel, error) { + return newWASMModel(databaseName, encryption, uiCallbacks) } // newWASMModel creates the given [idb.Database] and returns a wasmModel. func newWASMModel(databaseName string, encryption cryptoChannel.Cipher, - channelsCbs bindings.ChannelUICallbacks) (*wasmModel, error) { + uiCallbacks bindings.ChannelUICallbacks) (*wasmModel, error) { // Attempt to open database object ctx, cancel := impl.NewContext() defer cancel() @@ -80,9 +80,9 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher, data, err := json.Marshal(jsonMarshallable) if err != nil { jww.FATAL.Panicf("Failed to JSON marshal %T for EventUpdate "+ - "callback: %+v", err) + "callback: %+v", jsonMarshallable, err) } - channelsCbs.EventUpdate(eventType, data) + uiCallbacks.EventUpdate(eventType, data) }, } return wrapper, nil diff --git a/indexedDb/worker/channels/init.go b/indexedDb/worker/channels/init.go index 34dd3f0d2548042a3778267e9b5e46172c384dd6..e8a8f9419ff25da299bcb3f868b01ab4b1e048d5 100644 --- a/indexedDb/worker/channels/init.go +++ b/indexedDb/worker/channels/init.go @@ -20,7 +20,6 @@ import ( "gitlab.com/elixxir/client/v4/channels" cryptoChannel "gitlab.com/elixxir/crypto/channel" - "gitlab.com/elixxir/crypto/message" "gitlab.com/elixxir/xxdk-wasm/storage" "gitlab.com/elixxir/xxdk-wasm/worker" ) @@ -28,17 +27,8 @@ import ( // databaseSuffix is the suffix to be appended to the name of the database. const databaseSuffix = "_speakeasy" -// MessageReceivedCallback is called any time a message is received or updated. -// -// update is true if the row is old and was edited. -type MessageReceivedCallback func(uuid int64, channelID []byte, update bool) - -// DeletedMessageCallback is called any time a message is deleted. -type DeletedMessageCallback func(messageID []byte) - -// MutedUserCallback is called any time a user is muted or unmuted. unmute is -// true if the user has been unmuted and false if they have been muted. -type MutedUserCallback func(channelID, pubKey []byte, unmute bool) +// EventUpdate is called any time an event occurs. +type EventUpdate func(eventType int64, jsonData []byte) // NewWASMEventModelBuilder returns an EventModelBuilder which allows // the channel manager to define the path but the callback is the same @@ -72,17 +62,9 @@ func NewWASMEventModel(path, wasmJsPath string, encryption cryptoChannel.Cipher, return nil, err } - // Register handler to manage messages for the MessageReceivedCallback - wm.RegisterCallback(MessageReceivedCallbackTag, - messageReceivedCallbackHandler(channelCbs.MessageReceived)) - - // Register handler to manage messages for the DeletedMessageCallback - wm.RegisterCallback(DeletedMessageCallbackTag, - deletedMessageCallbackHandler(channelCbs.MessageDeleted)) - - // Register handler to manage messages for the MutedUserCallback - wm.RegisterCallback(MutedUserCallbackTag, - mutedUserCallbackHandler(channelCbs.UserMuted)) + // Register handler to manage messages for the EventUpdate + wm.RegisterCallback(EventUpdateCallbackTag, + messageReceivedCallbackHandler(channelCbs.EventUpdate)) // Store the database name err = storage.StoreIndexedDb(databaseName) @@ -129,49 +111,18 @@ func NewWASMEventModel(path, wasmJsPath string, encryption cryptoChannel.Cipher, return &wasmModel{wm}, nil } -// MessageReceivedCallbackMessage is JSON marshalled and received from the -// worker for the [MessageReceivedCallback] callback. -type MessageReceivedCallbackMessage struct { - UUID int64 `json:"uuid"` - ChannelID []byte `json:"channelID"` - Update bool `json:"update"` +// EventUpdateCallbackMessage is JSON marshalled and received from the worker +// for the [EventUpdate] callback. +type EventUpdateCallbackMessage struct { + EventType int64 `json:"eventType"` + JsonData []byte `json:"jsonData"` } // messageReceivedCallbackHandler returns a handler to manage messages for the // MessageReceivedCallback. -func messageReceivedCallbackHandler(cb MessageReceivedCallback) func(data []byte) { - return func(data []byte) { - var msg MessageReceivedCallbackMessage - err := json.Unmarshal(data, &msg) - if err != nil { - jww.ERROR.Printf( - "Failed to JSON unmarshal %T from worker: %+v", msg, err) - return - } - - cb(msg.UUID, msg.ChannelID, msg.Update) - } -} - -// deletedMessageCallbackHandler returns a handler to manage messages for the -// DeletedMessageCallback. -func deletedMessageCallbackHandler(cb DeletedMessageCallback) func(data []byte) { - return func(data []byte) { - messageID, err := message.UnmarshalID(data) - if err != nil { - jww.ERROR.Printf( - "Failed to JSON unmarshal message ID from worker: %+v", err) - } - - cb(messageID.Bytes()) - } -} - -// mutedUserCallbackHandler returns a handler to manage messages for the -// MutedUserCallback. -func mutedUserCallbackHandler(cb MutedUserCallback) func(data []byte) { +func messageReceivedCallbackHandler(cb EventUpdate) func(data []byte) { return func(data []byte) { - var msg MuteUserMessage + var msg EventUpdateCallbackMessage err := json.Unmarshal(data, &msg) if err != nil { jww.ERROR.Printf( @@ -179,7 +130,7 @@ func mutedUserCallbackHandler(cb MutedUserCallback) func(data []byte) { return } - cb(msg.ChannelID, msg.PubKey, msg.Unmute) + cb(msg.EventType, msg.JsonData) } } diff --git a/indexedDb/worker/channels/tags.go b/indexedDb/worker/channels/tags.go index d3555e549163c18b772cc86f965a2f7aeca7a827..f21c91653547cfe37158d514ef482c468084d800 100644 --- a/indexedDb/worker/channels/tags.go +++ b/indexedDb/worker/channels/tags.go @@ -14,10 +14,8 @@ import "gitlab.com/elixxir/xxdk-wasm/worker" // List of tags that can be used when sending a message or registering a handler // to receive a message. const ( - NewWASMEventModelTag worker.Tag = "NewWASMEventModel" - MessageReceivedCallbackTag worker.Tag = "MessageReceivedCallback" - DeletedMessageCallbackTag worker.Tag = "DeletedMessageCallback" - MutedUserCallbackTag worker.Tag = "MutedUserCallback" + NewWASMEventModelTag worker.Tag = "NewWASMEventModel" + EventUpdateCallbackTag worker.Tag = "EventUpdateCallback" JoinChannelTag worker.Tag = "JoinChannel" LeaveChannelTag worker.Tag = "LeaveChannel" diff --git a/main.go b/main.go index 72976b72f40ebdaa14f14bef576b2e607c3cd5bb..bf8ab4ae1251c5ccf8413efdbc1daf94bb014b7b 100644 --- a/main.go +++ b/main.go @@ -127,6 +127,8 @@ func setGlobals() { js.Global().Set("GetShareUrlType", js.FuncOf(wasm.GetShareUrlType)) js.Global().Set("ValidForever", js.FuncOf(wasm.ValidForever)) js.Global().Set("IsNicknameValid", js.FuncOf(wasm.IsNicknameValid)) + js.Global().Set("GetNotificationReportsForMe", + js.FuncOf(wasm.GetNotificationReportsForMe)) js.Global().Set("GetNoMessageErr", js.FuncOf(wasm.GetNoMessageErr)) js.Global().Set("CheckNoMessageErr", js.FuncOf(wasm.CheckNoMessageErr)) js.Global().Set("NewChannelsDatabaseCipher", diff --git a/storage/purge.go b/storage/purge.go index 9cd7dd4bf69f2ce7cbb131c88b757058db758356..df75cebf9175251d53c722565e7c1111d6d9262f 100644 --- a/storage/purge.go +++ b/storage/purge.go @@ -51,7 +51,7 @@ func DecrementNumClientsRunning() { // passed into [wasm.NewCmix]. // // Returns: -// - Throws a TypeError if the password is incorrect or if not all cMix +// - Throws an error if the password is incorrect or if not all cMix // followers have been stopped. func Purge(_ js.Value, args []js.Value) any { storageDirectory := args[0].String() diff --git a/wasm/authenticatedConnection.go b/wasm/authenticatedConnection.go index 61087341cb62c840f4fc765930b16f193536f6d6..66162cfb68ec42906a3d596278cdf2b4801149b4 100644 --- a/wasm/authenticatedConnection.go +++ b/wasm/authenticatedConnection.go @@ -87,7 +87,7 @@ func (ac *AuthenticatedConnection) SendE2E(_ js.Value, args []js.Value) any { // resources. // // Returns: -// - Throws a TypeError if closing fails. +// - Throws an error if closing fails. func (ac *AuthenticatedConnection) Close(js.Value, []js.Value) any { return ac.api.Close() } @@ -109,7 +109,7 @@ func (ac *AuthenticatedConnection) GetPartner(js.Value, []js.Value) any { // [bindings.Listener] interface. // // Returns: -// - Throws a TypeError is registering the listener fails. +// - Throws an error is registering the listener fails. func (ac *AuthenticatedConnection) RegisterListener( _ js.Value, args []js.Value) any { err := ac.api.RegisterListener(args[0].Int(), diff --git a/wasm/backup.go b/wasm/backup.go index d0f3a885bea45ccef74e8dca1184f644fac99ede..1a4a05de8d86410493544015501f852f72e7462d 100644 --- a/wasm/backup.go +++ b/wasm/backup.go @@ -70,7 +70,7 @@ func (ubf *updateBackupFunc) UpdateBackup(encryptedBackup []byte) { // // Returns: // - JSON of [bindings.BackupReport] (Uint8Array). -// - Throws a TypeError if creating [Cmix] from backup fails. +// - Throws an error if creating [Cmix] from backup fails. func NewCmixFromBackup(_ js.Value, args []js.Value) any { ndfJSON := args[0].String() storageDir := args[1].String() @@ -105,7 +105,7 @@ func NewCmixFromBackup(_ js.Value, args []js.Value) any { // // Returns: // - Javascript representation of the [Backup] object. -// - Throws a TypeError if initializing the [Backup] fails. +// - Throws an error if initializing the [Backup] fails. func InitializeBackup(_ js.Value, args []js.Value) any { cb := &updateBackupFunc{utils.WrapCB(args[3], "UpdateBackup")} api, err := bindings.InitializeBackup( @@ -134,7 +134,7 @@ func InitializeBackup(_ js.Value, args []js.Value) any { // // Returns: // - Javascript representation of the [Backup] object. -// - Throws a TypeError if initializing the [Backup] fails. +// - Throws an error 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) @@ -150,7 +150,7 @@ func ResumeBackup(_ js.Value, args []js.Value) any { // storage. To enable backups again, call [InitializeBackup]. // // Returns: -// - Throws a TypeError if stopping the backup fails. +// - Throws an error if stopping the backup fails. func (b *Backup) StopBackup(js.Value, []js.Value) any { err := b.api.StopBackup() if err != nil { diff --git a/wasm/channels.go b/wasm/channels.go index 2c09214455d1bcea80c297f12072341ddc47a4a4..a21c9a42a1486ab84937c525028daa8c3d291817 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -53,27 +53,30 @@ func newChannelsManagerJS(api *bindings.ChannelsManager) map[string]any { "GetShareURL": js.FuncOf(cm.GetShareURL), // Channel Sending Methods and Reports - "SendGeneric": js.FuncOf(cm.SendGeneric), - "SendAdminGeneric": js.FuncOf(cm.SendAdminGeneric), - "SendMessage": js.FuncOf(cm.SendMessage), - "SendReply": js.FuncOf(cm.SendReply), - "SendReaction": js.FuncOf(cm.SendReaction), - "DeleteMessage": js.FuncOf(cm.DeleteMessage), - "PinMessage": js.FuncOf(cm.PinMessage), - "MuteUser": js.FuncOf(cm.MuteUser), - "GetIdentity": js.FuncOf(cm.GetIdentity), - "ExportPrivateIdentity": js.FuncOf(cm.ExportPrivateIdentity), - "GetStorageTag": js.FuncOf(cm.GetStorageTag), - "SetNickname": js.FuncOf(cm.SetNickname), - "DeleteNickname": js.FuncOf(cm.DeleteNickname), - "GetNickname": js.FuncOf(cm.GetNickname), - "Muted": js.FuncOf(cm.Muted), - "GetMutedUsers": js.FuncOf(cm.GetMutedUsers), - "IsChannelAdmin": js.FuncOf(cm.IsChannelAdmin), - "ExportChannelAdminKey": js.FuncOf(cm.ExportChannelAdminKey), - "VerifyChannelAdminKey": js.FuncOf(cm.VerifyChannelAdminKey), - "ImportChannelAdminKey": js.FuncOf(cm.ImportChannelAdminKey), - "DeleteChannelAdminKey": js.FuncOf(cm.DeleteChannelAdminKey), + "SendGeneric": js.FuncOf(cm.SendGeneric), + "SendAdminGeneric": js.FuncOf(cm.SendAdminGeneric), + "SendMessage": js.FuncOf(cm.SendMessage), + "SendReply": js.FuncOf(cm.SendReply), + "SendReaction": js.FuncOf(cm.SendReaction), + "SendSilent": js.FuncOf(cm.SendSilent), + "DeleteMessage": js.FuncOf(cm.DeleteMessage), + "PinMessage": js.FuncOf(cm.PinMessage), + "MuteUser": js.FuncOf(cm.MuteUser), + "GetIdentity": js.FuncOf(cm.GetIdentity), + "ExportPrivateIdentity": js.FuncOf(cm.ExportPrivateIdentity), + "GetStorageTag": js.FuncOf(cm.GetStorageTag), + "SetNickname": js.FuncOf(cm.SetNickname), + "DeleteNickname": js.FuncOf(cm.DeleteNickname), + "GetNickname": js.FuncOf(cm.GetNickname), + "Muted": js.FuncOf(cm.Muted), + "GetMutedUsers": js.FuncOf(cm.GetMutedUsers), + "GetNotificationLevel": js.FuncOf(cm.GetNotificationLevel), + "SetMobileNotificationsLevel": js.FuncOf(cm.SetMobileNotificationsLevel), + "IsChannelAdmin": js.FuncOf(cm.IsChannelAdmin), + "ExportChannelAdminKey": js.FuncOf(cm.ExportChannelAdminKey), + "VerifyChannelAdminKey": js.FuncOf(cm.VerifyChannelAdminKey), + "ImportChannelAdminKey": js.FuncOf(cm.ImportChannelAdminKey), + "DeleteChannelAdminKey": js.FuncOf(cm.DeleteChannelAdminKey), // Channel Receiving Logic and Callback Registration "RegisterReceiveHandler": js.FuncOf(cm.RegisterReceiveHandler), @@ -103,7 +106,7 @@ func (cm *ChannelsManager) GetID(js.Value, []js.Value) any { // // Returns: // - Marshalled bytes of [channel.PrivateIdentity] (Uint8Array). -// - Throws a TypeError if generating the identity fails. +// - Throws an error if generating the identity fails. func GenerateChannelIdentity(_ js.Value, args []js.Value) any { pi, err := bindings.GenerateChannelIdentity(args[0].Int()) if err != nil { @@ -126,7 +129,7 @@ var identityMap sync.Map // // Returns: // - JSON of [channel.Identity] (Uint8Array). -// - Throws a TypeError if constructing the identity fails. +// - Throws an error 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 @@ -160,7 +163,7 @@ func ConstructIdentity(_ js.Value, args []js.Value) any { // // Returns: // - JSON of [channel.Identity] (Uint8Array). -// - Throws a TypeError if constructing the identity fails. +// - Throws an error if constructing the identity fails. func constructIdentity(_ js.Value, args []js.Value) any { identity, err := bindings.ConstructIdentity( utils.CopyBytesToGo(args[0]), args[1].Int()) @@ -182,7 +185,7 @@ func constructIdentity(_ js.Value, args []js.Value) any { // // Returns: // - JSON of [channel.PrivateIdentity] (Uint8Array). -// - Throws a TypeError if importing the identity fails. +// - Throws an error if importing the identity fails. func ImportPrivateIdentity(_ js.Value, args []js.Value) any { password := args[0].String() data := utils.CopyBytesToGo(args[1]) @@ -204,7 +207,7 @@ func ImportPrivateIdentity(_ js.Value, args []js.Value) any { // // Returns: // - JSON of the constructed [channel.Identity] (Uint8Array). -// - Throws a TypeError if unmarshalling the bytes or marshalling the identity +// - Throws an error if unmarshalling the bytes or marshalling the identity // fails. func GetPublicChannelIdentity(_ js.Value, args []js.Value) any { marshaledPublic := utils.CopyBytesToGo(args[0]) @@ -227,7 +230,7 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) any { // // Returns: // - JSON of the public identity ([channel.Identity]) (Uint8Array). -// - Throws a TypeError if unmarshalling the bytes or marshalling the identity +// - Throws an error if unmarshalling the bytes or marshalling the identity // fails. func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) any { marshaledPrivate := utils.CopyBytesToGo(args[0]) @@ -270,7 +273,7 @@ func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) any { // // Returns: // - Javascript representation of the [ChannelsManager] object. -// - Throws a TypeError if creating the manager fails. +// - Throws an error if creating the manager fails. func NewChannelsManager(_ js.Value, args []js.Value) any { cmixId := args[0].Int() privateIdentity := utils.CopyBytesToGo(args[1]) @@ -318,7 +321,7 @@ func NewChannelsManager(_ js.Value, args []js.Value) any { // // Returns: // - Javascript representation of the [ChannelsManager] object. -// - Throws a TypeError if loading the manager fails. +// - Throws an error if loading the manager fails. func LoadChannelsManager(_ js.Value, args []js.Value) any { cmixID := args[0].Int() storageTag := args[1].String() @@ -370,7 +373,7 @@ func LoadChannelsManager(_ js.Value, args []js.Value) any { // 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. +// - Throws an error if the cipher ID does not correspond to a cipher. func NewChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) any { cmixID := args[0].Int() wasmJsPath := args[1].String() @@ -488,7 +491,7 @@ func newChannelsManagerWithIndexedDb(cmixID int, wasmJsPath string, // 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. +// - Throws an error if the cipher ID does not correspond to a cipher. func LoadChannelsManagerWithIndexedDb(_ js.Value, args []js.Value) any { cmixID := args[0].Int() wasmJsPath := args[1].String() @@ -659,7 +662,7 @@ func GetChannelJSON(_ js.Value, args []js.Value) any { // Returns: // - JSON of [bindings.ChannelInfo], which describes all relevant channel info // (Uint8Array). -// - Throws a TypeError if getting the channel info fails. +// - Throws an error if getting the channel info fails. func GetChannelInfo(_ js.Value, args []js.Value) any { ci, err := bindings.GetChannelInfo(args[0].String()) if err != nil { @@ -784,7 +787,7 @@ func (cm *ChannelsManager) LeaveChannel(_ js.Value, args []js.Value) any { // - args[0] - Marshalled bytes of the channel's [id.ID] (Uint8Array). // // Returns: -// - Throws a TypeError if the replay fails. +// - Throws an error if the replay fails. func (cm *ChannelsManager) ReplayChannel(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) @@ -801,7 +804,7 @@ func (cm *ChannelsManager) ReplayChannel(_ js.Value, args []js.Value) any { // // Returns: // - JSON of an array of marshalled [id.ID] (Uint8Array). -// - Throws a TypeError if getting the channels fails. +// - Throws an error if getting the channels fails. // // JSON Example: // @@ -826,7 +829,7 @@ func (cm *ChannelsManager) GetChannels(js.Value, []js.Value) any { // - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). // // Returns: -// - Throws a TypeError if saving the DM token fails. +// - Throws an error if saving the DM token fails. func (cm *ChannelsManager) EnableDirectMessages(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) err := cm.api.EnableDirectMessages(marshalledChanId) @@ -844,7 +847,7 @@ func (cm *ChannelsManager) EnableDirectMessages(_ js.Value, args []js.Value) any // - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). // // Returns: -// - Throws a TypeError if saving the DM token fails +// - Throws an error if saving the DM token fails func (cm *ChannelsManager) DisableDirectMessages(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) err := cm.api.DisableDirectMessages(marshalledChanId) @@ -862,7 +865,7 @@ func (cm *ChannelsManager) DisableDirectMessages(_ js.Value, args []js.Value) an // // Returns: // - enabled (bool) - status of dms for passed in channel ID, true if enabled -// - Throws a TypeError if unmarshalling the channel ID +// - Throws an error if unmarshalling the channel ID func (cm *ChannelsManager) AreDMsEnabled(_ js.Value, args []js.Value) any { marshalledChanId := utils.CopyBytesToGo(args[0]) enabled, err := cm.api.AreDMsEnabled(marshalledChanId) @@ -910,7 +913,7 @@ type ShareURL struct { // // Returns: // - JSON of [bindings.ShareURL] (Uint8Array). -// - Throws a TypeError if generating the URL fails. +// - Throws an error if generating the URL fails. func (cm *ChannelsManager) GetShareURL(_ js.Value, args []js.Value) any { cmixID := args[0].Int() host := args[1].String() @@ -935,7 +938,7 @@ func (cm *ChannelsManager) GetShareURL(_ js.Value, args []js.Value) any { // Returns: // - An int that corresponds to the [broadcast.PrivacyLevel] as outlined // below (int). -// - Throws a TypeError if parsing the URL fails. +// - Throws an error if parsing the URL fails. // // Possible returns: // @@ -1187,6 +1190,45 @@ func (cm *ChannelsManager) SendReaction(_ js.Value, args []js.Value) any { return utils.CreatePromise(promiseFn) } +// SendSilent is used to send to a channel a message with no notifications. +// Its primary purpose is to communicate new nicknames without calling +// [SendMessage]. +// +// It takes no payload intentionally as the message should be very lightweight. +// +// Parameters: +// - args[0] - Marshalled bytes of the channel [id.ID] (Uint8Array). +// - args[1] - The lease of the message. This will be how long the +// message is available from the network, in milliseconds (int). 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. Use [ValidForever] to last the max message life. +// - args[2] - 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 (cm *ChannelsManager) SendSilent(_ js.Value, args []js.Value) any { + var ( + marshalledChanId = utils.CopyBytesToGo(args[0]) + leaseTimeMS = int64(args[1].Int()) + cmixParamsJSON = utils.CopyBytesToGo(args[2]) + ) + + promiseFn := func(resolve, reject func(args ...any) js.Value) { + sendReport, err := cm.api.SendSilent( + marshalledChanId, leaseTimeMS, cmixParamsJSON) + if err != nil { + reject(exception.NewTrace(err)) + } else { + resolve(utils.CopyBytesToJS(sendReport)) + } + } + + return utils.CreatePromise(promiseFn) +} + //////////////////////////////////////////////////////////////////////////////// // Admin Sending // //////////////////////////////////////////////////////////////////////////////// @@ -1500,7 +1542,7 @@ func IsNicknameValid(_ js.Value, args []js.Value) any { // Returns: // - Returns true if the user is muted in the channel and false otherwise // (boolean). -// - Throws a TypeError if the channel ID cannot be unmarshalled. +// - Throws an error if the channel ID cannot be unmarshalled. func (cm *ChannelsManager) Muted(_ js.Value, args []js.Value) any { channelIDBytes := utils.CopyBytesToGo(args[0]) @@ -1523,7 +1565,7 @@ func (cm *ChannelsManager) Muted(_ js.Value, args []js.Value) any { // Returns: // - JSON of an array of ed25519.PublicKey (Uint8Array). Look below for an // example. -// - Throws a TypeError if the channel ID cannot be unmarshalled. +// - Throws an error if the channel ID cannot be unmarshalled. // // Example return: // @@ -1539,6 +1581,144 @@ func (cm *ChannelsManager) GetMutedUsers(_ js.Value, args []js.Value) any { return utils.CopyBytesToJS(mutedUsers) } +//////////////////////////////////////////////////////////////////////////////// +// Notifications // +//////////////////////////////////////////////////////////////////////////////// + +// GetNotificationLevel returns the [channels.NotificationLevel] for the given +// channel. +// +// Parameters: +// - args[0] - The marshalled bytes of the channel's [id.ID] (Uint8Array). +// +// Returns: +// - The [channels.NotificationLevel] for the channel (int). +// - Throws an error if the channel ID cannot be unmarshalled or the channel +// cannot be found. +func (cm *ChannelsManager) GetNotificationLevel(_ js.Value, args []js.Value) any { + channelIDBytes := utils.CopyBytesToGo(args[0]) + + level, err := cm.api.GetNotificationLevel(channelIDBytes) + if err != nil { + exception.ThrowTrace(err) + return nil + } + + return level +} + +// SetMobileNotificationsLevel sets the notification level for the given +// channel. The [channels.NotificationLevel] dictates the type of notifications +// received and the status controls weather the notification is push or in-app. +// If muted, both the level and status must be set to mute. +// +// To use push notifications, a token must be registered with the notification +// manager. Note, when enabling push notifications, information may be shared +// with third parties (i.e., Firebase and Google's Palantir) and may represent a +// security risk to the user. +// +// Parameters: +// - args[0] - The marshalled bytes of the channel's [id.ID] (Uint8Array). +// - args[1] - The [channels.NotificationLevel] to set for the channel (int). +// - args[2] - The [notifications.NotificationState] to set for the channel +// (int). +// +// Returns: +// - Throws an error if setting the notification level fails. +func (cm *ChannelsManager) SetMobileNotificationsLevel(_ js.Value, args []js.Value) any { + channelIDBytes := utils.CopyBytesToGo(args[0]) + level := args[1].Int() + status := args[2].Int() + + err := cm.api.SetMobileNotificationsLevel(channelIDBytes, level, status) + if err != nil { + exception.ThrowTrace(err) + return nil + } + + return nil +} + +// GetNotificationReportsForMe checks the notification data against the filter +// list to determine which notifications belong to the user. A list of +// notification reports is returned detailing all notifications for the user. +// +// Parameters: +// - notificationFilterJSON - JSON of a slice of [channels.NotificationFilter]. +// - notificationDataJSON - JSON of a slice of [notifications.Data]. +// +// Example JSON of a slice of [channels.NotificationFilter]: +// [ +// +// { +// "identifier": "O8NUg0KaDo18ybTKajXM/sgqEYS37+lewPhGV/2sMAUDYXN5bUlkZW50aWZpZXI=", +// "channelID": "O8NUg0KaDo18ybTKajXM/sgqEYS37+lewPhGV/2sMAUD", +// "tags": ["6de69009a93d53793ee344e8fb48fae194eaf51861d3cc51c7348c337d13aedf-usrping"], +// "allowLists": { +// "allowWithTags": {}, +// "allowWithoutTags": {"102":{}, "2":{}} +// } +// }, +// { +// "identifier": "O8NUg0KaDo18ybTKajXM/sgqEYS37+lewPhGV/2sMAUDc3ltSWRlbnRpZmllcg==", +// "channelID": "O8NUg0KaDo18ybTKajXM/sgqEYS37+lewPhGV/2sMAUD", +// "tags": ["6de69009a93d53793ee344e8fb48fae194eaf51861d3cc51c7348c337d13aedf-usrping"], +// "allowLists": { +// "allowWithTags": {}, +// "allowWithoutTags": {"1":{}, "40000":{}} +// } +// }, +// { +// "identifier": "jCRgFRQvzzKOb8DJ0fqCRLgr9kiHN9LpqHXVhyHhhlQDYXN5bUlkZW50aWZpZXI=", +// "channelID": "jCRgFRQvzzKOb8DJ0fqCRLgr9kiHN9LpqHXVhyHhhlQD", +// "tags": ["6de69009a93d53793ee344e8fb48fae194eaf51861d3cc51c7348c337d13aedf-usrping"], +// "allowLists": { +// "allowWithTags": {}, +// "allowWithoutTags": {"102":{}, "2":{}} +// } +// } +// ] +// +// Example JSON of a slice of [notifications.Data]: +// +// [ +// { +// "EphemeralID": -6475, +// "RoundID": 875, +// "IdentityFP": "jWG/UuxRjD80HEo0WX3KYIag5LCfgaWKAg==", +// "MessageHash": "hDGE46QWa3d70y5nJTLbEaVmrFJHOyp2" +// }, +// { +// "EphemeralID": -2563, +// "RoundID": 875, +// "IdentityFP": "gL4nhCGKPNBm6YZ7KC0v4JThw65N9bRLTQ==", +// "MessageHash": "WcS4vGrSWDK8Kj7JYOkMo8kSh1Xti94V" +// }, +// { +// "EphemeralID": -13247, +// "RoundID": 875, +// "IdentityFP": "qV3uD++VWPhD2rRMmvrP9j8hp+jpFSsUHg==", +// "MessageHash": "VX6Tw7N48j7U2rRXYle20mFZi0If4CB1" +// } +// ] +// +// Returns: +// - The JSON of a slice of [channels.NotificationReport] (Uint8Array). +// - Throws an error if getting the report fails. +func GetNotificationReportsForMe(_ js.Value, args []js.Value) any { + notificationFilterJSON := utils.CopyBytesToGo(args[0]) + notificationDataJSON := utils.CopyBytesToGo(args[1]) + + report, err := bindings.GetNotificationReportsForMe( + notificationFilterJSON, notificationDataJSON) + if err != nil { + exception.ThrowTrace(err) + return nil + } + + return utils.CopyBytesToJS(report) +} + //////////////////////////////////////////////////////////////////////////////// // Admin Management // //////////////////////////////////////////////////////////////////////////////// @@ -1551,7 +1731,7 @@ func (cm *ChannelsManager) GetMutedUsers(_ js.Value, args []js.Value) any { // Returns: // - True if the user is an admin in the channel and false otherwise // (boolean). -// - Throws a TypeError if the channel ID cannot be unmarshalled. +// - Throws an error if the channel ID cannot be unmarshalled. func (cm *ChannelsManager) IsChannelAdmin(_ js.Value, args []js.Value) any { isAdmin, err := cm.api.IsChannelAdmin(utils.CopyBytesToGo(args[0])) if err != nil { @@ -1587,7 +1767,7 @@ func (cm *ChannelsManager) IsChannelAdmin(_ js.Value, args []js.Value) any { // Returns: // - Portable string of the channel private key encrypted with the password // (Uint8Array). -// - Throws a TypeError if the user is not an admin for the channel. +// - Throws an error if the user is not an admin for the channel. func (cm *ChannelsManager) ExportChannelAdminKey(_ js.Value, args []js.Value) any { pk, err := cm.api.ExportChannelAdminKey( utils.CopyBytesToGo(args[0]), args[1].String()) @@ -1610,14 +1790,14 @@ func (cm *ChannelsManager) ExportChannelAdminKey(_ js.Value, args []js.Value) an // Returns: // - Returns false if private key does not belong to the given channel ID // (boolean). -// - Throws a TypeError if the password is invalid. +// - Throws an error if the password is invalid. // // Returns: // - bool - True if the private key belongs to the channel and false // otherwise. -// - Throws a TypeError with the message [channels.WrongPasswordErr] for an +// - Throws an error with the message [channels.WrongPasswordErr] for an // invalid password. -// - Throws a TypeError with the message [channels.ChannelDoesNotExistsErr] i +// - Throws an error with the message [channels.ChannelDoesNotExistsErr] i // the channel has not already been joined. func (cm *ChannelsManager) VerifyChannelAdminKey(_ js.Value, args []js.Value) any { channelID := utils.CopyBytesToGo(args[0]) @@ -1644,13 +1824,13 @@ func (cm *ChannelsManager) VerifyChannelAdminKey(_ js.Value, args []js.Value) an // - args[2] - The encrypted channel private key packet (Uint8Array). // // Returns: -// - Throws a TypeError if the password is invalid or the private key does +// - Throws an error if the password is invalid or the private key does // not match the channel ID. -// - Throws a TypeError with the message [channels.WrongPasswordErr] for an +// - Throws an error with the message [channels.WrongPasswordErr] for an // invalid password. -// - Throws a TypeError with the message [channels.ChannelDoesNotExistsErr] if +// - Throws an error with the message [channels.ChannelDoesNotExistsErr] if // the channel has not already been joined. -// - Throws a TypeError with the message [channels.WrongPrivateKeyErr] if the +// - Throws an error with the message [channels.WrongPrivateKeyErr] if the // private key does not belong to the channel. func (cm *ChannelsManager) ImportChannelAdminKey(_ js.Value, args []js.Value) any { channelID := utils.CopyBytesToGo(args[0]) @@ -1676,7 +1856,7 @@ func (cm *ChannelsManager) ImportChannelAdminKey(_ js.Value, args []js.Value) an // - args[0] - The marshalled bytes of the channel's [id.ID] (Uint8Array) // // Returns: -// - Throws a TypeError if the deletion fails. +// - Throws an error if the deletion fails. func (cm *ChannelsManager) DeleteChannelAdminKey(_ js.Value, args []js.Value) any { err := cm.api.DeleteChannelAdminKey(utils.CopyBytesToGo(args[0])) if err != nil { @@ -1738,7 +1918,7 @@ func (cmrCB *channelMessageReceptionCallback) Callback( // users (boolean). // // Returns: -// - Throws a TypeError if registering the handler fails. +// - Throws an error if registering the handler fails. func (cm *ChannelsManager) RegisterReceiveHandler(_ js.Value, args []js.Value) any { messageType := args[0].Int() listenerCb := &channelMessageReceptionCallback{ @@ -2169,7 +2349,7 @@ func newChannelDbCipherJS(api *bindings.ChannelDbCipher) map[string]any { // // Returns: // - JavaScript representation of the [ChannelDbCipher] object. -// - Throws a TypeError if creating the cipher fails. +// - Throws an error if creating the cipher fails. func NewChannelsDatabaseCipher(_ js.Value, args []js.Value) any { cmixId := args[0].Int() password := utils.CopyBytesToGo(args[1]) @@ -2204,7 +2384,7 @@ func (c *ChannelDbCipher) GetID(js.Value, []js.Value) any { // // Returns: // - The ciphertext of the plaintext passed in (Uint8Array). -// - Throws a TypeError if it fails to encrypt the plaintext. +// - Throws an error if it fails to encrypt the plaintext. func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) any { ciphertext, err := c.api.Encrypt(utils.CopyBytesToGo(args[0])) if err != nil { @@ -2225,7 +2405,7 @@ func (c *ChannelDbCipher) Encrypt(_ js.Value, args []js.Value) any { // // Returns: // - The plaintext of the ciphertext passed in (Uint8Array). -// - Throws a TypeError if it fails to encrypt the plaintext. +// - Throws an error if it fails to encrypt the plaintext. func (c *ChannelDbCipher) Decrypt(_ js.Value, args []js.Value) any { plaintext, err := c.api.Decrypt(utils.CopyBytesToGo(args[0])) if err != nil { @@ -2240,7 +2420,7 @@ func (c *ChannelDbCipher) Decrypt(_ js.Value, args []js.Value) any { // // Returns: // - JSON of the cipher (Uint8Array). -// - Throws a TypeError if marshalling fails. +// - Throws an error if marshalling fails. func (c *ChannelDbCipher) MarshalJSON(js.Value, []js.Value) any { data, err := c.api.MarshalJSON() if err != nil { @@ -2261,7 +2441,7 @@ func (c *ChannelDbCipher) MarshalJSON(js.Value, []js.Value) any { // // Returns: // - JSON of the cipher (Uint8Array). -// - Throws a TypeError if marshalling fails. +// - Throws an error if marshalling fails. func (c *ChannelDbCipher) UnmarshalJSON(_ js.Value, args []js.Value) any { err := c.api.UnmarshalJSON(utils.CopyBytesToGo(args[0])) if err != nil { diff --git a/wasm/cmix.go b/wasm/cmix.go index 3b735f4eb477652b80ed9b54b93c5334cfe33c6d..be7ad6d31f2052b6f9750703611b4789cff35009 100644 --- a/wasm/cmix.go +++ b/wasm/cmix.go @@ -15,7 +15,6 @@ import ( "gitlab.com/elixxir/client/v4/bindings" "gitlab.com/elixxir/wasm-utils/exception" "gitlab.com/elixxir/wasm-utils/utils" - "syscall/js" ) // Cmix wraps the [bindings.Cmix] object so its methods can be wrapped to be @@ -168,7 +167,7 @@ func LoadSynchronizedCmix(_ js.Value, args []js.Value) any { net, err := bindings.LoadSynchronizedCmix(storageDir, password, rs, cmixParamsJSON) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(newCmixJS(net)) } diff --git a/wasm/collective.go b/wasm/collective.go index 5b35b3d4b597f0bf79543e1f38cb741c49ee8d24..932926d34d878bb042628125d271f9ce5b2a8dee 100644 --- a/wasm/collective.go +++ b/wasm/collective.go @@ -10,6 +10,7 @@ package wasm import ( + "gitlab.com/elixxir/wasm-utils/exception" "syscall/js" "gitlab.com/elixxir/client/v4/bindings" @@ -72,7 +73,7 @@ func (r *RemoteKV) Get(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { value, err := r.api.Get(key, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(utils.CopyBytesToJS(value)) } @@ -97,7 +98,7 @@ func (r *RemoteKV) Delete(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { err := r.api.Delete(key, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve() } @@ -128,7 +129,7 @@ func (r *RemoteKV) Set(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { err := r.api.Set(key, value) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve() } @@ -178,7 +179,7 @@ func (r *RemoteKV) Prefix(_ js.Value, args []js.Value) any { newAPI, err := r.api.Prefix(prefix) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(newRemoteKvJS(newAPI)) } @@ -193,7 +194,7 @@ func (r *RemoteKV) Root(_ js.Value, args []js.Value) any { newAPI, err := r.api.Root() if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(newRemoteKvJS(newAPI)) } @@ -260,7 +261,7 @@ func (r *RemoteKV) StoreMapElement(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { err := r.api.StoreMapElement(mapName, elementKey, val, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve() } @@ -291,7 +292,7 @@ func (r *RemoteKV) StoreMap(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { err := r.api.StoreMap(mapName, val, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve() } @@ -321,7 +322,7 @@ func (r *RemoteKV) DeleteMapElement(_ js.Value, args []js.Value) any { deleted, err := r.api.DeleteMapElement(mapName, elementKey, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(utils.CopyBytesToJS(deleted)) } @@ -350,7 +351,7 @@ func (r *RemoteKV) GetMap(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { mapJSON, err := r.api.GetMap(mapName, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(utils.CopyBytesToJS(mapJSON)) } @@ -381,7 +382,7 @@ func (r *RemoteKV) GetMapElement(_ js.Value, args []js.Value) any { deleted, err := r.api.GetMapElement(mapName, elementKey, version) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(utils.CopyBytesToJS(deleted)) } @@ -411,7 +412,7 @@ func (r *RemoteKV) ListenOnRemoteKey(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { deleted, err := r.api.ListenOnRemoteKey(key, version, cb) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(utils.CopyBytesToJS(deleted)) } @@ -441,7 +442,7 @@ func (r *RemoteKV) ListenOnRemoteMap(_ js.Value, args []js.Value) any { promiseFn := func(resolve, reject func(args ...any) js.Value) { deleted, err := r.api.ListenOnRemoteMap(mapName, version, cb) if err != nil { - reject(utils.JsTrace(err)) + reject(exception.NewTrace(err)) } else { resolve(utils.CopyBytesToJS(deleted)) } @@ -487,7 +488,7 @@ func newRemoteStore(arg js.Value) *RemoteStore { func (rsCB *RemoteStore) Read(path string) ([]byte, error) { fn := func() js.Value { return rsCB.read(path) } - v, err := utils.RunAndCatch(fn) + v, err := exception.RunAndCatch(fn) if err != nil { return nil, err } @@ -504,7 +505,7 @@ func (rsCB *RemoteStore) Read(path string) ([]byte, error) { // - Catches any thrown errors (of type Error) and returns it as an error. func (rsCB *RemoteStore) Write(path string, data []byte) error { fn := func() js.Value { return rsCB.write(path, utils.CopyBytesToJS(data)) } - _, err := utils.RunAndCatch(fn) + _, err := exception.RunAndCatch(fn) return err } @@ -518,7 +519,7 @@ func (rsCB *RemoteStore) Write(path string, data []byte) error { // - Catches any thrown errors (of type Error) and returns it as an error. func (rsCB *RemoteStore) GetLastModified(path string) ([]byte, error) { fn := func() js.Value { return rsCB.getLastModified(path) } - v, err := utils.RunAndCatch(fn) + v, err := exception.RunAndCatch(fn) if err != nil { return nil, err } @@ -532,7 +533,7 @@ func (rsCB *RemoteStore) GetLastModified(path string) ([]byte, error) { // - Catches any thrown errors (of type Error) and returns it as an error. func (rsCB *RemoteStore) GetLastWrite() ([]byte, error) { fn := func() js.Value { return rsCB.getLastWrite() } - v, err := utils.RunAndCatch(fn) + v, err := exception.RunAndCatch(fn) if err != nil { return nil, err } @@ -549,7 +550,7 @@ func (rsCB *RemoteStore) GetLastWrite() ([]byte, error) { // - Catches any thrown errors (of type Error) and returns it as an error. func (rsCB *RemoteStore) ReadDir(path string) ([]byte, error) { fn := func() js.Value { return rsCB.readDir(path) } - v, err := utils.RunAndCatch(fn) + v, err := exception.RunAndCatch(fn) if err != nil { return nil, err } diff --git a/wasm/connect.go b/wasm/connect.go index 279b98512e9b6ad91b62f0b6428a4d510b8c1f78..b6b78e6940f1314d6d189e737d016db89112110b 100644 --- a/wasm/connect.go +++ b/wasm/connect.go @@ -108,7 +108,7 @@ func (c *Connection) SendE2E(_ js.Value, args []js.Value) any { // Close deletes this [Connection]'s [partner.Manager] and releases resources. // // Returns: -// - Throws a TypeError if closing fails. +// - Throws an error if closing fails. func (c *Connection) Close(js.Value, []js.Value) any { err := c.api.Close() if err != nil { @@ -154,7 +154,7 @@ func (l *listener) Name() string { return l.name().String() } // [bindings.Listener] interface. // // Returns: -// - Throws a TypeError is registering the listener fails. +// - Throws an error 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")}) diff --git a/wasm/delivery.go b/wasm/delivery.go index 43c56a69d20c2da68228d2c701505c8938c86654..67bc677bc300ca0d5108b33dd5573f1f0d80c4ed 100644 --- a/wasm/delivery.go +++ b/wasm/delivery.go @@ -80,7 +80,7 @@ func (mdc *messageDeliveryCallback) EventCallback( // occurs, in milliseconds (int). // // Returns: -// - Throws a TypeError if the parameters are invalid or getting round results +// - Throws an error 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]) diff --git a/wasm/dm.go b/wasm/dm.go index 5503799fc7bd48be7ddc465202b6a9b4079c30fb..101ce92bdb36884069e3c71e6bc63074828a0d9d 100644 --- a/wasm/dm.go +++ b/wasm/dm.go @@ -61,6 +61,7 @@ func newDMClientJS(api *bindings.DMClient) map[string]any { "SendText": js.FuncOf(cm.SendText), "SendReply": js.FuncOf(cm.SendReply), "SendReaction": js.FuncOf(cm.SendReaction), + "SendSilent": js.FuncOf(cm.SendSilent), "Send": js.FuncOf(cm.Send), } @@ -86,7 +87,7 @@ func newDMClientJS(api *bindings.DMClient) map[string]any { // // Returns: // - Javascript representation of the [DMClient] object. -// - Throws a TypeError if creating the manager fails. +// - Throws an error if creating the manager fails. func NewDMClient(_ js.Value, args []js.Value) any { privateIdentity := utils.CopyBytesToGo(args[1]) em := newDMReceiverBuilder(args[2]) @@ -129,7 +130,7 @@ func NewDMClient(_ js.Value, args []js.Value) any { // Returns: // - Resolves to a Javascript representation of the [DMClient] object. // - Rejected with an error if loading indexedDbWorker or the manager fails. -// - Throws a TypeError if the cipher ID does not correspond to a cipher. +// - Throws an error if the cipher ID does not correspond to a cipher. func NewDMClientWithIndexedDb(_ js.Value, args []js.Value) any { cmixID := args[0].Int() wasmJsPath := args[1].String() @@ -474,6 +475,42 @@ func (dmc *DMClient) SendReaction(_ js.Value, args []js.Value) any { return utils.CreatePromise(promiseFn) } +// SendSilent is used to send to a channel a message with no notifications. +// Its primary purpose is to communicate new nicknames without calling [Send]. +// +// It takes no payload intentionally as the message should be very lightweight. +// +// Parameters: +// - args[0] - The bytes of the public key of the partner's ED25519 +// signing key (Uint8Array). +// - args[1] - The token used to derive the reception ID for the partner +// (int). +// - args[2] - 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 (dmc *DMClient) SendSilent(_ js.Value, args []js.Value) any { + var ( + partnerPubKeyBytes = utils.CopyBytesToGo(args[0]) + partnerToken = int32(args[1].Int()) + cmixParamsJSON = utils.CopyBytesToGo(args[2]) + ) + + promiseFn := func(resolve, reject func(args ...any) js.Value) { + sendReport, err := dmc.api.SendSilent( + partnerPubKeyBytes, partnerToken, cmixParamsJSON) + if err != nil { + reject(exception.NewTrace(err)) + } else { + resolve(utils.CopyBytesToJS(sendReport)) + } + } + + return utils.CreatePromise(promiseFn) +} + // Send is used to send a raw message. In general, it // should be wrapped in a function that defines the wire protocol. // @@ -962,7 +999,7 @@ func newDMDbCipherJS(api *bindings.DMDbCipher) map[string]any { // // Returns: // - JavaScript representation of the [DMDbCipher] object. -// - Throws a TypeError if creating the cipher fails. +// - Throws an error if creating the cipher fails. func NewDMsDatabaseCipher(_ js.Value, args []js.Value) any { cmixId := args[0].Int() password := utils.CopyBytesToGo(args[1]) @@ -997,7 +1034,7 @@ func (c *DMDbCipher) GetID(js.Value, []js.Value) any { // // Returns: // - The ciphertext of the plaintext passed in (Uint8Array). -// - Throws a TypeError if it fails to encrypt the plaintext. +// - Throws an error if it fails to encrypt the plaintext. func (c *DMDbCipher) Encrypt(_ js.Value, args []js.Value) any { ciphertext, err := c.api.Encrypt(utils.CopyBytesToGo(args[0])) if err != nil { @@ -1018,7 +1055,7 @@ func (c *DMDbCipher) Encrypt(_ js.Value, args []js.Value) any { // // Returns: // - The plaintext of the ciphertext passed in (Uint8Array). -// - Throws a TypeError if it fails to encrypt the plaintext. +// - Throws an error if it fails to encrypt the plaintext. func (c *DMDbCipher) Decrypt(_ js.Value, args []js.Value) any { plaintext, err := c.api.Decrypt(utils.CopyBytesToGo(args[0])) if err != nil { @@ -1033,7 +1070,7 @@ func (c *DMDbCipher) Decrypt(_ js.Value, args []js.Value) any { // // Returns: // - JSON of the cipher (Uint8Array). -// - Throws a TypeError if marshalling fails. +// - Throws an error if marshalling fails. func (c *DMDbCipher) MarshalJSON(js.Value, []js.Value) any { data, err := c.api.MarshalJSON() if err != nil { @@ -1055,7 +1092,7 @@ func (c *DMDbCipher) MarshalJSON(js.Value, []js.Value) any { // // Returns: // - JSON of the cipher (Uint8Array). -// - Throws a TypeError if marshalling fails. +// - Throws an error if marshalling fails. func (c *DMDbCipher) UnmarshalJSON(_ js.Value, args []js.Value) any { err := c.api.UnmarshalJSON(utils.CopyBytesToGo(args[0])) if err != nil { diff --git a/wasm/dummy.go b/wasm/dummy.go index b0fa6a82bad4f8e28290663eff285d002f10cafb..9efbc687eee46005192148f75f3164b81421a531 100644 --- a/wasm/dummy.go +++ b/wasm/dummy.go @@ -53,7 +53,7 @@ func newDummyTrafficJS(newDT *bindings.DummyTraffic) map[string]any { // // Returns: // - Javascript representation of the DummyTraffic object. -// - Throws a TypeError if creating the manager fails. +// - Throws an error 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()) @@ -75,7 +75,7 @@ func NewDummyTrafficManager(_ js.Value, args []js.Value) any { // thread will then be prevented from beginning another round of sending. // // Returns: -// - Throws a TypeError if it fails to send a pause signal to the sending +// - Throws an error if it fails to send a pause signal to the sending // thread. func (dt *DummyTraffic) Pause(js.Value, []js.Value) any { err := dt.api.Pause() @@ -98,7 +98,7 @@ func (dt *DummyTraffic) Pause(js.Value, []js.Value) any { // sending interval after a call to Start. // // Returns: -// - Throws a TypeError if it fails to send a start signal to the sending +// - Throws an error if it fails to send a start signal to the sending // thread. func (dt *DummyTraffic) Start(js.Value, []js.Value) any { err := dt.api.Start() diff --git a/wasm/e2e.go b/wasm/e2e.go index 5f3debbca3bb52f2b5e594942eaed3c96bcabd5a..dcb4853d23745f0d85a879284a6b2c918a1d5f39 100644 --- a/wasm/e2e.go +++ b/wasm/e2e.go @@ -91,7 +91,7 @@ func (e *E2e) GetID(js.Value, []js.Value) any { // // Returns: // - Javascript representation of the [E2e] object. -// - Throws a TypeError if logging in fails. +// - Throws an error if logging in fails. func Login(_ js.Value, args []js.Value) any { callbacks := newAuthCallbacks(args[1]) identity := utils.CopyBytesToGo(args[2]) @@ -121,7 +121,7 @@ func Login(_ js.Value, args []js.Value) any { // // Returns: // - Javascript representation of the [E2e] object. -// - Throws a TypeError if logging in fails. +// - Throws an error if logging in fails. func LoginEphemeral(_ js.Value, args []js.Value) any { callbacks := newAuthCallbacks(args[1]) identity := utils.CopyBytesToGo(args[2]) @@ -168,7 +168,7 @@ func (e *E2e) GetUdCertFromNdf(js.Value, []js.Value) any { // // Returns // - Marshalled bytes of [contact.Contact] (Uint8Array). -// - Throws a TypeError if the contact file cannot be loaded. +// - Throws an error if the contact file cannot be loaded. func (e *E2e) GetUdContactFromNdf(js.Value, []js.Value) any { b, err := e.api.GetUdContactFromNdf() if err != nil { diff --git a/wasm/e2eHandler.go b/wasm/e2eHandler.go index 7f3b5966e886b7e77752da24a03f64ac369b01be..ae3eb14c01991606c764022b9983c788bf36b81f 100644 --- a/wasm/e2eHandler.go +++ b/wasm/e2eHandler.go @@ -200,13 +200,16 @@ type processor struct { // // Parameters: // - message - Returns the message contents (Uint8Array). +// - tags - (Uint8Array). +// - metadata - (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), +func (p *processor) Process(message, tags, metadata, receptionId []byte, + ephemeralId, roundId int64) { + p.process(utils.CopyBytesToJS(message), utils.CopyBytesToJS(tags), + utils.CopyBytesToJS(metadata), utils.CopyBytesToJS(receptionId), ephemeralId, roundId) } diff --git a/wasm/emoji.go b/wasm/emoji.go index fd64418cdc7c14ac823c3115178d835efc88faf2..7be8ce8e45461c4e2ffb1a0f1f215cff313421a4 100644 --- a/wasm/emoji.go +++ b/wasm/emoji.go @@ -22,7 +22,7 @@ import ( // // Returns: // - JSON of an array of emoji.Emoji (Uint8Array). -// - Throws a TypeError if marshalling the JSON fails. +// - Throws an error if marshalling the JSON fails. // // Example JSON: // @@ -69,7 +69,7 @@ func SupportedEmojis(js.Value, []js.Value) any { // // Returns: // - JSON of a map of emoji.Emoji (Uint8Array). -// - Throws a TypeError if marshalling the JSON fails. +// - Throws an error if marshalling the JSON fails. // // Example JSON: // diff --git a/wasm/errors.go b/wasm/errors.go index baf9e8b095afed9b291bdfc9c793eaf3d70bea7f..2b2bab8c2ce6ebc762bad96c8e317de313207e6f 100644 --- a/wasm/errors.go +++ b/wasm/errors.go @@ -49,7 +49,7 @@ func CreateUserFriendlyErrorMessage(_ js.Value, args []js.Value) any { // } // // Returns: -// - Throws a TypeError if the JSON cannot be unmarshalled. +// - Throws an error if the JSON cannot be unmarshalled. func UpdateCommonErrors(_ js.Value, args []js.Value) any { err := bindings.UpdateCommonErrors(args[0].String()) if err != nil { diff --git a/wasm/fileTransfer.go b/wasm/fileTransfer.go index e91a8837cec438f4644e48407fdf2924a81eb1bc..033c410c1231685db46a9c88ea999d1c2be727f3 100644 --- a/wasm/fileTransfer.go +++ b/wasm/fileTransfer.go @@ -125,7 +125,7 @@ func (rpc *fileTransferReceiveProgressCallback) Callback( // // Returns: // - Javascript representation of the [FileTransfer] object. -// - Throws a TypeError initialising the file transfer manager fails. +// - Throws an error 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]) @@ -186,7 +186,7 @@ func (f *FileTransfer) Send(_ js.Value, args []js.Value) any { // // Returns: // - File contents (Uint8Array). -// - Throws a TypeError the file transfer is incomplete or Receive has already +// - Throws an error 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])) @@ -209,7 +209,7 @@ func (f *FileTransfer) Receive(_ js.Value, args []js.Value) any { // - args[0] - File transfer [fileTransfer.TransferID] (Uint8Array). // // Returns: -// - Throws a TypeError if the file transfer is incomplete. +// - Throws an error 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 { @@ -238,7 +238,7 @@ func (f *FileTransfer) CloseSend(_ js.Value, args []js.Value) any { // triggering (int). // // Returns: -// - Throws a TypeError if registering the callback fails. +// - Throws an error if registering the callback fails. func (f *FileTransfer) RegisterSentProgressCallback( _ js.Value, args []js.Value) any { tidBytes := utils.CopyBytesToGo(args[0]) @@ -266,7 +266,7 @@ func (f *FileTransfer) RegisterSentProgressCallback( // triggering (int). // // Returns: -// - Throws a TypeError if registering the callback fails. +// - Throws an error if registering the callback fails. func (f *FileTransfer) RegisterReceivedProgressCallback( _ js.Value, args []js.Value) any { tidBytes := utils.CopyBytesToGo(args[0]) diff --git a/wasm/follow.go b/wasm/follow.go index b215bf5471ca7d5028a7d84d6128c61394e472e4..992596fc2cf80d543febdcd6facec9b658479f11 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -54,7 +54,7 @@ import ( // - args[0] - Timeout when stopping threads in milliseconds (int). // // Returns: -// - Throws a TypeError if starting the network follower fails. +// - Throws an error 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 { @@ -72,7 +72,7 @@ func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) any { // 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 +// - Throws an error 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() @@ -381,6 +381,51 @@ func (tsc *trackServicesCallback) Callback(marshalData []byte, err error) { tsc.callback(utils.CopyBytesToJS(marshalData), exception.NewTrace(err)) } +// trackCompressedServicesCallback adheres to the +// [bindings.TrackCompressedServicesCallback] interface. +type trackCompressedServicesCallback struct { + callback func(args ...any) js.Value +} + +// Callback is the callback for [Cmix.TrackServices] that passes a +// JSON-marshalled list of compressed backend services. If an error occurs while +// retrieving or marshalling the service list, then err will be non-null. +// +// Parameters: +// - marshalData - JSON of [message.CompressedServiceList] (Uint8Array), +// which is a map of [id.ID] to an array of [message.CompressedService]. +// - err - Error that occurs during retrieval or marshalling. Null otherwise +// (Error). +// +// Example JSON: +// +// { +// "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD": [ +// { +// "Identifier": null, +// "Tags": ["test"], +// "Metadata": null +// } +// ], +// "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD": [ +// { +// "Identifier": null, +// "Tags": ["test"], +// "Metadata": null +// } +// ], +// "AAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD": [ +// { +// "Identifier": null, +// "Tags": ["test"], +// "Metadata": null +// } +// ] +// } +func (tsc *trackCompressedServicesCallback) Callback(marshalData []byte, err error) { + tsc.callback(utils.CopyBytesToJS(marshalData), exception.NewTrace(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 @@ -390,12 +435,16 @@ func (tsc *trackServicesCallback) Callback(marshalData []byte, err error) { // - args[0] - ID of [E2e] object in tracker (int). // - args[1] - Javascript object that has functions that implement the // [bindings.ClientError] interface. +// - args[2] - Javascript object that has functions that implement the +// [bindings.TrackCompressedServicesCallback], which will be passed the JSON +// of [message.CompressedServiceList]. // // 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")}) + &trackServicesCallback{utils.WrapCB(args[0], "Callback")}, + &trackCompressedServicesCallback{utils.WrapCB(args[0], "Callback")}) if err != nil { exception.ThrowTrace(err) return nil diff --git a/wasm/group.go b/wasm/group.go index 459a07db0cd79815da19f5d86254150f88ad1748..e824d4ee85ce7610f99e6e63dba6ab56e0e58f2a 100644 --- a/wasm/group.go +++ b/wasm/group.go @@ -55,7 +55,7 @@ func newGroupChatJS(api *bindings.GroupChat) map[string]any { // // Returns: // - Javascript representation of the [GroupChat] object. -// - Throws a TypeError if creating the [GroupChat] fails. +// - Throws an error if creating the [GroupChat] fails. func NewGroupChat(_ js.Value, args []js.Value) any { requestFunc := &groupRequest{utils.WrapCB(args[1], "Callback")} p := &groupChatProcessor{ @@ -136,7 +136,7 @@ func (g *GroupChat) ResendRequest(_ js.Value, args []js.Value) any { // object returned over the bindings (Uint8Array). // // Returns: -// - Throws a TypeError if joining the group fails. +// - Throws an error 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 { @@ -154,7 +154,7 @@ func (g *GroupChat) JoinGroup(_ js.Value, args []js.Value) any { // can be found in the report returned by [GroupChat.MakeGroup]. // // Returns: -// - Throws a TypeError if leaving the group fails. +// - Throws an error 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 { @@ -201,7 +201,7 @@ func (g *GroupChat) Send(_ js.Value, args []js.Value) any { // // Returns: // - JSON of array of [id.ID] representing all group ID's (Uint8Array). -// - Throws a TypeError if getting the groups fails. +// - Throws an error if getting the groups fails. func (g *GroupChat) GetGroups(js.Value, []js.Value) any { groups, err := g.api.GetGroups() if err != nil { @@ -221,7 +221,7 @@ func (g *GroupChat) GetGroups(js.Value, []js.Value) any { // // Returns: // - Javascript representation of the [GroupChat] object. -// - Throws a TypeError if getting the group fails. +// - Throws an error 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 { @@ -315,7 +315,7 @@ func (g *Group) GetCreatedMS(js.Value, []js.Value) any { // // Returns: // - JSON of [group.Membership] (Uint8Array). -// - Throws a TypeError if marshalling fails. +// - Throws an error if marshalling fails. func (g *Group) GetMembership(js.Value, []js.Value) any { membership, err := g.api.GetMembership() if err != nil { @@ -342,7 +342,7 @@ func (g *Group) Serialize(js.Value, []js.Value) any { // // Returns: // - Javascript representation of the [GroupChat] object. -// - Throws a TypeError if getting the group fails. +// - Throws an error if getting the group fails. func DeserializeGroup(_ js.Value, args []js.Value) any { grp, err := bindings.DeserializeGroup(utils.CopyBytesToGo(args[0])) if err != nil { diff --git a/wasm/identity.go b/wasm/identity.go index 013d2059b31378b2ce2e580723ada3d59fa35697..0800fffa8d209ab1bfd2c004998ade87c45cf2b3 100644 --- a/wasm/identity.go +++ b/wasm/identity.go @@ -32,7 +32,7 @@ import ( // - args[2] - ID of [Cmix] object in tracker (int). // // Returns: -// - Throws a TypeError if the identity cannot be stored in storage. +// - Throws an error if the identity cannot be stored in storage. func StoreReceptionIdentity(_ js.Value, args []js.Value) any { identity := utils.CopyBytesToGo(args[1]) err := bindings.StoreReceptionIdentity( @@ -55,7 +55,7 @@ func StoreReceptionIdentity(_ js.Value, args []js.Value) any { // // Returns: // - JSON of the stored [xxdk.ReceptionIdentity] object (Uint8Array). -// - Throws a TypeError if the identity cannot be retrieved from storage. +// - Throws an error 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 { @@ -127,7 +127,7 @@ func (c *Cmix) GetReceptionRegistrationValidationSignature( // // Returns: // - Marshalled bytes of [contact.Contact] (string). -// - Throws a TypeError if unmarshalling the identity fails. +// - Throws an error 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]) @@ -147,7 +147,7 @@ func GetContactFromReceptionIdentity(_ js.Value, args []js.Value) any { // // Returns: // - Marshalled bytes of [id.ID] (Uint8Array). -// - Throws a TypeError if loading the ID from the contact file fails. +// - Throws an error 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 { @@ -166,7 +166,7 @@ func GetIDFromContact(_ js.Value, args []js.Value) any { // // Returns: // - Bytes of the [cyclic.Int] object (Uint8Array). -// - Throws a TypeError if loading the public key from the contact file fails. +// - Throws an error 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 { @@ -190,7 +190,7 @@ func GetPubkeyFromContact(_ js.Value, args []js.Value) any { // // Returns: // - Marshalled bytes of the modified [contact.Contact] (string). -// - Throws a TypeError if loading or modifying the contact fails. +// - Throws an error 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]) @@ -210,7 +210,7 @@ func SetFactsOnContact(_ js.Value, args []js.Value) any { // // Returns: // - JSON of [fact.FactList] (Uint8Array). -// - Throws a TypeError if loading the contact fails. +// - Throws an error if loading the contact fails. func GetFactsFromContact(_ js.Value, args []js.Value) any { fl, err := bindings.GetFactsFromContact(utils.CopyBytesToGo(args[0])) if err != nil { diff --git a/wasm/restlikeSingle.go b/wasm/restlikeSingle.go index 7a2e8f8c2828b3c3b91b56e0ba5cce3ed45ef548..41118d7f6d6ae32960712ea2f0436a927d28255d 100644 --- a/wasm/restlikeSingle.go +++ b/wasm/restlikeSingle.go @@ -80,7 +80,7 @@ func RequestRestLike(_ js.Value, args []js.Value) any { // [bindings.RestlikeCallback] interface. // // Returns: -// - Throws a TypeError if parsing the parameters or making the request fails. +// - Throws an error 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]) diff --git a/wasm/single.go b/wasm/single.go index 5d6aa92eef53055bf8316f5dfaedea1b81746f97..3528a0bea1d27896c28e35c94960a9cf10fa1034 100644 --- a/wasm/single.go +++ b/wasm/single.go @@ -72,7 +72,7 @@ func TransmitSingleUse(_ js.Value, args []js.Value) any { // Returns: // - Javascript representation of the [Stopper] object, an interface // containing a function used to stop the listener. -// - Throws a TypeError if listening fails. +// - Throws an error 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) diff --git a/wasm/ud.go b/wasm/ud.go index 8b69f196b6362c3116551a9f78a0191d549fa571..cce7c8a7fecc09f6690c42de5891b0910ba3d5f2 100644 --- a/wasm/ud.go +++ b/wasm/ud.go @@ -100,7 +100,7 @@ func (uns *udNetworkStatus) UdNetworkStatus() int { // Returns: // - Javascript representation of the [UserDiscovery] object that is // registered to the specified UD service. -// - Throws a TypeError if creating or loading fails. +// - Throws an error if creating or loading fails. func NewOrLoadUd(_ js.Value, args []js.Value) any { e2eID := args[0].Int() follower := &udNetworkStatus{utils.WrapCB(args[1], "UdNetworkStatus")} @@ -146,7 +146,7 @@ func NewOrLoadUd(_ js.Value, args []js.Value) any { // Returns: // - Javascript representation of the [UserDiscovery] object that is loaded // from backup. -// - Throws a TypeError if getting UD from backup fails. +// - Throws an error 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")} diff --git a/wasm/version.go b/wasm/version.go index ca70bcbb150125aa427a271374632b4cef6118d8..048c49b585eb3196d8e1c3926cb87a6c7bf9556e 100644 --- a/wasm/version.go +++ b/wasm/version.go @@ -67,7 +67,7 @@ type VersionInfo struct { // // Returns: // - JSON of [VersionInfo] (Uint8Array). -// - Throws a TypeError if getting the version failed. +// - Throws an error if getting the version failed. func GetWasmSemanticVersion(js.Value, []js.Value) any { vi := VersionInfo{ Current: storage.SEMVER, @@ -92,7 +92,7 @@ func GetWasmSemanticVersion(js.Value, []js.Value) any { // // Returns: // - JSON of [VersionInfo] (Uint8Array). -// - Throws a TypeError if getting the version failed. +// - Throws an error if getting the version failed. func GetXXDKSemanticVersion(js.Value, []js.Value) any { vi := VersionInfo{ Current: bindings.GetVersion(),