Comments (1)
I'm not familiar with the Cosmos SDK, but looking at the github repo, I do see it listed as a direct dependency in their go.mod
, so it appears that it does use it.
For your question, it depends on what format the private key string is in. Assuming it's just the hex-encoded bytes of the private key and is already known to be good, you'd just do the typical hex.DecodeString
to decode the string into raw bytes and then call secp256k1.PrivKeyFromBytes
to convert it to a private key that you can then convert to a public key via the PubKey
method it exposes. From there, you have the public key and can serialize it if you want or otherwise use it however your want.
There is an example in the secp256k1/ecdsa
package of doing decoding a hard-coded private key string, using it to sign a message, getting the public key for it, and then verifying the signature+message with the public key:
https://pkg.go.dev/github.com/decred/dcrd/dcrec/secp256k1/[email protected]/ecdsa#example-Sign
Here is a trivial example that does only what you asked and then prints out the serialized compressed public key:
package main
import (
"encoding/hex"
"fmt"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
func main() {
privKeyString := "0000000000000000000000000000000000000000000000000000000000000001"
privKeyBytes, err := hex.DecodeString(privKeyString)
if err != nil {
fmt.Println(err)
return
}
privKey := secp256k1.PrivKeyFromBytes(privKeyBytes)
pubKey := privKey.PubKey()
fmt.Printf("Serialized Public Key: %x\n", pubKey.SerializeCompressed())
}
Output:
Serialized Public Key: 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
from dcrd.
Related Issues (20)
- using dcrec/secp256k1 with ethereum keys HOT 6
- code example please for signing ethereum transactions HOT 8
- Panic on notifying index subscribers (release 1.7.1) HOT 6
- testnet: Panic when running with address index on. HOT 4
- websocket: read limit exceeded HOT 11
- Is there an error in the secp256k1 example? HOT 12
- Remove planetdecred seeders from dcrd HOT 1
- dcrec/secp256k1: new release to fix boringcrypto issue HOT 2
- Add IPC (pipetx) events to report listening ports HOT 5
- The main dcrd module needs new tag with 1.8.0 release.
- Feature Request: Allow forcing a vote result in network parameters.
- Remove need for invalid choice index sentinal form threshold state tuple.
- Re-enable RPC integration tests one #3092 is merged.
- Serializing Signature not compatible with other lib HOT 10
- [rpcserver] getcoinsupply RPC is not reporting treasurybases
- Unable to override home directory HOT 19
- DCR explorer and my dcr nodes do not produce new block from Aug 30th till now HOT 2
- Template generator includes tspend that overspends treasury
- Request to change r and s in secp256k1 ecdsa signature to exported variable R and S HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dcrd.