Skip to content

Commit

Permalink
feat: add Ed25519SigVerify instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
gyllone committed Mar 6, 2024
1 parent 7975a21 commit 4e9be1d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions programs/ed25519-sig-verify/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ProgramName = "Ed25519SigVerify"

type Instruction struct {
Signer solana.PublicKey
Signature [64]byte
Signature solana.Signature
Message []byte
}

Expand Down Expand Up @@ -57,17 +57,29 @@ func (inst *Instruction) Data() ([]byte, error) {
data = binary.LittleEndian.AppendUint16(data, uint16(len(inst.Message)))
data = binary.LittleEndian.AppendUint16(data, math.MaxUint16)

data = append(data, inst.Signer.Bytes()...)
data = append(data, inst.Signer[:]...)
data = append(data, inst.Signature[:]...)
data = append(data, inst.Message...)

return data, nil
}

func NewEd25519VerifySigInstruction(signer solana.PublicKey, sig [64]byte, msg []byte) *Instruction {
func NewEd25519SigVerifyInstruction(signer solana.PublicKey, sig solana.Signature, msg []byte) *Instruction {
return &Instruction{
Signer: signer,
Signature: sig,
Message: msg,
}
}

func NewEd25519SigVerifyInstructionWithWallet(signer *solana.Wallet, msg []byte) (*Instruction, error) {
sig, err := signer.PrivateKey.Sign(msg)
if err != nil {
return nil, err
}
return &Instruction{
Signer: signer.PublicKey(),
Signature: sig,
Message: msg,
}, nil
}

0 comments on commit 4e9be1d

Please sign in to comment.