Skip to content

Commit

Permalink
Merge pull request #351 from hypersign-protocol/develop
Browse files Browse the repository at this point in the history
release: v0.1.7
  • Loading branch information
arnabghose997 committed Mar 22, 2023
2 parents 27c0a3b + 0369721 commit b910dd6
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 68 deletions.
178 changes: 171 additions & 7 deletions tests/e2e/ssi_tests/e2e_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ def create_did_test():
create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering DID by passing both Alice's and Eve's Signature")

print("8. FAIL: Alice tries to register a DID Document with duplicate publicKeyMultibase of type Ed25519VerificationKey2020 \n")
kp_alice = generate_key_pair()
signers = []
did_doc_string = generate_did_document(kp_alice)
did_doc_string_2 = generate_did_document(kp_alice)

did_doc_string_vm_1 = did_doc_string["verificationMethod"][0]
did_doc_string_vm_2 = did_doc_string_2["verificationMethod"][0]
did_doc_string_vm_2["id"] = did_doc_string_vm_2["id"] + "new"

did_doc_string["verificationMethod"] = [
did_doc_string_vm_1,
did_doc_string_vm_2
]

did_doc_alice = did_doc_string["id"]
signPair_alice = {
"kp": kp_alice,
"verificationMethodId": did_doc_string["verificationMethod"][0]["id"],
"signing_algo": "ed25519"
}
signers.append(signPair_alice)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering Alice's DID with Id: {did_doc_alice}", True, True)

print("--- Test Completed ---\n")

# TC - II : Update DID scenarios
Expand Down Expand Up @@ -657,6 +682,8 @@ def caip10_ethereum_support_test():
"eip155:1",
"eip155:::::23",
"eip155::0x1234567"
"eip155:1000231432:0x23",
"eip155:jagrat:0x23"
]

for invalid_blockchain_id in invalid_blockchain_account_ids:
Expand All @@ -673,7 +700,7 @@ def caip10_ethereum_support_test():
}
signers.append(signPair)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering a DID Document with an invalid blockchainAccountId: {invalid_blockchain_id}", True)
run_blockchain_command(create_tx_cmd, f"Registering a DID Document with an invalid blockchainAccountId: {invalid_blockchain_id}", True, True)

print("Registering a DID with a VM of type EcdsaSecp256k1SignatureRecovery2020 having publicKeyMultibase attribute populated")
kp = generate_key_pair(algo=kp_algo)
Expand Down Expand Up @@ -728,7 +755,7 @@ def caip10_cosmos_support_test():
"cosmos:::::23",
"cosmos::0x1234567"
]

print("1. FAIL: Registering a DID Document with an invalid blockchainAccountIds.\n")
for invalid_blockchain_id in invalid_blockchain_account_ids:
print("Registering a DID Document with an invalid blockchainAccountId:", invalid_blockchain_id)
kp = generate_key_pair(algo=kp_algo)
Expand All @@ -745,9 +772,9 @@ def caip10_cosmos_support_test():
signers.append(signPair)

create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering a DID Document with an invalid blockchainAccountId: {invalid_blockchain_id}", True)
run_blockchain_command(create_tx_cmd, f"Registering a DID Document with an invalid blockchainAccountId: {invalid_blockchain_id}", True, True)

print("Registering a DID with a VM of type EcdsaSecp256k1VerificationKey2019 having both publicKeyMultibase and blockchainAccountId attributes populated")
print("2. PASS: Registering a DID with a VM of type EcdsaSecp256k1VerificationKey2019 having both publicKeyMultibase and blockchainAccountId attributes populated")
kp = generate_key_pair(algo=kp_algo)
did_doc_string = generate_did_document(kp, kp_algo)
did_doc_id = did_doc_string["id"]
Expand All @@ -761,7 +788,7 @@ def caip10_cosmos_support_test():
create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering the DID with DID Id {did_doc_id}")

print("Registering a DID with invalid chain-id in blockchainAccountId")
print("3. FAIL: Registering a DID with invalid chain-id in blockchainAccountId")
kp = generate_key_pair(algo=kp_algo)
did_doc_string = generate_did_document(kp, kp_algo)
did_doc_id = did_doc_string["id"]
Expand All @@ -775,9 +802,146 @@ def caip10_cosmos_support_test():
"signing_algo": kp_algo
}
signers.append(signPair)

create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering DID with Id: {did_doc_id}", True)
run_blockchain_command(create_tx_cmd, f"Registering DID with Id: {did_doc_id}", True, True)

