mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
parent
7e3de2027e
commit
3e1baf68f8
@ -1,6 +1,6 @@
|
||||
# go-crypto
|
||||
# crypto
|
||||
|
||||
go-crypto is the cryptographic package adapted for Tendermint's uses
|
||||
crypto is the cryptographic package adapted for Tendermint's uses
|
||||
|
||||
## Importing it
|
||||
`import "github.com/tendermint/tendermint/crypto"`
|
||||
@ -11,7 +11,7 @@ For Binary encoding, please refer to the [Tendermint encoding spec](https://gith
|
||||
|
||||
## JSON Encoding
|
||||
|
||||
go-crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.
|
||||
crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported.
|
||||
|
||||
```go
|
||||
Example Amino:JSON encodings:
|
||||
|
@ -15,7 +15,7 @@ func init() {
|
||||
RegisterAmino(cdc)
|
||||
}
|
||||
|
||||
// RegisterAmino registers all go-crypto related types in the given (amino) codec.
|
||||
// RegisterAmino registers all crypto related types in the given (amino) codec.
|
||||
func RegisterAmino(cdc *amino.Codec) {
|
||||
cdc.RegisterInterface((*PubKey)(nil), nil)
|
||||
cdc.RegisterConcrete(PubKeyEd25519{},
|
||||
|
@ -1,48 +1,45 @@
|
||||
/*
|
||||
go-crypto is a customized/convenience cryptography package
|
||||
for supporting Tendermint.
|
||||
// crypto is a customized/convenience cryptography package for supporting
|
||||
// Tendermint.
|
||||
|
||||
It wraps select functionality of equivalent functions in the
|
||||
Go standard library, for easy usage with our libraries.
|
||||
// It wraps select functionality of equivalent functions in the
|
||||
// Go standard library, for easy usage with our libraries.
|
||||
|
||||
Keys:
|
||||
// Keys:
|
||||
|
||||
All key generation functions return an instance of the PrivKey interface
|
||||
which implements methods
|
||||
// All key generation functions return an instance of the PrivKey interface
|
||||
// which implements methods
|
||||
|
||||
AssertIsPrivKeyInner()
|
||||
Bytes() []byte
|
||||
Sign(msg []byte) Signature
|
||||
PubKey() PubKey
|
||||
Equals(PrivKey) bool
|
||||
Wrap() PrivKey
|
||||
// AssertIsPrivKeyInner()
|
||||
// Bytes() []byte
|
||||
// Sign(msg []byte) Signature
|
||||
// PubKey() PubKey
|
||||
// Equals(PrivKey) bool
|
||||
// Wrap() PrivKey
|
||||
|
||||
From the above method we can:
|
||||
a) Retrieve the public key if needed
|
||||
// From the above method we can:
|
||||
// a) Retrieve the public key if needed
|
||||
|
||||
pubKey := key.PubKey()
|
||||
// pubKey := key.PubKey()
|
||||
|
||||
For example:
|
||||
privKey, err := crypto.GenPrivKeyEd25519()
|
||||
if err != nil {
|
||||
...
|
||||
}
|
||||
pubKey := privKey.PubKey()
|
||||
...
|
||||
// And then you can use the private and public key
|
||||
doSomething(privKey, pubKey)
|
||||
// For example:
|
||||
// privKey, err := crypto.GenPrivKeyEd25519()
|
||||
// if err != nil {
|
||||
// ...
|
||||
// }
|
||||
// pubKey := privKey.PubKey()
|
||||
// ...
|
||||
// // And then you can use the private and public key
|
||||
// doSomething(privKey, pubKey)
|
||||
|
||||
// We also provide hashing wrappers around algorithms:
|
||||
|
||||
We also provide hashing wrappers around algorithms:
|
||||
// Sha256
|
||||
// sum := crypto.Sha256([]byte("This is Tendermint"))
|
||||
// fmt.Printf("%x\n", sum)
|
||||
|
||||
Sha256
|
||||
sum := crypto.Sha256([]byte("This is Tendermint"))
|
||||
fmt.Printf("%x\n", sum)
|
||||
|
||||
Ripemd160
|
||||
sum := crypto.Ripemd160([]byte("This is consensus"))
|
||||
fmt.Printf("%x\n", sum)
|
||||
*/
|
||||
// Ripemd160
|
||||
// sum := crypto.Ripemd160([]byte("This is consensus"))
|
||||
// fmt.Printf("%x\n", sum)
|
||||
package crypto
|
||||
|
||||
// TODO: Add more docs in here
|
||||
|
@ -28,7 +28,7 @@ func TestReadPrivKey(t *testing.T) {
|
||||
|
||||
// garbage in, garbage out
|
||||
garbage := []byte("hjgewugfbiewgofwgewr")
|
||||
XXX This test wants to register BadKey globally to go-crypto,
|
||||
XXX This test wants to register BadKey globally to crypto,
|
||||
but we don't want to support that.
|
||||
_, err := PrivKeyFromBytes(garbage)
|
||||
require.Error(err)
|
||||
|
@ -7,7 +7,7 @@ For details on peer discovery, see the [peer exchange (PEX) reactor doc](https:/
|
||||
## Peer Identity
|
||||
|
||||
Tendermint peers are expected to maintain long-term persistent identities in the form of a public key.
|
||||
Each peer has an ID defined as `peer.ID == peer.PubKey.Address()`, where `Address` uses the scheme defined in go-crypto.
|
||||
Each peer has an ID defined as `peer.ID == peer.PubKey.Address()`, where `Address` uses the scheme defined in `crypto` package.
|
||||
|
||||
A single peer ID can have multiple IP addresses associated with it, but a node
|
||||
will only ever connect to one at a time.
|
||||
|
@ -58,7 +58,7 @@ func (tm2pb) Validator(val *Validator) abci.Validator {
|
||||
}
|
||||
|
||||
// XXX: panics on nil or unknown pubkey type
|
||||
// TODO: add cases when new pubkey types are added to go-crypto
|
||||
// TODO: add cases when new pubkey types are added to crypto
|
||||
func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey {
|
||||
switch pk := pubKey.(type) {
|
||||
case crypto.PubKeyEd25519:
|
||||
@ -153,7 +153,7 @@ var PB2TM = pb2tm{}
|
||||
type pb2tm struct{}
|
||||
|
||||
func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
|
||||
// TODO: define these in go-crypto and use them
|
||||
// TODO: define these in crypto and use them
|
||||
sizeEd := 32
|
||||
sizeSecp := 33
|
||||
switch pubKey.Type {
|
||||
|
Loading…
x
Reference in New Issue
Block a user