-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: extend the maximum number of characters that can be decoded to 200 characters #159
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb1bca9
feat: move into tendermint/tendermint/libs/bech32/bech32plus.go from …
Kynea0b c8120db
feat: add LIMIT for decode to bech32plus and call this in bech32.go
Kynea0b c8f8c44
fix: change bytes-codec to amino-codec
Kynea0b 0f2a0a3
feat: add composite key and bls key encode test
Kynea0b 2dcd9df
feat: add genesis_test.go using composite pub_key
Kynea0b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,21 +1,38 @@ | ||
package composite | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/tendermint/go-amino" | ||
"github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/crypto/bls" | ||
"github.com/tendermint/tendermint/crypto/ed25519" | ||
"github.com/tendermint/tendermint/crypto/tmhash" | ||
) | ||
|
||
// PubKeyComposite and PrivKeyComposite are intended to allow public key algorithms to be selected for each function. | ||
|
||
const ( | ||
PubKeyCompositeAminoName = "tendermint/PubKeyComposite" | ||
PrivKeyCompositeAminoName = "tendermint/PrivKeyComposite" | ||
PrivKeyAminoName = "tendermint/PrivKeyComposite" | ||
PubKeyAminoName = "tendermint/PubKeyComposite" | ||
) | ||
|
||
var cdc = amino.NewCodec() | ||
|
||
func init() { | ||
cdc.RegisterInterface((*crypto.PubKey)(nil), nil) | ||
cdc.RegisterConcrete(PubKeyComposite{}, | ||
PubKeyAminoName, nil) | ||
cdc.RegisterConcrete(bls.PubKeyBLS12{}, | ||
bls.PubKeyAminoName, nil) | ||
cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, | ||
ed25519.PubKeyAminoName, nil) | ||
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) | ||
cdc.RegisterConcrete(PrivKeyComposite{}, | ||
PrivKeyAminoName, nil) | ||
cdc.RegisterConcrete(bls.PrivKeyBLS12{}, | ||
bls.PrivKeyAminoName, nil) | ||
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{}, | ||
ed25519.PrivKeyAminoName, nil) | ||
} | ||
|
||
type PubKeyComposite struct { | ||
SignKey crypto.PubKey `json:"sign"` | ||
VrfKey crypto.PubKey `json:"vrf"` | ||
|
@@ -30,9 +47,11 @@ func (pk PubKeyComposite) Address() crypto.Address { | |
} | ||
|
||
func (pk PubKeyComposite) Bytes() []byte { | ||
msg := bytes.NewBuffer(pk.SignKey.Bytes()) | ||
msg.Write(pk.VrfKey.Bytes()) | ||
return msg.Bytes() | ||
bz, err := cdc.MarshalBinaryBare(pk) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return bz | ||
} | ||
|
||
func (pk PubKeyComposite) VerifyBytes(msg []byte, sig []byte) bool { | ||
|
@@ -67,7 +86,7 @@ func (sk PrivKeyComposite) Identity() crypto.PrivKey { | |
} | ||
|
||
func (sk PrivKeyComposite) Bytes() []byte { | ||
return sk.Identity().Bytes() | ||
return cdc.MustMarshalBinaryBare(sk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I answered above, the reason is the same as |
||
} | ||
|
||
func (sk PrivKeyComposite) Sign(msg []byte) ([]byte, error) { | ||
|
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using
bytes.NewBuffer
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: https://github.com/line/tendermint/blob/develop/docs/architecture/adr-015-crypto-encoding.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. It was used to identify it as a unique value as a [] byte array inside tendermint. However, according to the specifications of tendermint, it seems correct to use amino encoding.