print("4. PASS: Registering a DID with two VM of type EcdsaSecp256k1VerificationKey2019 with duplicate publicKeyMultibase and different blockchain account Id")
kp = generate_key_pair(algo=kp_algo)

did_doc_string_1 = generate_did_document(kp, kp_algo)
did_doc_string_2 = generate_did_document(kp, kp_algo, "osmo")
did_doc_string_2_vm = did_doc_string_2["verificationMethod"][0]
did_doc_string_2_vm["id"] = did_doc_string_2_vm["id"] + "new"

did_doc_string_1["verificationMethod"] = [
did_doc_string_1["verificationMethod"][0],
did_doc_string_2_vm,
]
did_doc_id = did_doc_string_1["id"]

signers = []
signPair1 = {
"kp": kp,
"verificationMethodId": did_doc_string_1["verificationMethod"][0]["id"],
"signing_algo": kp_algo
}
signPair2 = {
"kp": kp,
"verificationMethodId": did_doc_string_2["verificationMethod"][0]["id"],
"signing_algo": kp_algo
}
signers.append(signPair1)
signers.append(signPair2)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string_1, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering the DID with DID Id {did_doc_id}")

print("5. PASS: Registering a DID with two VM of type EcdsaSecp256k1VerificationKey2019 with duplicate publicKeyMultibase but one of them is without a blockchain account id")
kp = generate_key_pair(algo=kp_algo)

did_doc_string_1 = generate_did_document(kp, kp_algo)
did_doc_string_2 = generate_did_document(kp, kp_algo)
did_doc_string_2_vm = did_doc_string_2["verificationMethod"][0]
did_doc_string_2_vm["id"] = did_doc_string_2_vm["id"] + "new"

#Remove blockchainAccountIds
did_doc_string_1["verificationMethod"][0]["blockchainAccountId"] = ""

did_doc_string_1["verificationMethod"] = [
did_doc_string_1["verificationMethod"][0],
did_doc_string_2_vm,
]
did_doc_id = did_doc_string_1["id"]

signers = []
signPair1 = {
"kp": kp,
"verificationMethodId": did_doc_string_1["verificationMethod"][0]["id"],
"signing_algo": kp_algo
}
signPair2 = {
"kp": kp,
"verificationMethodId": did_doc_string_2["verificationMethod"][0]["id"],
"signing_algo": kp_algo
}
signers.append(signPair1)
signers.append(signPair2)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string_1, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering the DID with DID Id {did_doc_id}")

print("6. FAIL: Registering a DID with two VM of type EcdsaSecp256k1VerificationKey2019 with duplicate publicKeyMultibase and duplicate blockchainAccountId")
kp = generate_key_pair(algo=kp_algo)

did_doc_string_1 = generate_did_document(kp, kp_algo)
did_doc_string_2 = generate_did_document(kp, kp_algo)

did_doc_vm1 = did_doc_string_1["verificationMethod"][0]
did_doc_vm2 = did_doc_string_2["verificationMethod"][0]

# Change vm id
did_doc_vm1["id"] = did_doc_vm1["id"] + "news"
did_doc_vm2["id"] = did_doc_vm1["id"] + "2"


did_doc_string_1["verificationMethod"] = [
did_doc_vm1,
did_doc_vm2
]
did_doc_id = did_doc_string_1["id"]

signers = []
signPair1 = {
"kp": kp,
"verificationMethodId": did_doc_string_1["verificationMethod"][0]["id"],
"signing_algo": kp_algo
}
signPair2 = {
"kp": kp,
"verificationMethodId": did_doc_string_1["verificationMethod"][1]["id"],
"signing_algo": kp_algo
}
signers.append(signPair1)
signers.append(signPair2)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string_1, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering the DID with DID Id {did_doc_id}", True, True)

print("7. FAIL: Registering a DID with two VM of type EcdsaSecp256k1VerificationKey2019 with duplicate publicKeyMultibase and no blockchainAccountId in either of them")
kp = generate_key_pair(algo=kp_algo)

did_doc_string_1 = generate_did_document(kp, kp_algo)
did_doc_string_2 = generate_did_document(kp, kp_algo)

did_doc_vm1 = did_doc_string_1["verificationMethod"][0]
did_doc_vm2 = did_doc_string_2["verificationMethod"][0]

# Change vm id
did_doc_vm1["id"] = did_doc_vm1["id"] + "news"
did_doc_vm2["id"] = did_doc_vm1["id"] + "2"

