Closed
Description
This one is a bit disturbing. I have got a very simple script that works perfectly on node but not on the browser.
package main
import (
"crypto/ed25519"
"encoding/base64"
"github.com/gopherjs/gopherjs/js"
)
func SignMessage(secBase64, pubBase64, displayedName, message, messageId string) string {
sec, err := base64.URLEncoding.DecodeString(secBase64)
if err != nil || len(sec) != ed25519.PrivateKeySize {
return ""
}
pub, err := base64.URLEncoding.DecodeString(pubBase64)
if err != nil {
return ""
}
msgToSign := append([]byte(message), pub...)
msgToSign = append(msgToSign, []byte(displayedName)...)
msgToSign = append(msgToSign, []byte(messageId)...)
signature := ed25519.Sign(sec, msgToSign)
return base64.URLEncoding.EncodeToString(signature)
}
func main() {
js.Module.Get("exports").Set("SignMessage", SignMessage)
}
You can easily reproduce it with gopherjs build -o lib.js
and this small html file:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script src="./lib.js"></script>
</head>
<body>
Test
<script>
console.log(SignMessage("test", "test", "test", "test", ""));
</script>
</body>
</html>
Metadata
Metadata
Assignees
Labels
No labels