-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from hypersign-protocol/cosmos-blockchain-add…
…r-support feat: support for Cosmos Ecosystem based wallet addresses in Verification Methods + verification Method Type condition rearrangements
- Loading branch information
Showing
14 changed files
with
605 additions
and
91 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
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,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
|
||
"golang.org/x/crypto/ripemd160" //nolint: staticcheck | ||
|
||
bech32 "github.com/cosmos/cosmos-sdk/types/bech32" | ||
) | ||
|
||
// publicKeyToBech32Address converts publicKey byteArray to Bech32 encoded blockchain address | ||
func publicKeyToBech32Address(addressPrefix string, pubKeyBytes []byte) string { | ||
// Throw error if the length of secp256k1 publicKey is not 33 | ||
if len(pubKeyBytes) != 33 { | ||
panic(fmt.Sprintf("invalid secp256k1 public key length %v", len(pubKeyBytes))) | ||
} | ||
|
||
// Hash pubKeyBytes as: RIPEMD160(SHA256(public_key_bytes)) | ||
pubKeySha256Hash := sha256.Sum256(pubKeyBytes) | ||
ripemd160hash := ripemd160.New() | ||
ripemd160hash.Write(pubKeySha256Hash[:]) | ||
addressBytes := ripemd160hash.Sum(nil) | ||
|
||
// Convert addressBytes to bech32 encoded address | ||
address, err := bech32.ConvertAndEncode(addressPrefix, addressBytes) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return address | ||
} |
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.