fix: compilation issues
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package ed25519
|
package ed25519
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
@@ -10,6 +11,8 @@ import (
|
|||||||
"golang.org/x/crypto/blake2b"
|
"golang.org/x/crypto/blake2b"
|
||||||
|
|
||||||
"github.com/block-vision/sui-go-sdk/constant"
|
"github.com/block-vision/sui-go-sdk/constant"
|
||||||
|
"github.com/block-vision/sui-go-sdk/models"
|
||||||
|
"github.com/block-vision/sui-go-sdk/mystenbcs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ed25519PublicKey struct {
|
type Ed25519PublicKey struct {
|
||||||
@@ -23,19 +26,26 @@ func NewEd25519PublicKey(signature []byte) *Ed25519PublicKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Ed25519PublicKey) ToSuiAddress() string {
|
func (e *Ed25519PublicKey) ToSuiAddress() string {
|
||||||
return ""
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Ed25519PublicKey) VerifyPersonalMessage(message []byte, signature []byte, client *graphql.Client) (bool, error) {
|
func (e *Ed25519PublicKey) VerifyPersonalMessage(message []byte, signature []byte, client *graphql.Client) (bool, error) {
|
||||||
b64Message := base64.StdEncoding.EncodeToString([]byte(message))
|
b64Message := base64.StdEncoding.EncodeToString([]byte(message))
|
||||||
return VerifyMessage(b64Message, signature, constant.PersonalMessageIntentScope)
|
b64Signature := base64.StdEncoding.EncodeToString([]byte(signature))
|
||||||
|
_, pass, err := VerifyMessage(b64Message, b64Signature, constant.PersonalMessageIntentScope)
|
||||||
|
return pass, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func VerifyMessage(message, signature string, scope constant.IntentScope) (signer string, pass bool, err error) {
|
func VerifyMessage(message, signature string, scope constant.IntentScope) (signer string, pass bool, err error) {
|
||||||
b64Bytes, _ := base64.StdEncoding.DecodeString(message)
|
b64Bytes, _ := base64.StdEncoding.DecodeString(message)
|
||||||
messageBytes := NewMessageWithIntent(b64Bytes, scope)
|
|
||||||
|
|
||||||
serializedSignature, err := FromSerializedSignature(signature)
|
bcsEncodedMsg := bytes.Buffer{}
|
||||||
|
bcsEncoder := mystenbcs.NewEncoder(&bcsEncodedMsg)
|
||||||
|
bcsEncoder.Encode(b64Bytes)
|
||||||
|
|
||||||
|
messageBytes := models.NewMessageWithIntent(bcsEncodedMsg.Bytes(), scope)
|
||||||
|
|
||||||
|
serializedSignature, err := models.FromSerializedSignature(signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
@@ -52,7 +62,7 @@ func VerifyMessage(message, signature string, scope constant.IntentScope) (signe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Ed25519PublicKeyToSuiAddress(pubKey []byte) string {
|
func Ed25519PublicKeyToSuiAddress(pubKey []byte) string {
|
||||||
newPubkey := []byte{byte(SigFlagEd25519)}
|
newPubkey := []byte{byte(models.SigFlagEd25519)}
|
||||||
newPubkey = append(newPubkey, pubKey...)
|
newPubkey = append(newPubkey, pubKey...)
|
||||||
|
|
||||||
addrBytes := blake2b.Sum256(newPubkey)
|
addrBytes := blake2b.Sum256(newPubkey)
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ type ZkLoginPublicIdentifier struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewZkLoginPublicIdentifier(data []byte, options *ZkLoginPublicIdentifierOptions) *ZkLoginPublicIdentifier {
|
func NewZkLoginPublicIdentifier(data []byte, options *ZkLoginPublicIdentifierOptions) *ZkLoginPublicIdentifier {
|
||||||
return &ZkLoginPublicIdentifier{
|
panic("not implemented")
|
||||||
data: data,
|
|
||||||
options: options,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +41,7 @@ func (p *ZkLoginPublicIdentifier) toRawBytes() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ZkLoginPublicIdentifier) ToSuiAddress() string {
|
func (p *ZkLoginPublicIdentifier) ToSuiAddress() string {
|
||||||
|
panic("not implemented")
|
||||||
|
|
||||||
// Each hex char represents half a byte, hence hex address doubles the length
|
// Each hex char represents half a byte, hence hex address doubles the length
|
||||||
// return normalizeSuiAddress(
|
// return normalizeSuiAddress(
|
||||||
@@ -51,7 +49,7 @@ func (p *ZkLoginPublicIdentifier) ToSuiAddress() string {
|
|||||||
// );
|
// );
|
||||||
|
|
||||||
// Convert the public identifier to a Sui address
|
// Convert the public identifier to a Sui address
|
||||||
return "0x" + mystenbcs.ToHex(mystenbcs.Blake2b(p.toSuiBytes(), 32))[:40]
|
// return "0x" + mystenbcs.ToHex(mystenbcs.Blake2b(p.toSuiBytes(), 32))[:40]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pk *ZkLoginPublicIdentifier) VerifyPersonalMessage(message []byte, signature []byte, client *graphql.Client) (bool, error) {
|
func (pk *ZkLoginPublicIdentifier) VerifyPersonalMessage(message []byte, signature []byte, client *graphql.Client) (bool, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user