@@ -20,7 +20,6 @@ package solana
2020import (
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
153153type 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+
155160func (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
160164type 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.
689686func 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
0 commit comments