import (
"crypto/ed25519"
"encoding/hex"
"encoding/json"
"time"
)
// Sign generates an Ed25519 signature for the message.
// seedHex is your 64-character hex-encoded private key seed.
func Sign(seedHex string, message []byte) (string, error) {
seed, err := hex.DecodeString(seedHex)
if err != nil {
return "", err
}
privateKey := ed25519.NewKeyFromSeed(seed)
signature := ed25519.Sign(privateKey, message)
return hex.EncodeToString(signature), nil
}
func main() {
// 1. Your Ed25519 private key seed (64 hex characters)
seed := "your_ed25519_private_key_hex_string_keep_this_secret"
// 2. Construct the exact same JSON body
message, _ := json.Marshal(map[string]interface{}{
"secret_id": "your-order-id-123",
"nonce": time.Now().UnixMilli(),
"amount": 100.50,
"currency": "USD",
"sender": "user_775",
"reciever": "merchant_A",
"callback_url": "[https://yourdomain.com/payment-success](https://yourdomain.com/payment-success)",
"forward_url": "[https://yourdomain.com/payment-failure](https://yourdomain.com/payment-failure)",
"meta_data": map[string]interface{}{
"order_id": "20231101123456",
"description": "VIP Subscription",
},
})
// 3. Sign the message
signature, err := Sign(seed, message)
if err != nil {
panic(err)
}
// 4. Use this signature in your x-signature header
// fmt.Println(signature)
}