Skip to content
Snippets Groups Projects
Commit b514c318 authored by Jono Wenger's avatar Jono Wenger
Browse files

Add ImportPrivateIdentity

parent 9c66e3be
No related branches found
No related tags found
1 merge request!60Revert "Fail a test to be sure it works"
...@@ -7,7 +7,7 @@ require ( ...@@ -7,7 +7,7 @@ require (
github.com/hack-pad/go-indexeddb v0.2.0 github.com/hack-pad/go-indexeddb v0.2.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/spf13/jwalterweatherman v1.1.0 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/crypto v0.0.7-0.20221014161526-ce04e14b9f80
gitlab.com/elixxir/primitives v0.0.3-0.20220901220638-1acc75fabdc6 gitlab.com/elixxir/primitives v0.0.3-0.20220901220638-1acc75fabdc6
gitlab.com/xx_network/crypto v0.0.5-0.20220913213008-98764f5b3287 gitlab.com/xx_network/crypto v0.0.5-0.20220913213008-98764f5b3287
......
...@@ -632,6 +632,8 @@ gitlab.com/elixxir/client v1.5.1-0.20221014161854-3e3de2653aa4 h1:zXEWsMHQ3aQr/8 ...@@ -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.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 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.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 h1:aw7Ao1oqho+97gO35HkzBmv2e25qluRXEiNXw/oD8MM=
gitlab.com/elixxir/comms v0.0.4-0.20221011183106-8c4450ba3cfb/go.mod h1:oRteMH+R5t1j/FZ+KJJnZUcqJO2sLXnWksN5HPkZUIo= 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= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
......
...@@ -50,6 +50,8 @@ func main() { ...@@ -50,6 +50,8 @@ func main() {
// wasm/channels.go // wasm/channels.go
js.Global().Set("GenerateChannelIdentity", js.Global().Set("GenerateChannelIdentity",
js.FuncOf(wasm.GenerateChannelIdentity)) js.FuncOf(wasm.GenerateChannelIdentity))
js.Global().Set("ImportPrivateIdentity",
js.FuncOf(wasm.ImportPrivateIdentity))
js.Global().Set("GetPublicChannelIdentity", js.Global().Set("GetPublicChannelIdentity",
js.FuncOf(wasm.GetPublicChannelIdentity)) js.FuncOf(wasm.GetPublicChannelIdentity))
js.Global().Set("GetPublicChannelIdentityFromPrivate", js.Global().Set("GetPublicChannelIdentityFromPrivate",
......
...@@ -83,6 +83,30 @@ func GenerateChannelIdentity(_ js.Value, args []js.Value) interface{} { ...@@ -83,6 +83,30 @@ func GenerateChannelIdentity(_ js.Value, args []js.Value) interface{} {
pi, err := bindings.GenerateChannelIdentity(args[0].Int()) pi, err := bindings.GenerateChannelIdentity(args[0].Int())
if err != nil { if err != nil {
utils.Throw(utils.TypeError, err) 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) return utils.CopyBytesToJS(pi)
...@@ -103,6 +127,7 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} { ...@@ -103,6 +127,7 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} {
pi, err := bindings.GetPublicChannelIdentity(marshaledPublic) pi, err := bindings.GetPublicChannelIdentity(marshaledPublic)
if err != nil { if err != nil {
utils.Throw(utils.TypeError, err) utils.Throw(utils.TypeError, err)
return nil
} }
return utils.CopyBytesToJS(pi) return utils.CopyBytesToJS(pi)
...@@ -122,10 +147,11 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} { ...@@ -122,10 +147,11 @@ func GetPublicChannelIdentity(_ js.Value, args []js.Value) interface{} {
// fails. // fails.
func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) interface{} { func GetPublicChannelIdentityFromPrivate(_ js.Value, args []js.Value) interface{} {
marshaledPrivate := utils.CopyBytesToGo(args[0]) marshaledPrivate := utils.CopyBytesToGo(args[0])
identity, err := bindings.GetPublicChannelIdentityFromPrivate( identity, err :=
marshaledPrivate) bindings.GetPublicChannelIdentityFromPrivate(marshaledPrivate)
if err != nil { if err != nil {
utils.Throw(utils.TypeError, err) utils.Throw(utils.TypeError, err)
return nil
} }
return utils.CopyBytesToJS(identity) return utils.CopyBytesToJS(identity)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment