-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") | ||
} | ||
} |