Skip to content
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: support for Cosmos Ecosystem based wallet addresses in Verification Methods + verification Method Type condition rearrangements #340

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/hid-noded/cmd/debug_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func secp256k1Cmd() *cobra.Command {

cmd.AddCommand(
secp256k1RandomCmd(),
secp256k1Bech32AddressCmd(),
secp256k1EthRandomCmd(),
)

Expand Down Expand Up @@ -79,6 +80,30 @@ func secp256k1RandomCmd() *cobra.Command {
return cmd
}

func secp256k1Bech32AddressCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bech32-addr [base64-encoded-public-key] [prefix]",
Short: "Converts a compressed base64 encoded secp256k1 public key to bech32 address",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
base64PubKey := args[0]
addrPrefix := args[1]

publicKeyBytes, err := base64.StdEncoding.DecodeString(base64PubKey)
if err != nil {
panic(err)
}

bech32address := publicKeyToBech32Address(addrPrefix, publicKeyBytes)

_, err = fmt.Fprintln(cmd.OutOrStdout(), bech32address)
return err
},
}

return cmd
}

func secp256k1EthRandomCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "eth-hex-random",
Expand Down
31 changes: 31 additions & 0 deletions cmd/hid-noded/cmd/debug_extensions_utils.go
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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/tendermint/spm v0.1.9
github.com/tendermint/tendermint v0.34.23
github.com/tendermint/tm-db v0.6.7
golang.org/x/crypto v0.1.0
google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a
google.golang.org/grpc v1.50.1
)
Expand Down Expand Up @@ -115,7 +116,6 @@ require (
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/zondax/hid v0.9.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.5.0 // indirect
Expand Down
16 changes: 0 additions & 16 deletions tests/e2e/ssi_tests/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
# SSI Module E2E Tests

Following scenarios are covered for E2E testing:

`TC-1`: A simple SSI flow where three elements of SSI (DID Document, Schema Document and Credential Status Document).<br>
`TC-2`: Controller DID attempts to create Credential Schema and Credential Status Documents on behalf of Parent DID.<br>
`TC-3`: Multiple Controller DID attempt to create Credential Schema and Credential Status Documents on behalf of Parent DID.<br>
`TC-4`: Non-Controller DID attempts to create Credential Schema and Credential Status Documents on behalf of Parent DID (Invalid Case).<br>
`TC-5`: Non-Controller DID attempts to update a DID Document (Invalid Case).<br>
`TC-6`: Controller DID attempts to update the Parent DID Document.<br>
`TC-7`: Parent DID adds multiple DIDs in its controller group, and removes itself. One of the controllers and the Parent DID attemps to change the DID Document.<br>
`TC-8`: Deactivated DID attempts to create Schema and Credential Status Documents.<br>
`TC-9`: `x/ssi` module related transactions, using `secp256k1` keypair.<br>
`TC-10`: Test scenarios for `blockchainAccountId`.<br>
`TC-11`: `x/ssi` module related transactions, using ethereum based `secp256k1` keypair.<br>

## Run Tests

Run the following to run tests
Expand Down
Loading