Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support crypto/ed25519.Verify #1863

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/reference/go-gno-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Legend:
| crypto/dsa | `tbd` |
| crypto/ecdh | `tbd` |
| crypto/ecdsa | `tbd` |
| crypto/ed25519 | `tbd` |
| crypto/ed25519 | `part`[^8] |
| crypto/elliptic | `tbd` |
| crypto/hmac | `todo` |
| crypto/md5 | `test`[^2] |
Expand Down Expand Up @@ -289,6 +289,8 @@ Legend:
bit of boilerplate, but you can use `sort.Interface` + `sort.Sort`!
[^7]: `time.Now` returns the block time rather than the system time, for
determinism. Concurrent functionality (such as `time.Ticker`) is not implemented.
[^8]: `crypto/ed25519` is currently only implemented for `Verify`, which should
still cover a majority of use cases. A full implementation is welcome.

## Tooling (`gno` binary)

Expand Down
8 changes: 8 additions & 0 deletions gnovm/stdlibs/crypto/ed25519/ed25519.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ed25519

// Verify returns true if the signature is valid for the message and public key.
func VerifyED25519(publicKey []byte, message []byte, signature []byte) bool {
return verifyED25519(publicKey, message, signature)
}

func verifyED25519(publicKey []byte, message []byte, signature []byte) bool // injected
thehowl marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions gnovm/stdlibs/crypto/ed25519/ed25519.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ed25519

import (
"crypto/ed25519"
)

func X_verifyED25519(publicKey []byte, message []byte, signature []byte) bool {
return ed25519.Verify(publicKey, message, signature)
}
16 changes: 16 additions & 0 deletions gnovm/stdlibs/crypto/ed25519/ed25519_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ed25519

import (
"crypto/ed25519"
"encoding/hex"
"std"
"testing"
)

func TestVerifyED25519(t *testing.T) {
publicKey, _ := hex.DecodeString("0D853FA898A07EB91F618BB3E8B738B0E45BE9B3053799A2C42F8204F5FA3505")
signature, _ := hex.DecodeString("2B39638983858715AD2FA059665ADFE267936B8F20C4DA01E9650958E0CA65C0255C75164360F468087FE8385140E48EE3471E332472A50AEE599F9D0EADD106")
if !ed25519.VerifyED25519(publicKey, []byte("hello gno.land"), signature) {
t.Error("verify failed")
}
}
36 changes: 36 additions & 0 deletions gnovm/stdlibs/native.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading