Skip to content

Commit

Permalink
Added basic examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Sep 30, 2020
1 parent dbd5bc3 commit fdc1d8a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/sign_message/sign_message.go
Original file line number Diff line number Diff line change
@@ -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)
}
28 changes: 28 additions & 0 deletions examples/verify_signature/verify_signature.go
Original file line number Diff line number Diff line change
@@ -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!")
}
}

0 comments on commit fdc1d8a

Please sign in to comment.