Skip to content

Commit 34eb841

Browse files
committed
init
1 parent 828ac78 commit 34eb841

4 files changed

Lines changed: 18 additions & 28 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/gagliardetto/treeout v0.1.4
99
github.com/google/uuid v1.6.0
1010
github.com/mr-tron/base58 v1.2.0
11+
github.com/oasisprotocol/curve25519-voi v0.0.0-20251114093237-2ab5a27a1729
1112
go.mongodb.org/mongo-driver/v2 v2.5.0
1213
)
1314

@@ -59,7 +60,6 @@ require (
5960
)
6061

6162
require (
62-
filippo.io/edwards25519 v1.2.0
6363
github.com/AlekSi/pointer v1.2.0
6464
github.com/buger/jsonparser v1.1.2
6565
github.com/davecgh/go-spew v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIi
44
cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c=
55
cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=
66
cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
7-
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
8-
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
97
github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
108
github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0=
119
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
@@ -105,6 +103,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
105103
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
106104
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
107105
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
106+
github.com/oasisprotocol/curve25519-voi v0.0.0-20251114093237-2ab5a27a1729 h1:yfQ2sO9WJXUAIUR+g7NUkxJSKCAFJcR5sUDu+ZmjTZI=
107+
github.com/oasisprotocol/curve25519-voi v0.0.0-20251114093237-2ab5a27a1729/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
108108
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
109109
github.com/onsi/ginkgo v1.12.1 h1:mFwc4LvZ0xpSvDZ3E+k8Yte0hLOMxXUlP+yXtJqkYfQ=
110110
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=

keys.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package solana
2020
import (
2121
"bytes"
2222
"crypto"
23-
"crypto/ed25519"
2423
crypto_rand "crypto/rand"
2524
"crypto/sha256"
2625
"errors"
@@ -29,9 +28,10 @@ import (
2928
"os"
3029
"sort"
3130

32-
"filippo.io/edwards25519/field"
3331
"github.com/gagliardetto/solana-go/base58"
3432
mrtronbase58 "github.com/mr-tron/base58"
33+
"github.com/oasisprotocol/curve25519-voi/curve"
34+
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
3535
"go.mongodb.org/mongo-driver/v2/bson"
3636
)
3737

@@ -152,9 +152,13 @@ func (k PrivateKey) PublicKey() PublicKey {
152152
// PK is a convenience alias for PublicKey
153153
type PK = PublicKey
154154

155+
// done to keep verify the same as stdlib crypto/ed25519
156+
var verifyOptsStdLib = &ed25519.Options{
157+
Verify: ed25519.VerifyOptionsStdLib,
158+
}
159+
155160
func (p PublicKey) Verify(message []byte, signature Signature) bool {
156-
pub := ed25519.PublicKey(p[:])
157-
return ed25519.Verify(pub, message, signature[:])
161+
return ed25519.VerifyWithOptions(p[:], message, signature[:], verifyOptsStdLib)
158162
}
159163

160164
type PublicKey [PublicKeyLength]byte
@@ -678,32 +682,17 @@ func CreateProgramAddress(seeds [][]byte, programID PublicKey) (PublicKey, error
678682
return PublicKeyFromBytes(hash[:]), nil
679683
}
680684

681-
var feOne = new(field.Element).One()
682-
var d, _ = new(field.Element).SetBytes([]byte{
683-
0xa3, 0x78, 0x59, 0x13, 0xca, 0x4d, 0xeb, 0x75,
684-
0xab, 0xd8, 0x41, 0x41, 0x4d, 0x0a, 0x70, 0x00,
685-
0x98, 0xe8, 0x79, 0x77, 0x79, 0x40, 0xc7, 0x8c,
686-
0x73, 0xfe, 0x6f, 0x2b, 0xee, 0x6c, 0x03, 0x52})
687-
688685
// Check if the provided `b` is on the ed25519 curve.
689686
func IsOnCurve(b []byte) bool {
690687
if len(b) != ed25519.PublicKeySize {
691688
return false
692689
}
693-
//_, err := new(edwards25519.Point).SetBytes(b)
694-
y, err := new(field.Element).SetBytes(b)
695-
if err != nil {
690+
var compressed curve.CompressedEdwardsY
691+
if _, err := compressed.SetBytes(b); err != nil {
696692
return false
697693
}
698-
699-
y2 := new(field.Element).Square(y)
700-
u := new(field.Element).Subtract(y2, feOne)
701-
702-
vv := new(field.Element).Multiply(y2, d)
703-
vv = vv.Add(vv, feOne)
704-
705-
_, wasSquare := new(field.Element).SqrtRatio(u, vv)
706-
if wasSquare == 0 {
694+
var p curve.EdwardsPoint
695+
if _, err := p.SetCompressedY(&compressed); err != nil {
707696
return false
708697
}
709698
return true

nativetypes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
package solana
1919

2020
import (
21-
"crypto/ed25519"
2221
"encoding/base64"
2322
"fmt"
2423
"io"
2524

25+
"github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
26+
2627
bin "github.com/gagliardetto/binary"
2728
"github.com/gagliardetto/solana-go/base58"
2829
"github.com/mostynb/zstdpool-freelist"
@@ -186,7 +187,7 @@ func (p *Signature) UnmarshalJSON(data []byte) (err error) {
186187

187188
// Verify checks that the signature is valid for the given public key and message.
188189
func (s Signature) Verify(pubkey PublicKey, msg []byte) bool {
189-
return ed25519.Verify(pubkey[:], msg, s[:])
190+
return ed25519.VerifyWithOptions(pubkey[:], msg, s[:], verifyOptsStdLib)
190191
}
191192

192193
func (p Signature) String() string {

0 commit comments

Comments
 (0)