Skip to content

Commit

Permalink
feat: algorand public key encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
robdefeo committed Feb 20, 2021
1 parent b5027e9 commit 611a172
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/pubkey/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
// EncodeByProtocol selects the correct encoding method, then encodes the public key with it.
func EncodeByProtocol(in []byte, protocol string) (encoded, encodingType string, err error) {
switch protocol {
case protocols.Algorand:
encodingType = encoding.KindBase32
encoded = encoding.EncodeBase32(in)
case protocols.Ethereum:
encodingType = encoding.KindHex0XPrefix
encoded = encoding.EncodeHexZeroX(in)
Expand Down
11 changes: 11 additions & 0 deletions internal/pubkey/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pubkey
import (
"testing"

"github.com/mailchain/mailchain/crypto/ed25519/ed25519test"
"github.com/mailchain/mailchain/encoding"
"github.com/mailchain/mailchain/encoding/encodingtest"
)
Expand All @@ -33,6 +34,16 @@ func TestEncodeByProtocol(t *testing.T) {
wantEncodingType string
wantErr bool
}{
{
"algorand",
args{
ed25519test.SofiaPublicKey.Bytes(),
"algorand",
},
"OI6KUI5FWUI26WWXW7XWA5XECSVX45NJ3SIQ5JQOIF5CW5YKKZYQ",
encoding.KindBase32,
false,
},
{
"ethereum",
args{
Expand Down

0 comments on commit 611a172

Please sign in to comment.