# Remove blockchainAccountId
did_doc_vm1["blockchainAccountId"] = ""
did_doc_vm2["blockchainAccountId"] = ""

did_doc_string_1["verificationMethod"] = [
did_doc_vm1,
did_doc_vm2
]
did_doc_id = did_doc_string_1["id"]

signers = []
signPair1 = {
"kp": kp,
"verificationMethodId": did_doc_string_1["verificationMethod"][0]["id"],
"signing_algo": kp_algo
}
signPair2 = {
"kp": kp,
"verificationMethodId": did_doc_vm2["id"],
"signing_algo": kp_algo
}
signers.append(signPair1)
signers.append(signPair2)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string_1, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering the DID with DID Id {did_doc_id}", True, True)

print("--- Test Completed ---\n")

Expand Down
13 changes: 10 additions & 3 deletions tests/e2e/ssi_tests/generate_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from utils import run_command, generate_document_id, get_document_signature, \
secp256k1_pubkey_to_address

def generate_did_document(key_pair, algo="ed25519"):
def generate_did_document(key_pair, algo="ed25519", bech32prefix="hid"):
base_document = {
"context" : [
"https://www.w3.org/ns/did/v1"
Expand Down Expand Up @@ -41,8 +41,15 @@ def generate_did_document(key_pair, algo="ed25519"):
verification_method["blockchainAccountId"] = "eip155:1:" + key_pair["ethereum_address"]
elif algo == "secp256k1":

verification_method["blockchainAccountId"] = "cosmos:jagrat:" + \
secp256k1_pubkey_to_address(key_pair["pub_key_base_64"], "hid")
if bech32prefix == "hid":
verification_method["blockchainAccountId"] = "cosmos:jagrat:" + \
secp256k1_pubkey_to_address(key_pair["pub_key_base_64"], bech32prefix)
elif bech32prefix == "osmo":
verification_method["blockchainAccountId"] = "cosmos:osmosis-1:" + \
secp256k1_pubkey_to_address(key_pair["pub_key_base_64"], bech32prefix)
else:
raise Exception("unsupported bech32 prefix " + bech32prefix)

verification_method["publicKeyMultibase"] = key_pair["pub_key_multibase"]
else:
verification_method["publicKeyMultibase"] = key_pair["pub_key_multibase"]
Expand Down
41 changes: 41 additions & 0 deletions x/ssi/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ var SupportedClientSpecs []string = []string{
PersonalSignClientSpec,
}

// Supported CAIP-10 Prefixes
var SupportedCAIP10Prefixes = []string{
EthereumCAIP10Prefix,
CosmosCAIP10Prefix,
}

var SupportedCAIP10EthereumChainIds = []string{
// Ethereum-Based Mainnet Chains
"1", // Ethereum Mainnet
"137", // Polygon Mainnet
"56", // Binance Smart Chain

// Ethereum-Based Testnet Chains
"3", // Ropsten (Ethereum Testnet)
"4", // Rinkeby (Ethereum Testnet)
"5", // Goerli (Ethereum Testnet)
"80001", // Polygon Mumbai Testnet
"97", // Binance Smart Chain Testnet
}

var SupportedCAIP10CosmosChainIds = []string{
"cosmoshub-4", // Cosmos Hub
"osmosis-1", // Osmosis
"akashnet-2", // Akash
"stargaze-1", // Stargaze
"core-1", // Persistence
"crypto-org-chain-mainnet-1", // Crypto.Org Chain

"theta-testnet-001", // Cosmos Hub Theta Testnet
"osmo-test-4", // Osmosis Testnet
"elgafar-1", // Stargaze Testnet
"test-core-1", // Persistence Testnet
"jagrat", // Hypersign Identity Network - Jagrat Testnet
}

// Map between supported cosmos chain-id and their respective blockhchain address prefix
var CosmosCAIP10ChainIdBech32PrefixMap = map[string]string{
// Mainnet Chains
Expand All @@ -70,3 +105,9 @@ var CosmosCAIP10ChainIdBech32PrefixMap = map[string]string{
"test-core-1": "persistence",
"jagrat": "hid",
}

// Map between support CAIP-10 prefix and list of chain-ids
var SupportedCAIP10PrefixChainIdsMap = map[string][]string{
EthereumCAIP10Prefix: SupportedCAIP10EthereumChainIds,
CosmosCAIP10Prefix: SupportedCAIP10CosmosChainIds,
}

0 comments on commit b910dd6

Please sign in to comment.