diff --git a/examples/sign_message/sign_message.go b/examples/sign_message/sign_message.go new file mode 100644 index 0000000..63bca2f --- /dev/null +++ b/examples/sign_message/sign_message.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/bitcoinschema/go-bitcoin" +) + +func main() { + // Create a private key for the example + privateKey, err := bitcoin.CreatePrivateKeyString() + if err != nil { + log.Fatalf("error occurred: %s", err.Error()) + } + + // Sign the message (returning a signature) + var signature string + if signature, err = bitcoin.SignMessage(privateKey, "This is the example message"); err != nil { + log.Fatalf("error occurred: %s", err.Error()) + } + + // Final signature for the given message + log.Printf("private key: %s signature: %s", privateKey, signature) +} diff --git a/examples/verify_signature/verify_signature.go b/examples/verify_signature/verify_signature.go new file mode 100644 index 0000000..d961081 --- /dev/null +++ b/examples/verify_signature/verify_signature.go @@ -0,0 +1,28 @@ +package main + +import ( + "log" + + "github.com/bitcoinschema/go-bitcoin" +) + +func main() { + + // Example values (from sign_message.go) + privateKey := "ac40784f09304a88b8db0cfcaff3a4e7d81b6b6ccdef68fad8ddf853ea1d1dce" + signature := "H/sEz5QDQYkXCox9shPB4MMVAVUM/JzfbPHNpPRwNl+hMI2gxy3x7xs9Ed5ryuny5s2hY4Qxc5uirqjMyEEON6k=" + message := "This is the example message" + + // Get an address from private key + address, err := bitcoin.AddressFromPrivateKey(privateKey) + if err != nil { + log.Fatalf("error occurred: %s", err.Error()) + } + + // Verify the signature + if err = bitcoin.VerifyMessage(address, signature, message); err != nil { + log.Fatalf("verify failed: %s", err.Error()) + } else { + log.Println("verification successful!") + } +}