diff --git a/go.mod b/go.mod index 081543d7535c7406c3207ae52320278e23f235fa..88d37252249a29661e461fead049d65482d36e83 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hack-pad/go-indexeddb v0.2.0 github.com/pkg/errors v0.9.1 github.com/spf13/jwalterweatherman v1.1.0 - gitlab.com/elixxir/client v1.5.1-0.20221014170508-d65477656611 + gitlab.com/elixxir/client v1.5.1-0.20221014182132-0a0ce8f77375 gitlab.com/elixxir/crypto v0.0.7-0.20221014161526-ce04e14b9f80 gitlab.com/elixxir/primitives v0.0.3-0.20220901220638-1acc75fabdc6 gitlab.com/xx_network/crypto v0.0.5-0.20220913213008-98764f5b3287 diff --git a/go.sum b/go.sum index 370f2f027eb5a8061ae146078970d9687590aa5d..d655884b52cf9afee65a2cb536730db57d667627 100644 --- a/go.sum +++ b/go.sum @@ -632,6 +632,8 @@ gitlab.com/elixxir/client v1.5.1-0.20221014161854-3e3de2653aa4 h1:zXEWsMHQ3aQr/8 gitlab.com/elixxir/client v1.5.1-0.20221014161854-3e3de2653aa4/go.mod h1:oSbLC/5yibV2zZk9iI6Cm8F44+I80fQfP6qw9QaGaeI= gitlab.com/elixxir/client v1.5.1-0.20221014170508-d65477656611 h1:aZc2X7dDfjfxVuhZYXrICpyl09jkvnrVvekZaO8y4es= gitlab.com/elixxir/client v1.5.1-0.20221014170508-d65477656611/go.mod h1:oSbLC/5yibV2zZk9iI6Cm8F44+I80fQfP6qw9QaGaeI= +gitlab.com/elixxir/client v1.5.1-0.20221014182132-0a0ce8f77375 h1:QQz79TDy3gZP7WeiQG+VZf54mKoqwmarhqICfSqJDx0= +gitlab.com/elixxir/client v1.5.1-0.20221014182132-0a0ce8f77375/go.mod h1:oSbLC/5yibV2zZk9iI6Cm8F44+I80fQfP6qw9QaGaeI= gitlab.com/elixxir/comms v0.0.4-0.20221011183106-8c4450ba3cfb h1:aw7Ao1oqho+97gO35HkzBmv2e25qluRXEiNXw/oD8MM= gitlab.com/elixxir/comms v0.0.4-0.20221011183106-8c4450ba3cfb/go.mod h1:oRteMH+R5t1j/FZ+KJJnZUcqJO2sLXnWksN5HPkZUIo= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= diff --git a/main.go b/main.go index 79d522f7deabcf8c8f731ac5fb2356b0020e78fc..3781c8d86f187be23d4a15610809eef02109b6ff 100644 --- a/main.go +++ b/main.go @@ -50,6 +50,8 @@ func main() { // wasm/channels.go js.Global().Set("GenerateChannelIdentity", js.FuncOf(wasm.GenerateChannelIdentity)) + js.Global().Set("ImportPrivateIdentity", + js.FuncOf(wasm.ImportPrivateIdentity)) js.Global().Set("GetPublicChannelIdentity", js.FuncOf(wasm.GetPublicChannelIdentity)) js.Global().Set("GetPublicChannelIdentityFromPrivate", diff --git a/wasm/channels.go b/wasm/channels.go index 401bec7ad72c767715758216c63d325b59ea1edf..951e36dc3ece27fd5310216a2f1ccfec71b4b62f 100644 --- a/wasm/channels.go +++ b/wasm/channels.go @@ -83,6 +83,30 @@ func GenerateChannelIdentity(_ js.Value, args []js.Value) interface{} { pi, err := bindings.GenerateChannelIdentity(args[0].Int()) if err != nil { utils.Throw(utils.TypeError, err) + return nil + } + + return utils.CopyBytesToJS(pi) +} + +// ImportPrivateIdentity generates a new [channel.PrivateIdentity] from exported +// data. +// +// Parameters: +// - 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{} { + password := args[0].String() + data := utils.CopyBytesToGo(args[1]) + + pi, err := bindings.ImportPrivateIdentity(password, data) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil } return utils.CopyBytesToJS(pi) @@ -103,6 +127,7 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} { pi, err := bindings.GetPublicChannelIdentity(marshaledPublic) if err != nil { utils.Throw(utils.TypeError, err) + return nil } return utils.CopyBytesToJS(pi) @@ -122,10 +147,11 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} { // fails. func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) interface{} { marshaledPrivate := utils.CopyBytesToGo(args[0]) - identity, err := bindings.GetPublicChannelIdentityFromPrivate( - marshaledPrivate) + identity, err := + bindings.GetPublicChannelIdentityFromPrivate(marshaledPrivate) if err != nil { utils.Throw(utils.TypeError, err) + return nil } return utils.CopyBytesToJS(identity)