diff --git a/cmd/hid-noded/cmd/generate_ssi.go b/cmd/hid-noded/cmd/generate_ssi.go index 1d7e024..3903248 100644 --- a/cmd/hid-noded/cmd/generate_ssi.go +++ b/cmd/hid-noded/cmd/generate_ssi.go @@ -189,7 +189,7 @@ func generateDidCmd() *cobra.Command { switch keyringBackend { case "test": - kr, err = keyring.New(appName, "test", didAliasConfig.HidNodeConfigDir, nil, nil) + kr, err = keyring.New(appName, "test", didAliasConfig.HidNodeConfigDir, nil, app.MakeEncodingConfig().Codec) if err != nil { return err } diff --git a/tests/e2e/ssi_tests/DEPRECATION.md b/tests/e2e/ssi_tests/DEPRECATION.md deleted file mode 100644 index e757d54..0000000 --- a/tests/e2e/ssi_tests/DEPRECATION.md +++ /dev/null @@ -1,5 +0,0 @@ -# Deprecation - -The Python based tests are outdated, and will be replaced by Golang based SSI tests. - -Until then, testing of `x/ssi` is done through JS SDK. \ No newline at end of file diff --git a/tests/e2e/ssi_tests/README.md b/tests/e2e/ssi_tests/README.md deleted file mode 100644 index 3a40c51..0000000 --- a/tests/e2e/ssi_tests/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## Run Tests - -Run the following to run tests -``` -# Make sure you are in `./tests/e2e/ssi_tests` directory - -python3 run.py -``` \ No newline at end of file diff --git a/tests/e2e/ssi_tests/broadcast_txs/tx_broadcast.json b/tests/e2e/ssi_tests/broadcast_txs/tx_broadcast.json deleted file mode 100644 index 529ffc9..0000000 --- a/tests/e2e/ssi_tests/broadcast_txs/tx_broadcast.json +++ /dev/null @@ -1,126 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/cosmos.bank.v1beta1.MsgSend", - "from_address": "hid1en0zyqxsevlkqdldcykydzxxqap2wx4ex5cgnl", - "to_address": "hid1gmhlnhj7zpr6dmdqagqhu2uww92vgj6f9wqrz2", - "amount": [ - { - "denom": "uhid", - "amount": "1000000" - } - ] - }, - { - "@type": "/hypersign.ssi.v1.MsgRegisterDID", - "didDocument": { - "context": [ - "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/suites/ed25519-2020/v1" - ], - "id": "did:hid:devnet:z6MkiXuTZdYs3qUsA2mo6S1Brs84bf4ryKJn2gJojrYZSbPq", - "controller": [ - "did:hid:devnet:z6MkiXuTZdYs3qUsA2mo6S1Brs84bf4ryKJn2gJojrYZSbPq" - ], - "alsoKnownAs": [], - "verificationMethod": [ - { - "id": "did:hid:devnet:z6MkiXuTZdYs3qUsA2mo6S1Brs84bf4ryKJn2gJojrYZSbPq#k1", - "type": "Ed25519VerificationKey2020", - "controller": "did:hid:devnet:z6MkiXuTZdYs3qUsA2mo6S1Brs84bf4ryKJn2gJojrYZSbPq", - "publicKeyMultibase": "z6MkiXuTZdYs3qUsA2mo6S1Brs84bf4ryKJn2gJojrYZSbPq", - "blockchainAccountId": "" - } - ], - "authentication": [], - "assertionMethod": [], - "keyAgreement": [], - "capabilityInvocation": [], - "capabilityDelegation": [], - "service": [] - }, - "didDocumentProofs": [ - { - "type": "Ed25519Signature2020", - "created": "2022-08-16T10:22:12Z", - "verificationMethod": "did:hid:devnet:z6MkiXuTZdYs3qUsA2mo6S1Brs84bf4ryKJn2gJojrYZSbPq#k1", - "proofPurpose": "assertionMethod", - "proofValue": "ztxeXJyc8sZC8gNRwZoGv28Rs1vzP2V9Zt94qF6nwhzHSU3QM2ZHrkpTW4tZYo9RVEugXNGvADr4RFAZx2yYJNyJ", - "clientSpecType": "CLIENT_SPEC_TYPE_NONE" - } - ], - "txAuthor": "hid1en0zyqxsevlkqdldcykydzxxqap2wx4ex5cgnl" - }, - { - "@type": "/hypersign.ssi.v1.MsgRegisterDID", - "didDocument": { - "context": [ - "https://www.w3.org/ns/did/v1", - "https://w3id.org/security/suites/ed25519-2020/v1" - ], - "id": "did:hid:devnet:z6MkqR457FGUq9JDm3eajLW3co1bERcrqdu3sJUzvJLbPFvS", - "controller": [ - "did:hid:devnet:z6MkqR457FGUq9JDm3eajLW3co1bERcrqdu3sJUzvJLbPFvS" - ], - "alsoKnownAs": [], - "verificationMethod": [ - { - "id": "did:hid:devnet:z6MkqR457FGUq9JDm3eajLW3co1bERcrqdu3sJUzvJLbPFvS#k1", - "type": "Ed25519VerificationKey2020", - "controller": "did:hid:devnet:z6MkqR457FGUq9JDm3eajLW3co1bERcrqdu3sJUzvJLbPFvS", - "publicKeyMultibase": "z6MkqR457FGUq9JDm3eajLW3co1bERcrqdu3sJUzvJLbPFvS", - "blockchainAccountId": "" - } - ], - "authentication": [], - "assertionMethod": [], - "keyAgreement": [], - "capabilityInvocation": [], - "capabilityDelegation": [], - "service": [] - }, - "didDocumentProofs": [ - { - "type": "Ed25519Signature2020", - "created": "2022-08-16T10:22:12Z", - "verificationMethod": "did:hid:devnet:z6MkqR457FGUq9JDm3eajLW3co1bERcrqdu3sJUzvJLbPFvS#k1", - "proofPurpose": "assertionMethod", - "proofValue": "ziupiWHX9n6jHY3euUKGe5d6VCgs6HjEykRKxYJTV9RdPEf4bGCHGqFHBgs1HX1AwjU4hsefL6bRkYPTxg1bybcp", - "clientSpecType": "CLIENT_SPEC_TYPE_NONE" - } - ], - "txAuthor": "hid1en0zyqxsevlkqdldcykydzxxqap2wx4ex5cgnl" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [ - { - "public_key": { - "@type": "/cosmos.crypto.secp256k1.PubKey", - "key": "Auezxmnywgrzb6M2kxLjapQ/bI6autcBSBParclOq//r" - }, - "mode_info": { - "single": { - "mode": "SIGN_MODE_DIRECT" - } - }, - "sequence": "106" - } - ], - "fee": { - "amount": [], - "gas_limit": "200000", - "payer": "", - "granter": "" - } - }, - "signatures": [ - "orwcPWyAWTueWl6g4VJEc92a7Lqo27JDoy7yOy0z2Z4rpDUaVLp4HeTLPZJ12fbjEDSGniHwStlcZ+NXryVx4g==" - ] -} \ No newline at end of file diff --git a/tests/e2e/ssi_tests/constants.py b/tests/e2e/ssi_tests/constants.py deleted file mode 100644 index fb2f2d9..0000000 --- a/tests/e2e/ssi_tests/constants.py +++ /dev/null @@ -1,3 +0,0 @@ -# The default single node localnet scripts (./scripts/localnet-single-node/setup.sh) -# spawns a blockchain and creates an account named `node1` -DEFAULT_BLOCKCHAIN_ACCOUNT_NAME="node1" \ No newline at end of file diff --git a/tests/e2e/ssi_tests/e2e_tests.py b/tests/e2e/ssi_tests/e2e_tests.py deleted file mode 100644 index df87d5a..0000000 --- a/tests/e2e/ssi_tests/e2e_tests.py +++ /dev/null @@ -1,1709 +0,0 @@ -import os -import sys -sys.path.insert(1, os.getcwd()) -import time -import copy - -from utils import run_blockchain_command, generate_key_pair, secp256k1_pubkey_to_address, add_keyAgreeemnt_pubKeyMultibase -from generate_doc import generate_did_document, generate_schema_document, generate_cred_status_document -from transactions import form_did_create_tx_multisig, form_did_update_tx_multisig, \ - query_did, form_create_schema_tx, form_did_deactivate_tx_multisig, form_create_cred_status_tx, \ - form_update_schema_tx, form_update_cred_status_tx -from constants import DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - -def bbs_signature_test(): - print("\n--1. PASS: Create a DID using BLS12381G2 Key Pair--\n") - - kp_alice = generate_key_pair("BbsBlsSignature2020") - signers = [] - did_doc_string = generate_did_document(kp_alice, "BbsBlsSignature2020") - did_doc_alice = did_doc_string["id"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "BbsBlsSignature2020" - } - 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}") - - print("\n--2. PASS: Create a Schema using BLS12381G2 Key Pair--\n") - - schema_doc, schema_proof = generate_schema_document( - kp_alice, - did_doc_alice, - did_doc_string["verificationMethod"][0]["id"], - algo="BbsBlsSignature2020" - ) - create_schema_cmd = form_create_schema_tx( - schema_doc, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - schema_doc_id = schema_doc["id"] - run_blockchain_command(create_schema_cmd, f"Registering Schema with Id: {schema_doc_id}") - - print("\n--3. PASS: Create a Credential Status using BLS12381G2 Key Pair--\n") - - cred_doc, cred_proof = generate_cred_status_document( - kp_alice, - did_doc_alice, - did_doc_string["verificationMethod"][0]["id"], - algo="BbsBlsSignature2020" - ) - register_cred_status_cmd = form_create_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Registering Credential status with Id: {cred_id}") - - - print("\n--4. PASS: Update a DID using BLS12381G2 Key Pair--\n") - did_doc_string["alsoKnownAs"] = ["blskeypairDid"] - signers = [] - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Bob (non-controller) attempts to update Org DID with Id: {did_doc_alice}") - - print("\n--5. PASS: Deactivate a DID using BLS12381G2 Key Pair--\n") - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_alice, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Org's DID with Id: {did_doc_alice}") - -def key_agrement_test(): - print("\n--1. FAIL: Ed25519VerificationKey2020 based Verification Method ID being added to keyAgreement attribute--\n") - - kp_alice = generate_key_pair("Ed25519Signature2020") - signers = [] - did_doc_string = generate_did_document(kp_alice, "Ed25519Signature2020") - did_doc_alice = did_doc_string["id"] - ed25519Vm = did_doc_string["verificationMethod"][0] - did_doc_string["keyAgreement"] = [ed25519Vm["id"]] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - 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("\n--2. FAIL: X25519KeyAgreementKey2020 based Verification Method ID being added to authentication attribute--\n") - - kp_bob = generate_key_pair("Ed25519Signature2020") - signers = [] - did_doc_string = generate_did_document(kp_bob, "Ed25519Signature2020") - did_doc_alice = did_doc_string["id"] - x25519Vm = add_keyAgreeemnt_pubKeyMultibase(did_doc_string["verificationMethod"][0], "X25519KeyAgreementKey2020") - did_doc_string["verificationMethod"] = [x25519Vm] - did_doc_string["authentication"] = [x25519Vm["id"]] - signPair_bob = { - "kp": kp_bob, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_bob) - 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("\n--3. PASS: A DID Document is created with Ed25519VerificationKey2020 and X25519KeyAgreementKey2020 based VMs--\n") - did_doc_string = generate_did_document(kp_alice, "Ed25519Signature2020") - signers = [] - x25519Vm["controller"] = ed25519Vm["controller"] - did_doc_string["verificationMethod"] = [ed25519Vm, x25519Vm] - did_doc_string["authentication"] = [ed25519Vm["id"]] - did_doc_string["keyAgreement"] = [x25519Vm["id"]] - 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_string['id']}") - - print("\n--4. FAIL: An attempt is made to update the DID Document by passing the signature of X25519KeyAgreementKey2020 based verification method") - signers = [] - did_doc_string["alsoKnownAs"] = ["KeyAgreementDid"] - did_doc_string["authentication"] = [] - signPair_x25519 = { - "kp": kp_bob, - "verificationMethodId": x25519Vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_x25519) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"DID Document update using X25519KeyAgreementKey2020 based verification method", True) - - print("\n--5. PASS: An attempt is made to update the DID Document by passing the signature of Ed25519VerificationKey2020 based verification method") - signers = [] - did_doc_string["alsoKnownAs"] = ["KeyAgreementDid"] - signers.append(signPair_alice) - signers.append(signPair_x25519) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"DID Document {did_doc_string['id']} update using Ed25519VerificationKey2020 based verification method") - - print("\n--6. FAIL: An attempt is made to deactivate the DID Document by passing the signature of X25519KeyAgreementKey2020 based verification method--\n") - signers = [] - signers.append(signPair_x25519) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_string["id"], signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"DID Document deactivate using X25519KeyAgreementKey2020 based verification method", True) - - print("\n--7. PASS: An attempt is made to deactivate the DID Document by passing the signature of Ed25519VerificationKey2020 based verification method--\n") - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_string["id"], signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"DID Document deactivate using Ed25519VerificationKey2020 based verification method") - -def unique_wallet_address_test(): - print("\n---1. FAIL: Alice Creates a DID Doc. Bob attempts to create a DID Document by adding one of Alice's VM.---\n") - - kp_alice = generate_key_pair("EcdsaSecp256k1RecoverySignature2020") - signers = [] - did_doc_string = generate_did_document(kp_alice, "EcdsaSecp256k1RecoverySignature2020") - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"][0] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "EcdsaSecp256k1RecoverySignature2020" - } - 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}") - - # Create Bob's DID with Alice's VM - kp_bob = generate_key_pair("EcdsaSecp256k1RecoverySignature2020") - signers = [] - did_doc_string = generate_did_document(kp_bob, "EcdsaSecp256k1RecoverySignature2020") - did_doc_bob = did_doc_string["id"] - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = [did_doc_alice_vm] - 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 Bob's DID with Id: {did_doc_bob}", True) - - print("\n---2. FAIL: Charlie creates a DID Document. After that, Charlie attempts to update its DID Document by adding one of Alice's VM for which valid signature is passed.---\n") - - kp_charlie = generate_key_pair("EcdsaSecp256k1RecoverySignature2020") - signers = [] - did_doc_string_charlie = generate_did_document(kp_charlie, "EcdsaSecp256k1RecoverySignature2020") - did_doc_charlie_id = did_doc_string_charlie["id"] - did_doc_charlie_vm = did_doc_string_charlie["verificationMethod"][0] - signPair_charlie = { - "kp": kp_charlie, - "verificationMethodId": did_doc_string_charlie["verificationMethod"][0]["id"], - "signing_algo": "EcdsaSecp256k1RecoverySignature2020" - } - signers.append(signPair_charlie) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string_charlie, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering Charlie's DID with Id: {did_doc_charlie_id}") - - signers = [] - did_doc_string_charlie["verificationMethod"] = [did_doc_charlie_vm, did_doc_alice_vm] - signers.append(signPair_charlie) - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_charlie, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Charlie (controller) attempts to add Alice's VM in its DID Id: {did_doc_charlie_id}", True) - - print("\n---3. PASS: Alice deactivates her DID Document. Charlie attempts to update its DID Document by adding one of Alice's VM for which valid signature is passed.---\n") - - # Alice Deactivates their DID Document - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_alice, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Org's DID with Id: {did_doc_alice}") - - # Charlie attempts to add the VM again - signers = [] - signers.append(signPair_charlie) - signers.append(signPair_alice) - run_blockchain_command(update_tx_cmd, f"Charlie (controller) attempts to add Alice's VM in DID Id: {did_doc_charlie_id}") - - print("\n---4. PASS: Charlie removes one of its Verification Methods. George creates a didDoc for himself. He then proceed to update his DID Document by adding the Verification method removed by Charlie---\n") - - # Create George's DIDDoc - kp_george = generate_key_pair("EcdsaSecp256k1RecoverySignature2020") - signers = [] - did_doc_string_george = generate_did_document(kp_george, "EcdsaSecp256k1RecoverySignature2020") - did_doc_george_id = did_doc_string_george["id"] - did_doc_george_vm = did_doc_string_george["verificationMethod"][0] - signPair_george = { - "kp": kp_george, - "verificationMethodId": did_doc_string_george["verificationMethod"][0]["id"], - "signing_algo": "EcdsaSecp256k1RecoverySignature2020" - } - signers.append(signPair_george) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string_george, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering George's DID with Id: {did_doc_george_id}") - - # Charlie Removes one of their DIDDoc - signers = [] - charlie_vm_to_be_removed = did_doc_string_charlie["verificationMethod"][0] # Controller is Charlie - signers.append(signPair_charlie) - did_doc_string_charlie["verificationMethod"] = [did_doc_string_charlie["verificationMethod"][1]] # Controller for this VM is alice - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_charlie, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Charlie (controller) attempts to remove one of its VM from its DID: {did_doc_charlie_id}") - - # George updates it DID Document by adding the VM that Charlie Removed - signers = [] - did_doc_string_george["verificationMethod"] = [charlie_vm_to_be_removed, did_doc_george_vm] - signers.append(signPair_charlie) - signers.append(signPair_george) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_george, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"George attempts add the VM removed by Charlie: {did_doc_george_id}") - -# TC - I : Create DID scenarios -def create_did_test(): - print("\n--- Create DID Test ---\n") - - print("1. FAIL: Alice has a registered DID Document where Alice is the controller. Bob tries to register their DID Document by keeping both Alice and Bob as controllers, and by sending only his signature.\n") - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - 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}") - - kp_bob = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_bob) - did_doc_bob = did_doc_string["id"] - did_doc_string["controller"] = [did_doc_alice, did_doc_bob] - signPair_bob = { - "kp": kp_bob, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering Bob's DID with Id: {did_doc_bob}", True) - - print("2. PASS: Alice has a registered DID Document where Alice is the controller. Bob tries to register their DID Document by keeping both Alice and Bob as controllers, and by sending only both Alice's and Bob's signatures.\n") - signers = [] - signers.append(signPair_bob) - 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 DID with Id: {did_doc_bob}") - - - print("3. PASS: Alice has a registered DID Document where Alice is the controller. She tries to create an organization DID, in which Alice is the only controller and it's verification method field is empty.\n") - kp_org = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_org) - did_doc_org = did_doc_string["id"] - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = [] - 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 DID with Id: {did_doc_org}") - - #Alice creates a DID where the controller only has Alice's DID and the verfication method has two ETH wallets added. Signature of all hot wallets are passed - kp_hot_wallet_1 = generate_key_pair("EcdsaSecp256k1RecoverySignature2020") - kp_hot_wallet_2 = generate_key_pair("EcdsaSecp256k1RecoverySignature2020") - kp_org = generate_key_pair() - - did_doc_string = generate_did_document(kp_org) - did_doc_canon = did_doc_string["id"] - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = [ - { - "id": "did:hid:devnet:" + kp_hot_wallet_1["ethereum_address"] + "#k1", - "controller": did_doc_alice, - "type": "EcdsaSecp256k1RecoveryMethod2020", - "blockchainAccountId": "eip155:1:" + kp_hot_wallet_1["ethereum_address"], - }, - { - "id": "did:hid:devnet:" + kp_hot_wallet_2["ethereum_address"] + "#k2", - "controller": did_doc_alice, - "type": "EcdsaSecp256k1RecoveryMethod2020", - "blockchainAccountId": "eip155:1:" + kp_hot_wallet_2["ethereum_address"], - }, - ] - - signPair_hotWallet1 = { - "kp": kp_hot_wallet_1, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "EcdsaSecp256k1RecoverySignature2020" - } - signPair_hotWallet2 = { - "kp": kp_hot_wallet_2, - "verificationMethodId": did_doc_string["verificationMethod"][1]["id"], - "signing_algo": "EcdsaSecp256k1RecoverySignature2020" - } - - print("4. FAIL: Alice has a registered DID Document where Alice is the controller. Alice tries to register an Org DID Document where Alice is the sole controller, and there are two verification Methods, of type EcdsaSecp256k1RecoveryMethod2020, and Alice is the controller for each one of them. Signature is provided by only one of the VMs.\n") - signers = [] - signers.append(signPair_hotWallet2) - 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_canon}", True) - - print("5. PASS: Alice has a registered DID Document where Alice is the controller. Alice tries to register an Org DID Document where Alice is the sole controller, and there are two verification Methods, of type EcdsaSecp256k1RecoveryMethod2020, and Alice is the controller for each one of them. Signature is provided by both VMs.\n") - signers = [] - signers.append(signPair_hotWallet1) - signers.append(signPair_hotWallet2) - 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_canon}") - - # Alice creates a DID where they keep the VM of their friend Eve in the verificationMethod list of the document - print("6. FAIL: Alice creates an Org DID where Alice is the controller, and she adds a verification method of her friend Eve. Only Alice sends the singature.\n") - kp_eve = generate_key_pair("Ed25519Signature2020") - did_doc_string = generate_did_document(kp_eve, algo="Ed25519Signature2020") - did_doc_eve = did_doc_string["id"] - did_doc_eve_vms = did_doc_string["verificationMethod"] - signers = [] - signPair_eve = { - "kp": kp_eve, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_eve) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering Eve's DID with Id: {did_doc_eve}") - - kp_random = generate_key_pair() - did_doc_string = generate_did_document(kp_random) - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = [ - did_doc_eve_vms[0] - ] - signers = [] - 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 DID by passing only Alice's Signature", True) - - print("7. PASS: Alice creates an Org DID where Alice is the controller, and she adds a verification method of her friend Eve. Both Alice and Eve send their singatures.\n") - signers = [] - signers.append(signPair_alice) - signers.append(signPair_eve) - 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": "Ed25519Signature2020" - } - 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 -def update_did_test(): - print("\n--- Update DID Test ---\n") - - print("1. FAIL: Alice creates an Org DID where alice is the controller, and Bob's VM is added to its VM List only. Bob attempts to update Org DID by sending his signature.\n") - - # Register Alice's DID - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"][0] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_alice_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 of Alice's DID with Id: {did_doc_alice}") - - # Register Bob's DID - kp_bob = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_bob) - did_doc_bob = did_doc_string["id"] - did_doc_bob_vm = did_doc_string["verificationMethod"][0] - signPair_bob = { - "kp": kp_bob, - "verificationMethodId": did_doc_bob_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Bob's DID with Id: {did_doc_bob}") - - # Alice creates Organization DID with itself being the only controller and Bob's VM being added to VM List - kp_org = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_org) - did_doc_org = did_doc_string["id"] - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = [did_doc_bob_vm] - signers.append(signPair_alice) - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Org DID with Id: {did_doc_org}") - - # Bob (who is not the controller) attempts to make changes in Org DID - signers = [] - did_doc_string["capabilityDelegation"] = [did_doc_bob_vm["id"]] - signers.append(signPair_bob) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Bob (non-controller) attempts to update Org DID with Id: {did_doc_org}", True) - - # Alice (who is the controller) attempts to make changes in Org DID - print("2. PASS: Alice creates an Org DID where alice is the controller, and Bob's VM is added to its VM List only. Alice attempts to update Org DID by sending her signature.\n") - signers = [] - did_doc_string["alsoKnownAs"] = ["gm1", "gm2"] - did_doc_string["capabilityDelegation"] = [did_doc_bob_vm["id"]] - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Alice (controller) attempts to update Org DID with Id: {did_doc_org}") - - did_doc_string_org = did_doc_string - - print("3. FAIL: Alice attempts to add George as controller of Org ID. Only George's Signature is sent.\n") - signers = [] - kp_george = generate_key_pair() - did_doc_string = generate_did_document(kp_george) - did_doc_george = did_doc_string["id"] - did_doc_george_vm = did_doc_string["verificationMethod"][0] - signPair_george = { - "kp": kp_george, - "verificationMethodId": did_doc_george_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_george) - update_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Registering George's DID with Id: {did_doc_george}") - - # Addition of George's DID to controller by only Alice's siganature - signers = [] - did_doc_string_org["controller"] = [did_doc_alice, did_doc_george] - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_org, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Adding George's DID as controller with Alice's signature only", True) - - # Addition of George's DID to controller by only George's siganature - print("4. FAIL: Alice attempts to add George as controller of Org ID. Only Alice's Signature is sent.\n") - signers = [] - did_doc_string_org["controller"] = [did_doc_alice, did_doc_george] - signers.append(signPair_george) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_org, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Adding George's DID as controller with George's signature only", True) - - # Addition of George's DID to controller by George's and Alice's siganature - print("5. PASS: Alice attempts to add George as controller of Org ID. Both Alice's and George's Signatures are sent.\n") - signers = [] - did_doc_string_org["controller"] = [did_doc_alice, did_doc_george] - signers.append(signPair_alice) - signers.append(signPair_george) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_org, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Adding George's DID as controller with George's and Alice's signature") - - # Removal of George's controller by Alice's signature - print("6. PASS: Alice attempts to remove George as controller of Org ID. Only Alice's Signature is sent.\n") - signers = [] - did_doc_string_org["controller"] = [did_doc_alice] - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_org, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Removal of George's controller by Alice's signature") - - # Addition of George's controller and removal of Alice's controller at same time - print("7. PASS: Addition of George as a controller and simultaneous removal of Alice as a controller. Both alice's and george's signature are passed.\n") - signers = [] - did_doc_string_org["controller"] = [did_doc_george] - signers.append(signPair_alice) - signers.append(signPair_george) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string_org, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Removal of Alice's controller and addition of Bob's controller") - - print("8. FAIL: Alice tries to update her DID Document without changing anything\n") - did_doc_string = query_did(did_doc_alice)["didDocument"] - signers = [] - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Alice attempts update without any change Tx", True) - - # Register Alice's DID - print("9. PASS: Jenny creates herself a DID with empty Controller list. She then attempts to update the DIDDoc by changing the alsoKnownAs field and passes her signature only.\n") - kp_jenny = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_jenny) - did_doc_string["controller"] = [] - did_doc_jenny = did_doc_string["id"] - did_doc_jenny_vm = did_doc_string["verificationMethod"][0] - signPair_jenny = { - "kp": kp_jenny, - "verificationMethodId": did_doc_jenny_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_jenny) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Jenny's DID with Id: {did_doc_jenny}") - - signers = [] - did_doc_string["capabilityDelegation"] = [did_doc_jenny_vm["id"]] - signers.append(signPair_jenny) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Jenny (controller) attempts to update Tx") - - print("10. FAIL: Jenny creates a DID. She then attempts to update the DIDDoc by adding a new Verification method. She passes signature only for old VM\n") - kp_jenny = generate_key_pair() - kp_jenny_2 = generate_key_pair() - - signers = [] - did_doc_string = generate_did_document(kp_jenny) - did_doc_jenny = did_doc_string["id"] - did_doc_jenny_vm = did_doc_string["verificationMethod"][0] - signPair_jenny = { - "kp": kp_jenny, - "verificationMethodId": did_doc_jenny_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_jenny) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Jenny's DID with Id: {did_doc_jenny}") - - signers = [] - did_doc_string_alice = generate_did_document(kp_jenny_2) - new_vm = did_doc_string_alice["verificationMethod"][0] - new_vm_id = did_doc_string["verificationMethod"][0]["id"] + "news" - new_vm["id"] = new_vm_id - new_vm["controller"] = did_doc_string["id"] - - did_doc_string["verificationMethod"] = [ - did_doc_string["verificationMethod"][0], - new_vm, - ] - signPair_jenny_1 = { - "kp": kp_jenny, - "verificationMethodId": did_doc_jenny_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signPair_jenny_2 = { - "kp": kp_jenny_2, - "verificationMethodId": new_vm_id, - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_jenny_1) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Jenny attempts to update the DIDDoc with only old VM's signature", True) - - print("11. PASS: Jenny attempts to update the same didDoc by passing signatures for both old and new verification methods\n") - - signers = [] - signers.append(signPair_jenny_1) - signers.append(signPair_jenny_2) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Jenny attempts to update the DIDDoc with both new and old VM's signature") - - print("12. PASS: Jenny removes the inital verification method she had added. She passes only one signature corresponding to the lastest VM") - - did_doc_string["verificationMethod"] = [ - new_vm, - ] - signers = [] - signers.append(signPair_jenny_1) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Jenny attempts to remove Verification Method using signature corresponding to other verification method") - - print("--- Test Completed ---\n") - -def deactivate_did(): - print("\n--- Deactivate DID Test ---\n") - - print("1. PASS: Alice creates an Org DID with herself and Bob being the Controller. Alice attempts to deactivate it \n") - - # Register Alice's DID - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"][0] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_alice_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 of Alice's DID with Id: {did_doc_alice}") - - # Register Bob's DID - kp_bob = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_bob) - did_doc_bob = did_doc_string["id"] - did_doc_bob_vm = did_doc_string["verificationMethod"][0] - signPair_bob = { - "kp": kp_bob, - "verificationMethodId": did_doc_bob_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Bob's DID with Id: {did_doc_bob}") - - # Alice creates Organization DID with itself being the only controller and Bob's VM being added to VM List - kp_org = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_org) - did_doc_org = did_doc_string["id"] - did_doc_string["controller"] = [did_doc_alice, did_doc_bob] - did_doc_string["verificationMethod"] = [] - signers.append(signPair_alice) - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Org DID with Id: {did_doc_org}") - - # Deactivate DID - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_org, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Org's DID with Id: {did_doc_org}") - - print("2. PASS: Mike creates a DID for himself, but the controller list is empty. Mike attempts to deactivate it \n") - - # Register Mike's DID - kp_mike = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_mike) - did_doc_string["controller"] = [] - did_doc_mike = did_doc_string["id"] - did_doc_mike_vm = did_doc_string["verificationMethod"][0] - signPair_mike = { - "kp": kp_mike, - "verificationMethodId": did_doc_mike_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_mike) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Mike's DID with Id: {did_doc_mike}") - - - # Deactivate DID - signers = [] - signers.append(signPair_mike) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_mike, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Mike's DID with Id: {did_doc_mike}") - - print("3. FAIL: Mike creates a DID for himself, but the controller list is empty. Mike deactivates it and then attempts to updates it. \n") - - kp_mike = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_mike) - did_doc_string["controller"] = [] - did_doc_mike = did_doc_string["id"] - did_doc_mike_vm = did_doc_string["verificationMethod"][0] - signPair_mike = { - "kp": kp_mike, - "verificationMethodId": did_doc_mike_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_mike) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Mike's DID with Id: {did_doc_mike}") - - # Deactivate DID - signers = [] - signers.append(signPair_mike) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_mike, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Mike's DID with Id: {did_doc_mike}") - - # Attempt to update deactivated DID - signers = [] - signers.append(signPair_mike) - did_doc_string["alsoKnownAs"] = ["selfCustody"] - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Bob (non-controller) attempts to update Org DID with Id: {did_doc_org}", True) - - print("--- Test Completed ---\n") - -def schema_test(): - print("\n--- Schema Test ---\n") - - print("1. FAIL: Alice creates a DID with herself being the controller, and then deactivates it. She attempts to registers a schema using one of her VMs\n") - - # Register Alice's DID - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"][0] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_alice_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 of Alice's DID with Id: {did_doc_alice}") - - # Deactiving Alice's DID - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_alice, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Alice's DID with Id: {did_doc_alice}") - - # Register Schema from one of alice's VM Id - schema_doc, schema_proof = generate_schema_document( - kp_alice, - did_doc_alice, - did_doc_alice_vm["id"] - ) - create_schema_cmd = form_create_schema_tx( - schema_doc, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - schema_doc_id = schema_doc["id"] - run_blockchain_command(create_schema_cmd, f"Registering Schema with Id: {schema_doc_id}", True) - - print("2. PASS: Bob creates a DID with herself being the controller. He attempts to registers a schema using one of her VMs\n") - - # Register Alice's DID - kp_bob = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_bob) - did_doc_bob = did_doc_string["id"] - did_doc_bob_vm = did_doc_string["verificationMethod"][0] - signPair_bob = { - "kp": kp_bob, - "verificationMethodId": did_doc_bob_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Bob's DID with Id: {did_doc_bob}") - - - # Register Schema from one of alice's VM Id - schema_doc, schema_proof = generate_schema_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"] - ) - create_schema_cmd = form_create_schema_tx( - schema_doc, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - schema_doc_id = schema_doc["id"] - run_blockchain_command(create_schema_cmd, f"Registering Schema with Id: {schema_doc_id}") - - print("3. FAIL: Bob creates a Schema where the name field is not in Pascal Case \n") - - invalid_schema_doc_1 = copy.deepcopy(schema_doc) - invalid_schema_doc_1["name"] = "Day Pass Credential" - schema_id_list = list(invalid_schema_doc_1["id"]) - schema_id_list[-3] = '4' - invalid_schema_doc_1["id"] = "".join(schema_id_list) - invalid_schema_doc_1_id = invalid_schema_doc_1["id"] - - _, schema_proof = generate_schema_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_schema=invalid_schema_doc_1 - ) - update_schema_cmd = form_update_schema_tx( - invalid_schema_doc_1, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - run_blockchain_command(update_schema_cmd, f"Updating Schema with Id: {invalid_schema_doc_1_id}", True) - - print("4. FAIL: Bob creates a Schema where the property field is some random string\n") - - invalid_schema_doc_2 = copy.deepcopy(schema_doc) - invalid_schema_doc_2["schema"]["properties"] = "somestring" - schema_id_list = list(invalid_schema_doc_2["id"]) - schema_id_list[-3] = '4' - invalid_schema_doc_2["id"] = "".join(schema_id_list) - invalid_schema_doc_2_id = invalid_schema_doc_2["id"] - - _, schema_proof = generate_schema_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_schema=invalid_schema_doc_2 - ) - update_schema_cmd = form_update_schema_tx( - invalid_schema_doc_2, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - run_blockchain_command(update_schema_cmd, f"Updating Schema with Id: {invalid_schema_doc_2_id}", True) - - print("5. FAIL: Bob creates a Schema where the property field is a valid JSON, but one of the attributes has an invalid sub-attribute\n") - - invalid_schema_doc_3 = copy.deepcopy(schema_doc) - invalid_schema_doc_3["schema"]["properties"] = "{\"fullName\":{\"type\":\"string\",\"sda\":\"string\"},\"companyName\":{\"type\":\"string\"},\"center\":{\"type\":\"string\"},\"invoiceNumber\":{\"type\":\"string\"}}" - schema_id_list = list(invalid_schema_doc_3["id"]) - schema_id_list[-3] = '4' - invalid_schema_doc_3["id"] = "".join(schema_id_list) - invalid_schema_doc_3_id = invalid_schema_doc_3["id"] - - _, schema_proof = generate_schema_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_schema=invalid_schema_doc_3 - ) - update_schema_cmd = form_update_schema_tx( - invalid_schema_doc_3, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - run_blockchain_command(update_schema_cmd, f"Updating Schema with Id: {invalid_schema_doc_3_id}", True) - - print("6. FAIL: Bob creates a Schema where the property field is a valid JSON, but `type` sub-attribute is missing\n") - - invalid_schema_doc_4 = copy.deepcopy(schema_doc) - invalid_schema_doc_4["schema"]["properties"] = "{\"fullName\":{\"format\":\"string\"},\"companyName\":{\"type\":\"string\"},\"center\":{\"type\":\"string\"},\"invoiceNumber\":{\"type\":\"string\"}}" - schema_id_list = list(invalid_schema_doc_4["id"]) - schema_id_list[-3] = '4' - invalid_schema_doc_4["id"] = "".join(schema_id_list) - invalid_schema_doc_4_id = invalid_schema_doc_4["id"] - - _, schema_proof = generate_schema_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_schema=invalid_schema_doc_4 - ) - update_schema_cmd = form_update_schema_tx( - invalid_schema_doc_4, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - run_blockchain_command(update_schema_cmd, f"Updating Schema with Id: {invalid_schema_doc_4_id}", True) - - print("7. PASS: Bob updates a schema using one of her VMs\n") - updated_schema_doc = copy.deepcopy(schema_doc) - #Increment version in Schema id - schema_id_list = list(updated_schema_doc["id"]) - schema_id_list[-3] = '4' - updated_schema_doc["id"] = "".join(schema_id_list) - updated_schema_doc_id = updated_schema_doc["id"] - - _, schema_proof = generate_schema_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_schema=updated_schema_doc - ) - update_schema_cmd = form_update_schema_tx( - updated_schema_doc, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - run_blockchain_command(update_schema_cmd, f"Updating Schema with Id: {updated_schema_doc_id}") - - print("--- Test Completed ---\n") - -def credential_status_test(): - print("\n--- Credential Status Test ---\n") - - print("1. FAIL: Alice creates a DID with herself being the controller, and then deactivates it. She attempts to registers a credential status using one of her VMs\n") - - # Register Alice's DID - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"][0] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_alice_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 of Alice's DID with Id: {did_doc_alice}") - - # Deactiving Alice's DID - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_alice, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Alice's DID with Id: {did_doc_alice}") - - # Register Credential Status from one of alice's VM Id - cred_doc, cred_proof = generate_cred_status_document( - kp_alice, - did_doc_alice, - did_doc_alice_vm["id"] - ) - register_cred_status_cmd = form_create_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Registering Credential status with Id: {cred_id}", True) - - print("2. PASS: Bob creates a DID with herself being the controller. He attempts to registers a credential status using one of his VMs\n") - - # Register Alice's DID - kp_bob = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_bob) - did_doc_bob = did_doc_string["id"] - did_doc_bob_vm = did_doc_string["verificationMethod"][0] - signPair_bob = { - "kp": kp_bob, - "verificationMethodId": did_doc_bob_vm["id"], - "signing_algo": "Ed25519Signature2020" - } - signers.append(signPair_bob) - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering of Bob's DID with Id: {did_doc_bob}") - - - # Register Credential Status from one of alice's VM Id - cred_doc, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"] - ) - register_cred_status_cmd = form_create_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Registering Credential status with Id: {cred_id}") - - print("3. FAIL: Bob attempts to update credential status without any changes\n") - _, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_credstatus_doc=cred_doc - ) - register_cred_status_cmd = form_update_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Updating Credential status with Id: {cred_id}", True) - - print("4. PASS: Bob suspends the credential status using one of his VMs\n") - cred_doc["suspended"] = True - - _, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_credstatus_doc=cred_doc - ) - register_cred_status_cmd = form_update_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Updating Credential status with Id: {cred_id}") - - print("5. PASS: Bob un-suspends the credential status using one of his VMs\n") - cred_doc["suspended"] = False - - _, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_credstatus_doc=cred_doc - ) - register_cred_status_cmd = form_update_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Updating Credential status with Id: {cred_id}") - - print("6. FAIL: Bob attempts to update the VC status document by changing the Credential Merkle Root Hash\n") - valid_cred_merkle_root_hash = cred_doc["credentialMerkleRootHash"] # for later re-assignment in next test case - cred_doc["credentialMerkleRootHash"] = "9de17abaffe74f4675c738f5d69c28a329aff8721cb0ed4808d8616e26280ed9" - - _, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_credstatus_doc=cred_doc - ) - register_cred_status_cmd = form_update_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Updating Credential status with Id: {cred_id}", True) - cred_doc["credentialMerkleRootHash"] = valid_cred_merkle_root_hash - - print("7. PASS: Bob revokes the credential status using one of his VMs\n") - cred_doc["revoked"] = True - - _, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_credstatus_doc=cred_doc - ) - register_cred_status_cmd = form_update_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Updating Credential status with Id: {cred_id}") - - print("8. FAIL: Bob attempts to un-revoke the credential status using one of his VMs\n") - cred_doc["revoked"] = False - - _, cred_proof = generate_cred_status_document( - kp_bob, - did_doc_bob, - did_doc_bob_vm["id"], - updated_credstatus_doc=cred_doc - ) - register_cred_status_cmd = form_update_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Updating Credential status with Id: {cred_id}", True) - - print("--- Test Completed ---\n") - -def caip10_ethereum_support_test(): - print("\n--- CAIP-10 Test: Ethereum Chains ---\n") - kp_algo = "EcdsaSecp256k1RecoverySignature2020" - - # Invalid blockchain Account Ids - invalid_blockchain_account_ids = [ - "abc345566", - "eip:1:0x1234", - "eip155", - "eip155:1:", - "eip155::", - "eip155:1", - "eip155:::::23", - "eip155::0x1234567" - "eip155:1000231432:0x23", - "eip155:jagrat:0x23" - ] - - 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) - - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = invalid_blockchain_id - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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 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) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["publicKeyMultibase"] = "zrxxgf1f9xPYTraixqi9tipLta61hp4VJWQUUW5pmwcVz" - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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, "Registering a DID with a VM of type EcdsaSecp256k1SignatureRecovery2020 having publicKeyMultibase attribute populated", True, True) - - # Test for valid blockchainAccountId - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - print( - "Registering a DID Document with a valid blockchainAccountId:", - did_doc_string["verificationMethod"][0]["blockchainAccountId"] - ) - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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}") - - print("--- Test Completed ---\n") - -def caip10_cosmos_support_test(): - print("\n--- CAIP-10 Test: Cosmos Chains ---\n") - - kp_algo = "EcdsaSecp256k1Signature2019" - - # Invalid blockchain Account Ids - invalid_blockchain_account_ids = [ - "abc345566", - "cos:1:0x1234", - "cosmos", - "cosmos:1", - "cosmos:jagrat", - "cosmos:1:", - "cosmos::", - "cosmos:1", - "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) - - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = invalid_blockchain_id - - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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 a DID Document with an invalid blockchainAccountId: {invalid_blockchain_id}", True, True) - - 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"] - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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 the DID with DID Id {did_doc_id}") - - 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"] - blockchainAccountId = secp256k1_pubkey_to_address(kp["pub_key_base_64"], "hid") - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = "cosmos:hidnode02:" + blockchainAccountId - - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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, 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_2_vm["controller"] = did_doc_string_1["verificationMethod"][0]["controller"] - - 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") - -def vm_type_test(): - print("\n--- Verification Method Types Test ---\n") - - # Ed25519VerificationKey2020 - print("1. FAIL: Registering DID Document with a verification method of type Ed25519VerificationKey2020. Both publicKeyMultibase and blockchainAccountId are passed.") - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = "solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv" - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 DID with Id: {did_doc_alice}", True, True) - - print("2. FAIL: Registering DID Document with a verification method of type Ed25519VerificationKey2020. Only blockchainAccountId is passed.") - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["publicKeyMultibase"] = "" - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = "solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ:7S3P4HxJpyyigGzodYwHtCxZyUQe9JiBMHyRWXArAaKv" - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 DID with Id: {did_doc_alice}", True, True) - - print("3. PASS: Registering DID Document with a verification method of type Ed25519VerificationKey2020. Only publicKeyMultibase is passed.") - kp_alice = generate_key_pair() - signers = [] - did_doc_string = generate_did_document(kp_alice) - did_doc_alice = did_doc_string["id"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "Ed25519Signature2020" - } - 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 DID with Id: {did_doc_alice}") - - # EcdsaSecp256k1VerificationKey2019 - print("4. PASS: Registering DID Document with a verification method of type EcdsaSecp256k1VerificationKey2019. Only publicKeyMultibase is passed.") - kp_algo = "EcdsaSecp256k1Signature2019" - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo, is_uuid=True, bech32prefix="") - did_doc_id = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = "" - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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}") - - print("5. PASS: Registering DID Document with a verification method of type EcdsaSecp256k1VerificationKey2019. Both publicKeyMultibase and blockchainAccountId are passed.") - kp_algo = "EcdsaSecp256k1Signature2019" - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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}") - - print("6. FAIL: Registering DID Document with a verification method of type EcdsaSecp256k1VerificationKey2019. Only blockchainAccountId is passed.") - kp_algo = "EcdsaSecp256k1Signature2019" - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["publicKeyMultibase"] = "" - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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, True) - - # EcdsaSecp256k1RecoveryMethod2020 - print("7. FAIL: Registering DID Document with a verification method of type EcdsaSecp256k1RecoveryMethod2020. Only publicKeyMultibase is passed.") - kp_algo = "EcdsaSecp256k1RecoverySignature2020" - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["publicKeyMultibase"] = "z22XxPVrzTr24zUBGfZiZCm9bwj3RkHKLmx9ENYBxmY57o" - did_doc_string["verificationMethod"][0]["blockchainAccountId"] = "" - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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, True) - - print("8. FAIL: Registering DID Document with a verification method of type EcdsaSecp256k1RecoveryMethod2020. Both publicKeyMultibase and blockchainAccountId is passed.") - kp_algo = "EcdsaSecp256k1RecoverySignature2020" - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - did_doc_string["verificationMethod"][0]["publicKeyMultibase"] = "z22XxPVrzTr24zUBGfZiZCm9bwj3RkHKLmx9ENYBxmY57o" - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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, True) - - print("9. PASS: Registering DID Document with a verification method of type EcdsaSecp256k1RecoveryMethod2020. Only blockchainAccountId is passed.") - kp_algo = "EcdsaSecp256k1RecoverySignature2020" - kp = generate_key_pair(algo=kp_algo) - did_doc_string = generate_did_document(kp, kp_algo) - did_doc_id = did_doc_string["id"] - signers = [] - signPair = { - "kp": kp, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "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}") - - print("--- Test Completed ---\n") - -def method_specific_id_test(): - print("\n--- Method Specific ID Tests ---\n") - - print("1. PASS: Registering a DID Document where the user provides a blockchain address in MSI that they own") - - kp_algo = "EcdsaSecp256k1Signature2019" - kp_alice = generate_key_pair(algo=kp_algo) - signers = [] - did_doc_string = generate_did_document(kp_alice, algo=kp_algo) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": kp_algo - } - 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}") - - print("2. FAIL: Registering a DID Document where the user provides a blockchain address in MSI that they don't own") - - kp_algo = "EcdsaSecp256k1Signature2019" - kp_bob = generate_key_pair(algo=kp_algo) - signers = [] - did_doc_string = generate_did_document(kp_bob, algo=kp_algo) - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = did_doc_alice_vm - - did_doc_bob = did_doc_string["id"] - 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 Bob's DID with Id: {did_doc_bob}", True) - - print("3. PASS: Registering a DID Document where the user provides a multibase encoded public key in MSI that they own") - - kp_algo = "Ed25519Signature2020" - kp_alice = generate_key_pair(algo=kp_algo) - signers = [] - did_doc_string = generate_did_document(kp_alice, algo=kp_algo) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": kp_algo - } - 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}") - - print("4. PASS: Registering a DID Document where the user provides a multibase encoded public key in MSI that they don't own") - - kp_algo = "Ed25519Signature2020" - kp_bob = generate_key_pair(algo=kp_algo) - signers = [] - did_doc_string = generate_did_document(kp_bob, algo=kp_algo) - did_doc_string["controller"] = [did_doc_alice] - did_doc_string["verificationMethod"] = did_doc_alice_vm - - did_doc_bob = did_doc_string["id"] - 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 Bob's DID with Id: {did_doc_bob}") - - print("5. FAIL: Attempt to Register Invalid DID Documents with invalid DID Id") - - did_id_list = [ - "did:hid:1:", - "did:hid:1", - "did:hid:devnet", - "did:hid:devnet:", - "did:hid:devnet:zHiii", - "did:hid:devnet:asa54qf", - "did:hid:devnet:asa54qf|sds", - "did:hid:devnet:-asa54-qfsds", - "did:hid:devnet:.com", - ] - - for did_id in did_id_list: - did_doc_string["id"] = did_id - create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(create_tx_cmd, f"Registering Invalid DID with Id: {did_id}", True, True) - - print("6. PASS: Alice tries to update their DID Document by removing the Verification Method associated with the method specific id (CAIP-10 Blockchain Address)") - - kp_algo = "EcdsaSecp256k1Signature2019" - kp_alice = generate_key_pair(algo=kp_algo) - signers = [] - did_doc_string = generate_did_document(kp_alice, algo=kp_algo) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": kp_algo - } - 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}") - - did_doc_string["verificationMethod"] = [] - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Removal of Verification Method associated with method specific id") - - print("7. PASS: Alice tries to update their DID Document by removing the Verification Method associated with the method specific id (Multibase Encoded PublicKey)") - - kp_algo = "Ed25519Signature2020" - kp_alice = generate_key_pair(algo=kp_algo) - signers = [] - did_doc_string = generate_did_document(kp_alice, algo=kp_algo) - did_doc_alice = did_doc_string["id"] - did_doc_alice_vm = did_doc_string["verificationMethod"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": kp_algo - } - 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}") - - did_doc_string["verificationMethod"] = [] - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Removal of Verification Method associated with method specific id") - - print("--- Test Completed ---\n") - -def bjj_signature_test(): - print("\n--1. PASS: Create a DID using BabyJubJub Key Pair--\n") - - kp_alice = generate_key_pair("BJJSignature2021") - signers = [] - did_doc_string = generate_did_document(kp_alice, "BJJSignature2021") - did_doc_alice = did_doc_string["id"] - signPair_alice = { - "kp": kp_alice, - "verificationMethodId": did_doc_string["verificationMethod"][0]["id"], - "signing_algo": "BJJSignature2021" - } - 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}") - - print("\n--2. PASS: Create a Schema using BabyJubJub Key Pair--\n") - - schema_doc, schema_proof = generate_schema_document( - kp_alice, - did_doc_alice, - did_doc_string["verificationMethod"][0]["id"], - algo="BJJSignature2021" - ) - create_schema_cmd = form_create_schema_tx( - schema_doc, - schema_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - schema_doc_id = schema_doc["id"] - run_blockchain_command(create_schema_cmd, f"Registering Schema with Id: {schema_doc_id}") - - print("\n--3. PASS: Create a Credential Status using BabyJubJub Key Pair--\n") - - cred_doc, cred_proof = generate_cred_status_document( - kp_alice, - did_doc_alice, - did_doc_string["verificationMethod"][0]["id"], - algo="BJJSignature2021" - ) - register_cred_status_cmd = form_create_cred_status_tx( - cred_doc, - cred_proof, - DEFAULT_BLOCKCHAIN_ACCOUNT_NAME - ) - cred_id = cred_doc["id"] - run_blockchain_command(register_cred_status_cmd, f"Registering Credential status with Id: {cred_id}") - - print("\n--4. PASS: Update a DID using BabyJubJub Key Pair--\n") - did_doc_string["alsoKnownAs"] = ["http://example.com"] - signers = [] - signers.append(signPair_alice) - update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(update_tx_cmd, f"Bob (non-controller) attempts to update Org DID with Id: {did_doc_alice}") - - print("\n--5. PASS: Deactivate a DID using BabyJubJub Key Pair--\n") - signers = [] - signers.append(signPair_alice) - deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_alice, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME) - run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Org's DID with Id: {did_doc_alice}") diff --git a/tests/e2e/ssi_tests/generate_doc.py b/tests/e2e/ssi_tests/generate_doc.py deleted file mode 100644 index ccd9e37..0000000 --- a/tests/e2e/ssi_tests/generate_doc.py +++ /dev/null @@ -1,216 +0,0 @@ -import os -import sys -sys.path.insert(1, os.getcwd()) - -import json -from utils import run_command, generate_document_id, get_document_signature, \ - secp256k1_pubkey_to_address - -ED25519_CONTEXT = "https://w3id.org/security/suites/ed25519-2020/v1" -DID_CONTEXT = "https://www.w3.org/ns/did/v1" -SECP256K1_RECOVERY_CONTEXT = "https://ns.did.ai/suites/secp256k1-2020/v1" -SECP256K1_VER_KEY_2019_CONTEXT = "https://ns.did.ai/suites/secp256k1-2019/v1" -BBS_CONTEXT = "https://ns.did.ai/suites/bls12381-2020/v1" -CREDENTIAL_STATUS_CONTEXT = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/CredentialStatus.jsonld" -CREDENTIAL_SCHEMA_CONTEXT = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/CredentialSchema.jsonld" -BJJ_CONTEXT = "https://raw.githubusercontent.com/hypersign-protocol/hypersign-contexts/main/BabyJubJubKey2021.jsonld" - -def generate_did_document(key_pair, algo="Ed25519Signature2020", bech32prefix="hid", is_uuid=False): - base_document = { - "context" : [ - DID_CONTEXT, - ], - "id": "", - "controller": [], - "verificationMethod": [], - "authentication": [], - } - if algo == "Ed25519Signature2020": - base_document["context"].append(ED25519_CONTEXT) - if algo == "EcdsaSecp256k1RecoverySignature2020": - base_document["context"].append(SECP256K1_RECOVERY_CONTEXT) - if algo == "EcdsaSecp256k1Signature2019": - base_document["context"].append(SECP256K1_VER_KEY_2019_CONTEXT) - if algo == "BbsBlsSignature2020": - base_document["context"].append(BBS_CONTEXT) - if algo == "BJJSignature2021": - base_document["context"].append(BJJ_CONTEXT) - did_id = generate_document_id("did", key_pair, algo, is_uuid) - - # Form the DID Document - vm_type = "" - if algo == "Ed25519Signature2020": - vm_type = "Ed25519VerificationKey2020" - elif algo == "EcdsaSecp256k1Signature2019": - vm_type = "EcdsaSecp256k1VerificationKey2019" - elif algo == "EcdsaSecp256k1RecoverySignature2020": - vm_type = "EcdsaSecp256k1RecoveryMethod2020" - elif algo == "BbsBlsSignature2020": - vm_type = "Bls12381G2Key2020" - elif algo == "BJJSignature2021": - vm_type = "BabyJubJubKey2021" - else: - raise Exception("unknown signing algorithm: " + algo) - - verification_method = {} - if algo == "EcdsaSecp256k1RecoverySignature2020": - verification_method = { - "id": "", - "type": "", - "controller": "", - "blockchainAccountId": "" - } - else: - verification_method = { - "id": "", - "type": "", - "controller": "", - "publicKeyMultibase": "" - } - - if algo == "EcdsaSecp256k1RecoverySignature2020": - verification_method["blockchainAccountId"] = "eip155:1:" + key_pair["ethereum_address"] - elif algo == "EcdsaSecp256k1Signature2019": - - if bech32prefix == "hid": - verification_method["blockchainAccountId"] = "cosmos:jagrat:" + \ - secp256k1_pubkey_to_address(key_pair["pub_key_base_64"], bech32prefix) - did_id = "did:hid:devnet:" + verification_method["blockchainAccountId"] - elif bech32prefix == "osmo": - verification_method["blockchainAccountId"] = "cosmos:osmosis-1:" + \ - secp256k1_pubkey_to_address(key_pair["pub_key_base_64"], bech32prefix) - did_id = "did:hid:devnet:" + verification_method["blockchainAccountId"] - else: - verification_method["blockchainAccountId"] = "" - - verification_method["publicKeyMultibase"] = key_pair["pub_key_multibase"] - else: - verification_method["publicKeyMultibase"] = key_pair["pub_key_multibase"] - - verification_method["controller"] = did_id - verification_method["type"] = vm_type - verification_method["id"] = did_id + "#k1" - - base_document["id"] = did_id - base_document["controller"] = [did_id] - base_document["verificationMethod"] = [verification_method] - base_document["authentication"] = [] - base_document["assertionMethod"] = [] - return base_document - -def generate_schema_document(key_pair, schema_author, vm, signature=None, algo="Ed25519Signature2020", updated_schema=None): - base_schema_doc = { - "@context": [CREDENTIAL_SCHEMA_CONTEXT], - "type": "https://schema.org/Person", - "modelVersion": "v1.0", - "id": "", - "name": "SomeCredentialSchema", - "author": "", - "authored": "2022-08-16T10:22:12Z", - "schema": { - "schema":"https://json-schema.org/draft-07/schema#", - "description":"Person Schema", - "type":"object", - "properties":"{\"fullName\":{\"type\":\"string\"},\"companyName\":{\"type\":\"string\"},\"center\":{\"type\":\"string\"},\"invoiceNumber\":{\"type\":\"string\"}}", - "required": [ - "fullName", - "center", - "invoiceNumber" - ], - } - } - - proof_type = "" - if algo == "Ed25519Signature2020": - proof_type = "Ed25519Signature2020" - base_schema_doc["@context"].append(ED25519_CONTEXT) - elif algo == "EcdsaSecp256k1Signature2019": - proof_type = "EcdsaSecp256k1Signature2019" - base_schema_doc["@context"].append(SECP256K1_VER_KEY_2019_CONTEXT) - elif algo == "EcdsaSecp256k1RecoverySignature2020": - proof_type = "EcdsaSecp256k1RecoverySignature2020" - base_schema_doc["@context"].append(SECP256K1_RECOVERY_CONTEXT) - elif algo == "BbsBlsSignature2020": - proof_type = "BbsBlsSignature2020" - base_schema_doc["@context"].append(BBS_CONTEXT) - elif algo == "BJJSignature2021": - proof_type = "BJJSignature2021" - else: - raise Exception("Invalid signing algo: " + algo) - - base_schema_proof = { - "type": proof_type, - "created": "2022-08-16T10:22:12Z", - "verificationMethod": "", - "proofValue": "", - "proofPurpose": "assertionMethod" - } - - schema_id = generate_document_id("schema", algo=algo) - base_schema_doc["id"] = schema_id - base_schema_doc["author"] = schema_author - base_schema_proof["verificationMethod"] = vm - - # Form Signature - if not updated_schema: - if not signature: - signature = get_document_signature(base_schema_doc, "schema", key_pair, algo, proofObj=base_schema_proof) - base_schema_proof["proofValue"] = signature - return base_schema_doc, base_schema_proof - else: - if not signature: - signature = get_document_signature(updated_schema, "schema", key_pair, algo, proofObj=base_schema_proof) - base_schema_proof["proofValue"] = signature - return updated_schema, base_schema_proof - -def generate_cred_status_document(key_pair, cred_author, vm, signature=None, algo="Ed25519Signature2020", updated_credstatus_doc=None): - base_cred_status_doc = { - "@context": [CREDENTIAL_STATUS_CONTEXT], - "id": "", - "issuer": "did:hid:devnet:z3861habXtUFLNuu6J7m5p8VPsoBMduYbYeUxfx9CnWZR", - "issuanceDate": "2022-08-16T09:37:12Z", - "credentialMerkleRootHash": "f35c3a4e3f1b8ba54ee3cf59d3de91b8b357f707fdb72a46473b65b46f92f80b" - } - - proof_type = "" - if algo == "Ed25519Signature2020": - proof_type = "Ed25519Signature2020" - base_cred_status_doc["@context"].append(ED25519_CONTEXT) - elif algo == "EcdsaSecp256k1Signature2019": - proof_type = "EcdsaSecp256k1Signature2019" - base_cred_status_doc["@context"].append(SECP256K1_VER_KEY_2019_CONTEXT) - elif algo == "EcdsaSecp256k1RecoverySignature2020": - proof_type = "EcdsaSecp256k1RecoverySignature2020" - base_cred_status_doc["@context"].append(SECP256K1_RECOVERY_CONTEXT) - elif algo == "BbsBlsSignature2020": - proof_type = "BbsBlsSignature2020" - base_cred_status_doc["@context"].append(BBS_CONTEXT) - elif algo == "BJJSignature2021": - proof_type = "BJJSignature2021" - else: - raise Exception("Invalid signing algo: " + algo) - - base_cred_status_proof = { - "type": proof_type, - "created": "2022-08-16T09:37:12Z", - "verificationMethod": "", - "proofValue": "", - "proofPurpose": "assertionMethod" - } - - cred_id = generate_document_id("cred-status", algo=algo) - base_cred_status_doc["id"] = cred_id - base_cred_status_doc["issuer"] = cred_author - base_cred_status_proof["verificationMethod"] = vm - - # Form Signature - if not updated_credstatus_doc: - if not signature: - signature = get_document_signature(base_cred_status_doc, "cred-status", key_pair, algo, proofObj=base_cred_status_proof) - base_cred_status_proof["proofValue"] = signature - return base_cred_status_doc, base_cred_status_proof - else: - if not signature: - signature = get_document_signature(updated_credstatus_doc, "cred-status", key_pair, algo, proofObj=base_cred_status_proof) - base_cred_status_proof["proofValue"] = signature - return updated_credstatus_doc, base_cred_status_proof \ No newline at end of file diff --git a/tests/e2e/ssi_tests/run.py b/tests/e2e/ssi_tests/run.py deleted file mode 100644 index 7363c0c..0000000 --- a/tests/e2e/ssi_tests/run.py +++ /dev/null @@ -1,54 +0,0 @@ -import sys -import contextlib -import os - -from e2e_tests import * -from utils import is_blockchain_active - -def generate_report(func): - print("Generating reports in artifacts directory...") - try: - report_dir = os.getcwd() + "/artifacts" - report_name = "e2e_ssi_module_test_report.txt" - report_path = report_dir + "/" + report_name - - if not os.path.exists(report_dir): - os.makedirs(report_dir) - - with open(report_path, 'w') as f, contextlib.redirect_stdout(f): - func() - print("Test report is generated.") - except Exception as e: - print("Test report generation failed\n", e) - -def run_all_tests(): - print("============= Running all x/ssi e2e tests ============== \n") - - create_did_test() - update_did_test() - schema_test() - deactivate_did() - credential_status_test() - caip10_ethereum_support_test() - caip10_cosmos_support_test() - vm_type_test() - method_specific_id_test() - unique_wallet_address_test() - key_agrement_test() - bbs_signature_test() - bjj_signature_test() - - print("============= All test cases completed successfully ============== \n") - -if __name__=='__main__': - # Assert if blockchain is currently running - is_blockchain_active(rpc_port=26657) - - try: - if len(sys.argv) > 1 and sys.argv[1] == "generate": - generate_report(run_all_tests) - else: - run_all_tests() - - except Exception as e: - raise(e) diff --git a/tests/e2e/ssi_tests/transactions.py b/tests/e2e/ssi_tests/transactions.py deleted file mode 100644 index c1ccc4e..0000000 --- a/tests/e2e/ssi_tests/transactions.py +++ /dev/null @@ -1,112 +0,0 @@ -import os -import sys -import time -sys.path.insert(1, os.getcwd()) -from utils import run_command - -import json -from utils import run_command, get_document_signature, get_sequence - -COMMON_CREATE_DID_TX_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 4000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() -COMMON_UPDATE_DID_TX_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 1000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() -COMMON_DEACTIVATE_DID_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 1000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() -COMMON_CREATE_SCHEMA_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 2000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() -COMMON_UPDATE_SCHEMA_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 2000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() -COMMON_REGISTER_CREDENTIAL_STATUS_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 2000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() -COMMON_UPDATE_CREDENTIAL_STATUS_COMMAND_FLAGS = "--chain-id hidnode --output json --broadcast-mode sync --fees 2000uhid --keyring-backend test --yes" + " --sequence " + get_sequence() - -def form_did_create_tx_multisig(diddoc, signPairs, blockchain_account): - time.sleep(5) - proofsStr = "" - - for signPair in signPairs: - vmId = signPair["verificationMethodId"] - signAlgo = signPair["signing_algo"] - - base_diddoc_proof = { - "type": signAlgo, - "created": "2022-08-16T10:22:12Z", - "verificationMethod": vmId, - "proofPurpose": "assertionMethod", - "proofValue": "", - } - - signature = get_document_signature(diddoc, "did", signPair["kp"], signAlgo, base_diddoc_proof) - base_diddoc_proof["proofValue"] = signature - proofsStr += f"'{json.dumps(base_diddoc_proof)}' " - - cmd_string = f"hid-noded tx ssi register-did '{json.dumps(diddoc)}' {proofsStr} --from {blockchain_account} " + COMMON_CREATE_DID_TX_COMMAND_FLAGS - return cmd_string - -def form_did_update_tx_multisig(diddoc, signPairs, blockchain_account): - proofsStr = "" - - for signPair in signPairs: - vmId = signPair["verificationMethodId"] - signAlgo = signPair["signing_algo"] - - base_diddoc_proof = { - "type": signAlgo, - "created": "2022-08-16T10:22:12Z", - "verificationMethod": vmId, - "proofPurpose": "assertionMethod", - "proofValue": "", - } - - signature = get_document_signature(diddoc, "did", signPair["kp"], signAlgo, base_diddoc_proof) - base_diddoc_proof["proofValue"] = signature - proofsStr += f"'{json.dumps(base_diddoc_proof)}' " - - version_id = query_did(diddoc["id"])["didDocumentMetadata"]["versionId"] - cmd_string = f"hid-noded tx ssi update-did '{json.dumps(diddoc)}' '{version_id}' {proofsStr} --from {blockchain_account} " + COMMON_UPDATE_DID_TX_COMMAND_FLAGS - return cmd_string - -def form_did_deactivate_tx_multisig(didId, signPairs, blockchain_account): - proofsStr = "" - didDocState = query_did(didId) - diddoc = didDocState["didDocument"] - version_id = didDocState["didDocumentMetadata"]["versionId"] - - for signPair in signPairs: - vmId = signPair["verificationMethodId"] - signAlgo = signPair["signing_algo"] - - base_diddoc_proof = { - "type": signAlgo, - "created": "2022-08-16T10:22:12Z", - "verificationMethod": vmId, - "proofPurpose": "assertionMethod", - "proofValue": "", - } - - signature = get_document_signature(diddoc, "did", signPair["kp"], signAlgo, base_diddoc_proof) - base_diddoc_proof["proofValue"] = signature - proofsStr += f"'{json.dumps(base_diddoc_proof)}' " - - cmd_string = f"hid-noded tx ssi deactivate-did '{didId}' '{version_id}' {proofsStr} --from {blockchain_account} " + COMMON_DEACTIVATE_DID_COMMAND_FLAGS - return cmd_string - -def form_create_schema_tx(schema_msg, schema_proof, blockchain_account): - cmd_string = f"hid-noded tx ssi create-schema '{json.dumps(schema_msg)}' '{json.dumps(schema_proof)}' --from {blockchain_account} " + COMMON_CREATE_SCHEMA_COMMAND_FLAGS - return cmd_string - -def form_update_schema_tx(schema_msg, schema_proof, blockchain_account): - cmd_string = f"hid-noded tx ssi update-schema '{json.dumps(schema_msg)}' '{json.dumps(schema_proof)}' --from {blockchain_account} " + COMMON_UPDATE_SCHEMA_COMMAND_FLAGS - return cmd_string - -def form_create_cred_status_tx(cred_msg, cred_proof, blockchain_account): - cmd_string = f"hid-noded tx ssi register-credential-status '{json.dumps(cred_msg)}' '{json.dumps(cred_proof)}' --from {blockchain_account} " + COMMON_REGISTER_CREDENTIAL_STATUS_COMMAND_FLAGS - return cmd_string - -def form_update_cred_status_tx(cred_msg, cred_proof, blockchain_account): - cmd_string = f"hid-noded tx ssi update-credential-status '{json.dumps(cred_msg)}' '{json.dumps(cred_proof)}' --from {blockchain_account} " + COMMON_UPDATE_CREDENTIAL_STATUS_COMMAND_FLAGS - return cmd_string - -def query_did(did_id): - cmd_string = f"hid-noded q ssi did {did_id} --output json" - did_doc, _ = run_command(cmd_string) - - if did_doc == "": - raise Exception(f"unable to fetch DID Document {did_id} from server") - - return json.loads(did_doc) \ No newline at end of file diff --git a/tests/e2e/ssi_tests/utils.py b/tests/e2e/ssi_tests/utils.py deleted file mode 100644 index 64a3067..0000000 --- a/tests/e2e/ssi_tests/utils.py +++ /dev/null @@ -1,144 +0,0 @@ -import subprocess -import json -import uuid - -def run_command(cmd_string): - if type(cmd_string) != str: - raise Exception("input parameter should be a string") - - cmd_run = subprocess.run(cmd_string, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - cmd_output = cmd_run.stdout.decode('utf-8')[:-1] - - # if cmd_run.returncode != 0: - # raise Exception(f"Command {cmd_string} returned error. Check the log: \n {cmd_output}") - - return cmd_output, cmd_run.returncode - -def get_sequence(): - add_cmd = "hid-noded keys show node1 -a --keyring-backend test" - address, _ = run_command(add_cmd) - cmd_string = "hid-noded q auth account " + address + " --output json" - cs, _ = run_command(cmd_string) - cs_dict = json.loads(cs) - return cs_dict["sequence"] - -def run_blockchain_command(cmd_string: str, transaction_name: str = None, expect_failure: bool = False, stateless_err: bool = False): - if not expect_failure: - try: - tx_out, _ = run_command(cmd_string) - tx_out_json = json.loads(tx_out) - if tx_out_json["code"] != 0: - error_log = tx_out_json["raw_log"] - raise Exception(f"Transaction failed: Log -> {error_log}") - print(f"{transaction_name} : transaction was successful\n") - except Exception as e: - print(f"{transaction_name} : Error while executing transaction command\n") - raise(e) - else: - try: - tx_out, return_code = run_command(cmd_string) - if return_code != 0 and not stateless_err: - raise Exception(f"tx command {cmd_string} failed") - else: - if not stateless_err: - tx_out_json = json.loads(tx_out) - tx_status_code = tx_out_json["code"] - tx_status_log = tx_out_json["raw_log"] - if tx_out_json["code"] == 0: - raise Exception(f"{transaction_name} transaction was expected to fail, but it didn't") - print(f"{transaction_name} : transaction failed as expected with error code {tx_status_code}. Log: {tx_status_log}\n") - else: - print(f"{transaction_name} : transaction failed as expected during stateless validation\n") - except Exception as e: - print(f"{transaction_name} : Error while executing transaction command\n") - raise(e) - -def generate_key_pair(algo="Ed25519Signature2020"): - cmd = "" - if algo == "Ed25519Signature2020": - cmd = "hid-noded ssi-tools ed25519 random" - elif algo == "EcdsaSecp256k1Signature2019": - cmd = "hid-noded ssi-tools secp256k1 random" - elif algo == "EcdsaSecp256k1RecoverySignature2020": - cmd = "hid-noded ssi-tools secp256k1 eth-hex-random" - elif algo == "BbsBlsSignature2020": - cmd = "hid-noded ssi-tools bbs random" - elif algo == "BJJSignature2021": - cmd = "hid-noded ssi-tools bjj random" - else: - raise Exception(algo + " is not a supported signing algorithm") - result_str, _ = run_command(cmd) - kp = json.loads(result_str) - return kp - -def add_keyAgreeemnt_pubKeyMultibase(verification_method, type): - if verification_method["type"] != "Ed25519VerificationKey2020": - raise Exception("verification method " + verification_method["id"] + " must be of type Ed25519VerificationKey2020") - - if type == "X25519KeyAgreementKey2020": - verification_method["type"] = "X25519KeyAgreementKey2020" - elif type == "X25519KeyAgreementKeyEIP5630": - verification_method["type"] = "X25519KeyAgreementKeyEIP5630" - else: - raise Exception("invalid key agreement type " + type) - - return verification_method - -def generate_document_id(doc_type: str, kp: dict = None, algo: str = "Ed25519Signature2020", is_uuid: bool =False): - id = "" - if not kp: - kp = generate_key_pair(algo) - - if is_uuid: - method_specific_id = str(uuid.uuid4()) - else: - if algo in ["EcdsaSecp256k1RecoverySignature2020"]: - method_specific_id = kp["ethereum_address"] - else: - method_specific_id = kp["pub_key_multibase"] - - if method_specific_id == None: - raise Exception("Public key is empty") - - if doc_type == "did": - id = "did:hid:devnet:" + method_specific_id - elif doc_type == "schema": - id = "sch:hid:devnet:" + method_specific_id + ":1.0" - elif doc_type == "cred-status": - id = "vc:hid:devnet:" + method_specific_id - else: - raise Exception("The argument `doc_type` only accepts the values: did, schema and cred-status") - - return id - -def is_blockchain_active(rpc_port): - import socket - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - assert s.connect_ex(('localhost', rpc_port)) == 0, f"hid-noded is not running" - -def get_document_signature(doc: dict, doc_type: str, key_pair: dict, algo: str = "ed25519", proofObj = None): - if algo in ["EcdsaSecp256k1RecoverySignature2020", "BJJSignature2021"]: - private_key = key_pair["priv_key_hex"] - else: - private_key = key_pair["priv_key_base_64"] - - if doc_type == "cred-status": - doc_cmd = "cred-status-doc" - elif doc_type == "schema": - doc_cmd = "schema-doc" - elif doc_type == "did": - doc_cmd = "did-doc" - else: - raise Exception("Invalid value for doc_type param: " + doc_type) - - cmd_string = f"hid-noded ssi-tools sign-ssi-doc {doc_cmd} '{json.dumps(doc)}' {private_key} '{json.dumps(proofObj)}'" - signature, _ = run_command(cmd_string) - - if signature == "": - raise Exception(f"Signature came empty while running command: {cmd_string}") - return signature - -def secp256k1_pubkey_to_address(pub_key, prefix): - cmd_string = f"hid-noded ssi-tools secp256k1 bech32-addr {pub_key} {prefix}" - addr, _ = run_command(cmd_string) - return addr diff --git a/x/ssi/client/cli/tx_ssi.go b/x/ssi/client/cli/tx_ssi.go index 89a261f..5efa041 100644 --- a/x/ssi/client/cli/tx_ssi.go +++ b/x/ssi/client/cli/tx_ssi.go @@ -110,7 +110,7 @@ func CmdRegisterDID() *cobra.Command { return fmt.Errorf("unsupported keyring backend for DID Document Alias Signing: %v", keyringBackend) } - kr, err := keyring.New("hid-node-app", keyringBackend, didAliasConfig.HidNodeConfigDir, nil, nil) + kr, err := keyring.New("hid-node-app", keyringBackend, didAliasConfig.HidNodeConfigDir, nil, clientCtx.Codec) if err != nil { return err } diff --git a/x/ssi/tests/common.go b/x/ssi/tests/common.go new file mode 100644 index 0000000..00e3c07 --- /dev/null +++ b/x/ssi/tests/common.go @@ -0,0 +1,57 @@ +package tests + +import ( + "context" + "strings" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testconstants "github.com/hypersign-protocol/hid-node/x/ssi/tests/constants" + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + + +func GenerateSchemaDocumentRPCElements(keyPair testcrypto.IKeyPair, authorId string, verficationMethodId string) *types.MsgRegisterCredentialSchema { + var schemaId string = "sch:" + testconstants.DidMethod + ":" + testconstants.ChainNamespace + ":" + strings.Split(authorId, ":")[3] + ":1.0" + var schemaDocument *types.CredentialSchemaDocument = &types.CredentialSchemaDocument{ + Type: "https://w3c-ccg.github.io/vc-json-schemas/schema/1.0/schema.json", + ModelVersion: "v1.0", + Name: "HS Credential", + Author: authorId, + Id: schemaId, + Authored: "2022-04-10T04:07:12Z", + Schema: &types.CredentialSchemaProperty{ + Schema: "https://json-schema.org/draft-07/schema#", + Description: "test", + Type: "Object", + Properties: "{myString:{type:string}}", + Required: []string{"myString"}, + AdditionalProperties: false, + }, + } + + var schemaProof *types.DocumentProof = &types.DocumentProof{ + Created: "2022-04-10T04:07:12Z", + VerificationMethod: verficationMethodId, + ProofPurpose: "assertionMethod", + } + + var schemaDocumentSignature string = testcrypto.SignGeneric(keyPair, schemaDocument, schemaProof) + + schemaProof.ProofValue = schemaDocumentSignature + + return &types.MsgRegisterCredentialSchema{ + CredentialSchemaDocument: schemaDocument, + CredentialSchemaProof: schemaProof, + TxAuthor: testconstants.Creator, + } +} + + +func UpdateDidTx(msgServer types.MsgServer, ctx context.Context, rpcElements *types.MsgUpdateDID, versionId string) error { + _, err := msgServer.UpdateDID(ctx, rpcElements) + if err != nil { + return err + } + return nil +} + diff --git a/x/ssi/tests/constants.go b/x/ssi/tests/constants.go new file mode 100644 index 0000000..08024c5 --- /dev/null +++ b/x/ssi/tests/constants.go @@ -0,0 +1,3 @@ +package tests + +const errExpectedToFail = "the tx was expected to fail, but it didn't" \ No newline at end of file diff --git a/x/ssi/tests/constants/constants.go b/x/ssi/tests/constants/constants.go new file mode 100644 index 0000000..7c54df6 --- /dev/null +++ b/x/ssi/tests/constants/constants.go @@ -0,0 +1,5 @@ +package constants + +const Creator = "hid1kxqk5ejca8nfpw8pg47484rppv359xh7qcasy4" +const DidMethod = "hid" +const ChainNamespace = "devnet" \ No newline at end of file diff --git a/x/ssi/tests/crypto/babyJubJub.go b/x/ssi/tests/crypto/babyJubJub.go new file mode 100644 index 0000000..32a9d08 --- /dev/null +++ b/x/ssi/tests/crypto/babyJubJub.go @@ -0,0 +1,38 @@ +package crypto + +import ( + "encoding/hex" + + "github.com/hypersign-protocol/hid-node/x/ssi/types" + "github.com/iden3/go-iden3-crypto/babyjub" + "github.com/multiformats/go-multibase" +) + +func GenerateBabyJubJubKeyPair() *BabyJubJubKeyPair { + // Generate Key Pair + babyJubjubPrivKey := babyjub.NewRandPrivKey() + babyJubjubPubKey := babyJubjubPrivKey.Public() + + // Prepare Priv key + var privKeyBytes [32]byte = babyJubjubPrivKey + var privKeyHex string = hex.EncodeToString(privKeyBytes[:]) + + // Prepare Public Key + var pubKeyHex string = babyJubjubPubKey.Compress().String() + + // Prepare Multibase Public Key + pubKeyBytes, err := hex.DecodeString(pubKeyHex) + if err != nil { + panic(err) + } + pubKeyMultibase, err := multibase.Encode(multibase.Base58BTC, pubKeyBytes) + if err != nil { + panic(err) + } + + return &BabyJubJubKeyPair{ + Type: types.BabyJubJubKey2021, + PublicKey: pubKeyMultibase, + PrivateKey: privKeyHex, + } +} diff --git a/x/ssi/tests/crypto/bbs_bls.go b/x/ssi/tests/crypto/bbs_bls.go new file mode 100644 index 0000000..cfa3d72 --- /dev/null +++ b/x/ssi/tests/crypto/bbs_bls.go @@ -0,0 +1,40 @@ +package crypto + +import ( + "crypto/sha256" + "encoding/base64" + + bbs "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/primitive/bbs12381g2pub" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + "github.com/multiformats/go-multibase" +) + +func GenerateBbsBlsKeyPair() *BbsBlsKeyPair { + pubKey, privKey, err := bbs.GenerateKeyPair(sha256.New, nil) + if err != nil { + panic(err) + } + + // Convert Public Key Object to Multibase + pubKeyBytes, err := pubKey.Marshal() + if err != nil { + panic(err) + } + + publicKeyMultibase, err := multibase.Encode(multibase.Base58BTC, pubKeyBytes) + if err != nil { + panic(err) + } + + // Convert Private Object to Bytes + privKeyBytes, err := privKey.Marshal() + if err != nil { + panic(err) + } + + return &BbsBlsKeyPair{ + Type: types.Bls12381G2Key2020, + PublicKey: publicKeyMultibase, + PrivateKey: base64.StdEncoding.EncodeToString(privKeyBytes), + } +} diff --git a/x/ssi/tests/crypto/ed25519.go b/x/ssi/tests/crypto/ed25519.go new file mode 100644 index 0000000..66eda29 --- /dev/null +++ b/x/ssi/tests/crypto/ed25519.go @@ -0,0 +1,33 @@ +package crypto + +import ( + "crypto/ed25519" + "crypto/rand" + "encoding/base64" + + "github.com/hypersign-protocol/hid-node/x/ssi/types" + "github.com/multiformats/go-multibase" +) + +func GenerateEd25519KeyPair() *Ed25519KeyPair { + publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + panic(err) + } + + var publicKeyWithHeader []byte + publicKeyWithHeader = append(publicKeyWithHeader, append([]byte{0xed, 0x01}, publicKey...)...) + + publicKeyMultibase, err := multibase.Encode(multibase.Base58BTC, publicKeyWithHeader) + if err != nil { + panic("Error while encoding multibase string") + } + + privKeyBase64String := base64.StdEncoding.EncodeToString(privateKey) + + return &Ed25519KeyPair{ + Type: types.Ed25519VerificationKey2020, + PublicKey: publicKeyMultibase, + PrivateKey: privKeyBase64String, + } +} diff --git a/x/ssi/tests/crypto/secp256k1.go b/x/ssi/tests/crypto/secp256k1.go new file mode 100644 index 0000000..d04f8a5 --- /dev/null +++ b/x/ssi/tests/crypto/secp256k1.go @@ -0,0 +1,48 @@ +package crypto + +import ( + "encoding/base64" + "encoding/hex" + + "github.com/cometbft/cometbft/crypto/secp256k1" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + "github.com/multiformats/go-multibase" + + ethercrypto "github.com/ethereum/go-ethereum/crypto" +) + +func GenerateSecp256k1KeyPair() *Secp256k1Pair { + privateKey := secp256k1.GenPrivKey() + + publicKey := privateKey.PubKey().Bytes() + + publicKeyMultibase, err := multibase.Encode(multibase.Base58BTC, publicKey) + if err != nil { + panic("Error while encoding multibase string") + } + return &Secp256k1Pair{ + Type: types.EcdsaSecp256k1VerificationKey2019, + PublicKey: publicKeyMultibase, + PrivateKey: base64.StdEncoding.EncodeToString(privateKey), + } +} + +func GenerateSecp256k1RecoveryKeyPair() *Secp256k1RecoveryPair { + privateKeyObj := secp256k1.GenPrivKey() + privateKey := privateKeyObj.Bytes() + + publicKeyCompressed := privateKeyObj.PubKey().Bytes() + + publicKeyUncompressed, err := ethercrypto.DecompressPubkey(publicKeyCompressed) + if err != nil { + panic(err) + } + ethereumAddress := ethercrypto.PubkeyToAddress(*publicKeyUncompressed).Hex() + + return &Secp256k1RecoveryPair{ + Type: types.EcdsaSecp256k1RecoveryMethod2020, + PublicKey: hex.EncodeToString(publicKeyCompressed), + PrivateKey: hex.EncodeToString(privateKey), + OptionalID: ethereumAddress, + } +} diff --git a/x/ssi/tests/crypto/signature.go b/x/ssi/tests/crypto/signature.go new file mode 100644 index 0000000..361dff7 --- /dev/null +++ b/x/ssi/tests/crypto/signature.go @@ -0,0 +1,87 @@ +package crypto + +import ( + ldcontext "github.com/hypersign-protocol/hid-node/x/ssi/ld-context" + cli "github.com/hypersign-protocol/hid-node/x/ssi/client/cli" + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + +func SignGeneric(keyPair IKeyPair, doc types.SsiMsg, docProof *types.DocumentProof) string { + docProof.Type = GetSignatureTypeFromVmType(keyPair.GetType()) + + signature, err := GetDocumentSignature(doc, docProof, keyPair.GetPrivateKey()) + if err != nil { + panic(err) + } + return signature +} + +func GetPublicKeyAndOptionalID(keyPair IKeyPair) (string, string) { + return keyPair.GetPublicKey(), keyPair.GetOptionalID() +} + +func GetDocumentSignature(doc types.SsiMsg, docProof *types.DocumentProof, privateKey string) (string, error) { + var signature string + + switch docProof.Type { + case types.Ed25519Signature2020: + var docBytes []byte + docBytes, err := ldcontext.Ed25519Signature2020Normalize(doc, docProof) + if err != nil { + return "", err + } + + signature, err = cli.GetEd25519Signature2020(privateKey, docBytes) + if err != nil { + return "", err + } + case types.EcdsaSecp256k1Signature2019: + var docBytes []byte + docBytes, err := ldcontext.EcdsaSecp256k1Signature2019Normalize(doc, docProof) + if err != nil { + return "", err + } + + signature, err = cli.GetEcdsaSecp256k1Signature2019(privateKey, docBytes) + if err != nil { + return "", err + } + case types.EcdsaSecp256k1RecoverySignature2020: + var docBytes []byte + docBytes, err := ldcontext.EcdsaSecp256k1RecoverySignature2020Normalize(doc, docProof) + if err != nil { + return "", err + } + + signature, err = cli.GetEcdsaSecp256k1RecoverySignature2020(privateKey, docBytes) + if err != nil { + return "", err + } + case types.BbsBlsSignature2020: + var docBytes []byte + docBytes, err := ldcontext.BbsBlsSignature2020Normalize(doc, docProof) + if err != nil { + return "", err + } + + signature, err = cli.GetBbsBlsSignature2020(privateKey, docBytes) + if err != nil { + return "", err + } + case types.BJJSignature2021: + var docBytes []byte + docBytes, err := ldcontext.BJJSignature2021Normalize(doc) + if err != nil { + return "", err + } + + signature, err = cli.GetBJJSignature2021(privateKey, docBytes) + if err != nil { + return "", err + } + default: + panic("recieved unsupported signing-algo. Supported algorithms are: [Ed25519Signature2020, EcdsaSecp256k1Signature2019, EcdsaSecp256k1RecoverySignature2020, BbsBlsSignature2020, BJJSignature2021]") + } + + return signature, nil +} diff --git a/x/ssi/tests/crypto/types.go b/x/ssi/tests/crypto/types.go new file mode 100644 index 0000000..ec524d0 --- /dev/null +++ b/x/ssi/tests/crypto/types.go @@ -0,0 +1,178 @@ +package crypto + +import ( + "fmt" + + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + +type IKeyPair interface { + GetType() string + GetPublicKey() string + GetPrivateKey() string + GetVerificationMethodId() string + GetOptionalID() string +} + +type Ed25519KeyPair struct { + Type string + PublicKey string + PrivateKey string + VerificationMethodId string + OptionalID string // If this field is not empty, it will override publicKey as the method specific id +} + +func (kp *Ed25519KeyPair) GetType() string { + return kp.Type +} + +func (kp *Ed25519KeyPair) GetPublicKey() string { + return kp.PublicKey +} + +func (kp *Ed25519KeyPair) GetPrivateKey() string { + return kp.PrivateKey +} + +func (kp *Ed25519KeyPair) GetVerificationMethodId() string { + return kp.VerificationMethodId +} + +func (kp *Ed25519KeyPair) GetOptionalID() string { + return kp.OptionalID +} + +type Secp256k1Pair struct { + Type string + PublicKey string + PrivateKey string + VerificationMethodId string + OptionalID string // If this field is not empty, it will override publicKey as the method specific id +} + +func (kp *Secp256k1Pair) GetType() string { + return kp.Type +} + +func (kp *Secp256k1Pair) GetPublicKey() string { + return kp.PublicKey +} + +func (kp *Secp256k1Pair) GetPrivateKey() string { + return kp.PrivateKey +} + +func (kp *Secp256k1Pair) GetVerificationMethodId() string { + return kp.VerificationMethodId +} + +func (kp *Secp256k1Pair) GetOptionalID() string { + return kp.OptionalID +} + + +type Secp256k1RecoveryPair struct { + Type string + PublicKey string + PrivateKey string + VerificationMethodId string + OptionalID string // If this field is not empty, it will override publicKey as the method specific id +} + +func (kp *Secp256k1RecoveryPair) GetType() string { + return kp.Type +} + +func (kp *Secp256k1RecoveryPair) GetPublicKey() string { + return kp.PublicKey +} + +func (kp *Secp256k1RecoveryPair) GetPrivateKey() string { + return kp.PrivateKey +} + +func (kp *Secp256k1RecoveryPair) GetVerificationMethodId() string { + return kp.VerificationMethodId +} + +func (kp *Secp256k1RecoveryPair) GetOptionalID() string { + return kp.OptionalID +} + +type BabyJubJubKeyPair struct { + Type string + PublicKey string + PrivateKey string + VerificationMethodId string + OptionalID string // If this field is not empty, it will override publicKey as the method specific id +} + +func (kp *BabyJubJubKeyPair) GetType() string { + return kp.Type +} + +func (kp *BabyJubJubKeyPair) GetPublicKey() string { + return kp.PublicKey +} + +func (kp *BabyJubJubKeyPair) GetPrivateKey() string { + return kp.PrivateKey +} + +func (kp *BabyJubJubKeyPair) GetVerificationMethodId() string { + return kp.VerificationMethodId +} + +func (kp *BabyJubJubKeyPair) GetOptionalID() string { + return kp.OptionalID +} + +type BbsBlsKeyPair struct { + Type string + PublicKey string + PrivateKey string + VerificationMethodId string + OptionalID string // If this field is not empty, it will override publicKey as the method specific id +} + +func (kp *BbsBlsKeyPair) GetType() string { + return kp.Type +} + +func (kp *BbsBlsKeyPair) GetPublicKey() string { + return kp.PublicKey +} + +func (kp *BbsBlsKeyPair) GetPrivateKey() string { + return kp.PrivateKey +} + +func (kp *BbsBlsKeyPair) GetVerificationMethodId() string { + return kp.VerificationMethodId +} + +func (kp *BbsBlsKeyPair) GetOptionalID() string { + return kp.OptionalID +} + + +func CollectKeysPairs(kps ...IKeyPair) []IKeyPair { + return kps +} + +func GetSignatureTypeFromVmType(vmType string) string { + switch vmType { + case types.Ed25519VerificationKey2020: + return types.Ed25519Signature2020 + case types.EcdsaSecp256k1VerificationKey2019: + return types.EcdsaSecp256k1Signature2019 + case types.EcdsaSecp256k1RecoveryMethod2020: + return types.EcdsaSecp256k1RecoverySignature2020 + case types.Bls12381G2Key2020: + return types.BbsBlsSignature2020 + case types.BabyJubJubKey2021: + return types.BJJSignature2021 + default: + panic(fmt.Sprintf("Unsupported vm Type: %v", vmType)) + } +} \ No newline at end of file diff --git a/x/ssi/tests/keeper.go b/x/ssi/tests/keeper.go new file mode 100644 index 0000000..78f6690 --- /dev/null +++ b/x/ssi/tests/keeper.go @@ -0,0 +1,53 @@ +package tests + +import ( + "testing" + + dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + typesparams "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + "github.com/stretchr/testify/require" +) + +func TestKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { + storeKey := sdk.NewKVStoreKey(types.StoreKey) + memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + + db := dbm.NewMemDB() + stateStore := store.NewCommitMultiStore(db) + stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) + stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) + require.NoError(t, stateStore.LoadLatestVersion()) + + registry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(registry) + + paramsSubspace := typesparams.NewSubspace(cdc, + types.Amino, + storeKey, + memStoreKey, + "SsiParams", + ) + k := keeper.NewKeeper( + cdc, + storeKey, + memStoreKey, + paramsSubspace, + ) + + ctx := sdk.NewContext(stateStore, + cmtproto.Header{ + ChainID: "hidnode", + }, false, log.NewNopLogger()) + + k.SetChainNamespace(&ctx, "devnet") + return k, ctx +} diff --git a/x/ssi/tests/ssi/credential_schema.go b/x/ssi/tests/ssi/credential_schema.go new file mode 100644 index 0000000..fee604e --- /dev/null +++ b/x/ssi/tests/ssi/credential_schema.go @@ -0,0 +1,57 @@ +package ssi + +import ( + "strings" + + ldcontext "github.com/hypersign-protocol/hid-node/x/ssi/ld-context" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + + testconstants "github.com/hypersign-protocol/hid-node/x/ssi/tests/constants" + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" +) + +func GenerateSchema(keyPair testcrypto.IKeyPair, authorId string) *types.CredentialSchemaDocument { + var schemaId = "sch:" + testconstants.DidMethod + ":" + testconstants.ChainNamespace + ":" + strings.Split(authorId, ":")[3] + ":" + "1.0" + var vmContextUrl = GetContextFromKeyPair(keyPair) + + var credentialSchema *types.CredentialSchemaDocument = &types.CredentialSchemaDocument{ + Context: []string{ + ldcontext.CredentialSchemaContext, + vmContextUrl, + }, + Type: "https://w3c-ccg.github.io/vc-json-schemas/v1/schema/1.0/schema.json", + ModelVersion: "1.0", + Id: schemaId, + Name: "SomeSchema", + Author: authorId, + Authored: "2022-04-10T02:07:12Z", + Schema: &types.CredentialSchemaProperty{ + Schema: "http://json-schema.org/draft-07/schema", + Description: "Student ID Credential Schema", + Type: "https://schema.org/object", + Properties: "{\"jayeshL\":{\"type\":\"string\"}}", + Required: []string{"jayeshL"}, + AdditionalProperties: false, + }, + } + + return credentialSchema +} + +func GenerateSchemaRPCElements(keyPair testcrypto.IKeyPair, credentialSchema *types.CredentialSchemaDocument, verficationMethod *types.VerificationMethod) *types.MsgRegisterCredentialSchema { + + var credentialProof *types.DocumentProof = &types.DocumentProof{ + Created: "2022-04-10T04:07:12Z", + VerificationMethod: verficationMethod.Id, + ProofPurpose: "assertionMethod", + } + + var credentialStatusSignature string = testcrypto.SignGeneric(keyPair, credentialSchema, credentialProof) + credentialProof.ProofValue = credentialStatusSignature + + return &types.MsgRegisterCredentialSchema{ + CredentialSchemaDocument: credentialSchema, + CredentialSchemaProof: credentialProof, + TxAuthor: testconstants.Creator, + } +} diff --git a/x/ssi/tests/ssi/credential_status.go b/x/ssi/tests/ssi/credential_status.go new file mode 100644 index 0000000..8b295ef --- /dev/null +++ b/x/ssi/tests/ssi/credential_status.go @@ -0,0 +1,67 @@ +package ssi + +import ( + "crypto/sha256" + "encoding/hex" + "strings" + + ldcontext "github.com/hypersign-protocol/hid-node/x/ssi/ld-context" + testconstants "github.com/hypersign-protocol/hid-node/x/ssi/tests/constants" + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + +func GenerateCredentialStatus(keyPair testcrypto.IKeyPair, issuerId string) *types.CredentialStatusDocument { + var credentialId = "vc:" + testconstants.DidMethod + ":" + testconstants.ChainNamespace + ":" + strings.Split(issuerId, ":")[3] + var credHash = sha256.Sum256([]byte("Hash1234")) + var vmContextUrl = GetContextFromKeyPair(keyPair) + + var credentialStatus *types.CredentialStatusDocument = &types.CredentialStatusDocument{ + Context: []string{ + ldcontext.CredentialStatusContext, + vmContextUrl, + }, + Id: credentialId, + Remarks: "Live", + Revoked: false, + Suspended: false, + Issuer: issuerId, + IssuanceDate: "2022-04-10T04:07:12Z", + CredentialMerkleRootHash: hex.EncodeToString(credHash[:]), + } + return credentialStatus +} + +func GenerateRegisterCredStatusRPCElements(keyPair testcrypto.IKeyPair, credentialStatus *types.CredentialStatusDocument, verficationMethod *types.VerificationMethod) *types.MsgRegisterCredentialStatus { + var credentialProof *types.DocumentProof = &types.DocumentProof{ + Created: "2022-04-10T04:07:12Z", + VerificationMethod: verficationMethod.Id, + ProofPurpose: "assertionMethod", + } + + var credentialStatusSignature string = testcrypto.SignGeneric(keyPair, credentialStatus, credentialProof) + credentialProof.ProofValue = credentialStatusSignature + + return &types.MsgRegisterCredentialStatus{ + CredentialStatusDocument: credentialStatus, + CredentialStatusProof: credentialProof, + TxAuthor: testconstants.Creator, + } +} + +func GenerateUpdateCredStatusRPCElements(keyPair testcrypto.IKeyPair, credentialStatus *types.CredentialStatusDocument, verficationMethod *types.VerificationMethod) *types.MsgUpdateCredentialStatus { + var credentialProof *types.DocumentProof = &types.DocumentProof{ + Created: "2022-04-10T04:07:12Z", + VerificationMethod: verficationMethod.Id, + ProofPurpose: "assertionMethod", + } + + var credentialStatusSignature string = testcrypto.SignGeneric(keyPair, credentialStatus, credentialProof) + credentialProof.ProofValue = credentialStatusSignature + + return &types.MsgUpdateCredentialStatus{ + CredentialStatusDocument: credentialStatus, + CredentialStatusProof: credentialProof, + TxAuthor: testconstants.Creator, + } +} diff --git a/x/ssi/tests/ssi/did_document.go b/x/ssi/tests/ssi/did_document.go new file mode 100644 index 0000000..a8aa980 --- /dev/null +++ b/x/ssi/tests/ssi/did_document.go @@ -0,0 +1,133 @@ +package ssi + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + + testconstants "github.com/hypersign-protocol/hid-node/x/ssi/tests/constants" + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + +func GetRegisterDidDocumentRPC( + didDocument *types.DidDocument, + keyPairs []testcrypto.IKeyPair, +) *types.MsgRegisterDID { + var proofs []*types.DocumentProof = getDocumentProof( + didDocument, + keyPairs, + ) + + return &types.MsgRegisterDID{ + DidDocument: didDocument, + DidDocumentProofs: proofs, + TxAuthor: testconstants.Creator, + } +} + +func GetUpdateDidDocumentRPC( + k *keeper.Keeper, + ctx sdk.Context, + didDocument *types.DidDocument, + keyPairs []testcrypto.IKeyPair, +) *types.MsgUpdateDID { + // Get Version ID + didDocFromState := QueryDid(k, ctx, didDocument.Id) + versionId := didDocFromState.DidDocumentMetadata.VersionId + + var proofs []*types.DocumentProof = getDocumentProof( + didDocument, + keyPairs, + ) + + return &types.MsgUpdateDID{ + DidDocument: didDocument, + DidDocumentProofs: proofs, + TxAuthor: testconstants.Creator, + VersionId: versionId, + } +} + +func GetDeactivateDidDocumentRPC( + k *keeper.Keeper, + ctx sdk.Context, + didDocument *types.DidDocument, + keyPairs []testcrypto.IKeyPair, +) *types.MsgDeactivateDID { + // Get Version ID + didId := didDocument.Id + didDocFromState := QueryDid(k, ctx, didId) + versionId := didDocFromState.DidDocumentMetadata.VersionId + + var proofs []*types.DocumentProof = getDocumentProof( + didDocument, + keyPairs, + ) + + return &types.MsgDeactivateDID{ + DidDocumentId: didId, + DidDocumentProofs: proofs, + TxAuthor: testconstants.Creator, + VersionId: versionId, + } +} + +func GenerateDidDoc(keyPair testcrypto.IKeyPair) *types.DidDocument { + publicKey, optionalID := testcrypto.GetPublicKeyAndOptionalID(keyPair) + var didId string + if optionalID == "" { + didId = "did:" + testconstants.DidMethod + ":" + testconstants.ChainNamespace + ":" + publicKey + } else { + didId = "did:" + testconstants.DidMethod + ":" + testconstants.ChainNamespace + ":" + optionalID + } + + var verificationMethodId string = didId + "#" + "key-1" + + var vmType string = keyPair.GetType() + + var vm = &types.VerificationMethod{ + Id: verificationMethodId, + Type: vmType, + Controller: didId, + PublicKeyMultibase: publicKey, + } + + if optionalID != "" { + if vm.Type == types.EcdsaSecp256k1RecoveryMethod2020 { + vm.PublicKeyMultibase = "" + vm.BlockchainAccountId = "eip155:1:" + optionalID + } + if vm.Type == types.EcdsaSecp256k1VerificationKey2019 { + vm.BlockchainAccountId = "cosmos:prajna:" + optionalID + } + } + + vmContextUrl := GetContextFromKeyPair(keyPair) + var didDocument *types.DidDocument = &types.DidDocument{ + Context: []string{ + "https://www.w3.org/ns/did/v1", + vmContextUrl, + }, + Id: didId, + Controller: []string{}, + VerificationMethod: []*types.VerificationMethod{ + vm, + }, + } + + return didDocument +} + +func QueryDid(k *keeper.Keeper, ctx sdk.Context, Id string) *types.DidDocumentState { + resolvedDidDocument, errResolve := k.DidDocumentByID(&ctx, &types.QueryDidDocumentRequest{ + DidId: Id, + }) + if errResolve != nil { + panic(errResolve) + } + + return &types.DidDocumentState{ + DidDocument: resolvedDidDocument.DidDocument, + DidDocumentMetadata: resolvedDidDocument.DidDocumentMetadata, + } +} diff --git a/x/ssi/tests/ssi/document_proof.go b/x/ssi/tests/ssi/document_proof.go new file mode 100644 index 0000000..a97d69e --- /dev/null +++ b/x/ssi/tests/ssi/document_proof.go @@ -0,0 +1,25 @@ +package ssi + +import ( + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + "github.com/hypersign-protocol/hid-node/x/ssi/types" +) + +func getDocumentProof(ssiDoc types.SsiMsg, keyPairs []testcrypto.IKeyPair) []*types.DocumentProof { + var docProofs []*types.DocumentProof + + for i := 0; i < len(keyPairs); i++ { + var genericDocumentProof *types.DocumentProof = &types.DocumentProof{ + Type: testcrypto.GetSignatureTypeFromVmType(keyPairs[i].GetType()), + Created: "2023-08-16T09:37:12Z", + ProofPurpose: "assertionMethod", + } + genericDocumentProof.VerificationMethod = keyPairs[i].GetVerificationMethodId() + + signature := testcrypto.SignGeneric(keyPairs[i], ssiDoc, genericDocumentProof) + genericDocumentProof.ProofValue = signature + + docProofs = append(docProofs, genericDocumentProof) + } + return docProofs +} diff --git a/x/ssi/tests/ssi/types.go b/x/ssi/tests/ssi/types.go new file mode 100644 index 0000000..5d8e4a5 --- /dev/null +++ b/x/ssi/tests/ssi/types.go @@ -0,0 +1,2 @@ +package ssi + diff --git a/x/ssi/tests/ssi/utils.go b/x/ssi/tests/ssi/utils.go new file mode 100644 index 0000000..0d4199d --- /dev/null +++ b/x/ssi/tests/ssi/utils.go @@ -0,0 +1,23 @@ +package ssi + +import ( + ldcontext "github.com/hypersign-protocol/hid-node/x/ssi/ld-context" + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" +) + +func GetContextFromKeyPair(kp testcrypto.IKeyPair) string { + switch kp.(type) { + case *testcrypto.Ed25519KeyPair: + return ldcontext.Ed25519Context2020 + case *testcrypto.Secp256k1Pair: + return ldcontext.Secp256k12019Context + case *testcrypto.Secp256k1RecoveryPair: + return ldcontext.Secp256k1Recovery2020Context + case *testcrypto.BabyJubJubKeyPair: + return ldcontext.BabyJubJubKey2021Context + case *testcrypto.BbsBlsKeyPair: + return ldcontext.BbsSignature2020Context + default: + panic("Unsupported IKeyPair type") + } +} diff --git a/x/ssi/tests/tx_credential_status_test.go b/x/ssi/tests/tx_credential_status_test.go new file mode 100644 index 0000000..d0fc988 --- /dev/null +++ b/x/ssi/tests/tx_credential_status_test.go @@ -0,0 +1,261 @@ +package tests + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testssi "github.com/hypersign-protocol/hid-node/x/ssi/tests/ssi" +) + +func TestCredentialStatusTC1(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Alice creates a DID, deactivates it and attempts to create a credential status document") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a credential status with her deactivated DID Document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} + +func TestCredentialStatusTC2(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("PASS: Alice creates a DID and attempts to create a credential status document") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a credential status document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestCredentialStatusTC3(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Alice attempts to update credential status without any changes") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a credential status document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to update credential status document without changes") + updateCredentialStatusRPCElements := testssi.GenerateUpdateCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.UpdateCredentialStatus(goCtx, updateCredentialStatusRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} + +func TestCredentialStatusTC4(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("PASS: Alice suspends the credential status using one of his VMs and then un-suspends it") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a credential status document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to suspend her credential status") + credentialStatus.Suspended = true + credentialStatus.Remarks = "Test" + updateCredentialStatusRPCElements := testssi.GenerateUpdateCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.UpdateCredentialStatus(goCtx, updateCredentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to un-suspend her credential status") + credentialStatus.Suspended = false + credentialStatus.Remarks = "Test" + updateCredentialStatusRPCElements = testssi.GenerateUpdateCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.UpdateCredentialStatus(goCtx, updateCredentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + +} + +func TestCredentialStatusTC5(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("Alice revokes the credential status using one of his VMs (PASS) and then attempts to un-revoke it (FAIL)") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a credential status document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to revokes her credential status") + credentialStatus.Revoked = true + credentialStatus.Remarks = "Test" + updateCredentialStatusRPCElements := testssi.GenerateUpdateCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.UpdateCredentialStatus(goCtx, updateCredentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to un-revokes her credential status") + credentialStatus.Revoked = false + credentialStatus.Remarks = "Test" + updateCredentialStatusRPCElements = testssi.GenerateUpdateCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.UpdateCredentialStatus(goCtx, updateCredentialStatusRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + +} + +func TestCredentialStatusTC6(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Alice attempts to update her credential status by changing Merkle Root Hash") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a credential status document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to update her credential status by changing Merkle Root Hash") + credentialStatus.CredentialMerkleRootHash = "9de17abaffe74f4675c738f5d69c28a329aff8721cb0ed4808d8616e26280ed9" + updateCredentialStatusRPCElements := testssi.GenerateUpdateCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.UpdateCredentialStatus(goCtx, updateCredentialStatusRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + +} + + diff --git a/x/ssi/tests/tx_deactivate_did_test.go b/x/ssi/tests/tx_deactivate_did_test.go new file mode 100644 index 0000000..7fe8f1e --- /dev/null +++ b/x/ssi/tests/tx_deactivate_did_test.go @@ -0,0 +1,104 @@ +package tests + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testssi "github.com/hypersign-protocol/hid-node/x/ssi/tests/ssi" +) + +func TestDeactivateDidTC1(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("PASS: Alice creates an Org DID with herself and Bob being the Controller. Bob attempts to deactivate it") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("Bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx = testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create Organization DID") + org_kp := testcrypto.GenerateEd25519KeyPair() + org_didDoc := testssi.GenerateDidDoc(org_kp) + org_didDoc.Controller = []string{alice_didDoc.Id, bob_didDoc.Id} + org_didDoc.VerificationMethod = []*types.VerificationMethod{} + didDocTx = testssi.GetRegisterDidDocumentRPC(org_didDoc, []testcrypto.IKeyPair{alice_kp, bob_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Bob attempts to deactivate DID Document") + rpcElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err = msgServer.DeactivateDID(goCtx, rpcElements) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestDeactivateDidTC2(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Alice creates a DID for herself. She deactivates it and attempts to update it.") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to update it") + alice_didDoc.CapabilityDelegation = append(alice_didDoc.CapabilityDelegation, alice_didDoc.VerificationMethod[0].Id) + updateDidElements := testssi.GetUpdateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} diff --git a/x/ssi/tests/tx_register_did_test.go b/x/ssi/tests/tx_register_did_test.go new file mode 100644 index 0000000..ee841bb --- /dev/null +++ b/x/ssi/tests/tx_register_did_test.go @@ -0,0 +1,237 @@ +package tests + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testssi "github.com/hypersign-protocol/hid-node/x/ssi/tests/ssi" +) + +func TestCreateDidTC1(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + var didDocTx *types.MsgRegisterDID + var err error + t.Log("1. Alice has a registered DID Document where Alice is the controller. Bob tries to register their DID Document by keeping both Alice and Bob as controllers.") + t.Log("Create Alice's DID") + + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + + didDocTx = testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("1.1 FAIL: Only Bob's signature is sent") + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = []string{alice_didDoc.Id, bob_didDoc.Id} + t.Logf("Bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + + didDocTx = testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + + t.Log("1.2 PASS: Both Alice's and Bob's signatures are sent") + didDocTx = testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{alice_kp, bob_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestCreateDidTC2(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("2. PASS: Alice has a registered DID Document where they are the controller. They attempt to create an organization DID, in which they are the only controller and the verification method field is empty.") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create Organization DID") + org_kp := testcrypto.GenerateEd25519KeyPair() + org_didDoc := testssi.GenerateDidDoc(org_kp) + org_didDoc.Controller = []string{alice_didDoc.Id} + org_didDoc.VerificationMethod = []*types.VerificationMethod{} + + t.Logf("Organization DID Id: %s", org_didDoc.Id) + didDocTx = testssi.GetRegisterDidDocumentRPC(org_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestCreateDidTC3(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("3. Alice has a registered DID Document where they are the controller. Alice tries to register an Org DID Document where they are the sole controller, and there are two verification Methods, of type EcdsaSecp256k1RecoveryMethod2020, and Alice is the controller for each one of them.") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + wallet1_kp := testcrypto.GenerateEd25519KeyPair() + wallet1_didDoc := testssi.GenerateDidDoc(wallet1_kp) + wallet1_didDoc.VerificationMethod[0].Controller = alice_didDoc.Id + t.Logf("Wallet 1 DID Id: %s", wallet1_didDoc.Id) + wallet1_kp.VerificationMethodId = wallet1_didDoc.VerificationMethod[0].Id + + wallet2_kp := testcrypto.GenerateSecp256k1KeyPair() + wallet2_didDoc := testssi.GenerateDidDoc(wallet2_kp) + wallet2_didDoc.VerificationMethod[0].Controller = alice_didDoc.Id + t.Logf("Wallet 2 DID Id: %s", wallet2_didDoc.Id) + wallet2_kp.VerificationMethodId = wallet2_didDoc.VerificationMethod[0].Id + + t.Log("Create Org DID") + org_kp := testcrypto.GenerateEd25519KeyPair() + org_didDoc := testssi.GenerateDidDoc(org_kp) + org_didDoc.Controller = []string{alice_didDoc.Id} + org_didDoc.VerificationMethod = []*types.VerificationMethod{ + wallet1_didDoc.VerificationMethod[0], + wallet2_didDoc.VerificationMethod[0], + } + + t.Log("3.1 FAIL: Signature is provided by only one of the VMs.") + t.Logf("Org DID Id: %s", org_didDoc.Id) + didDocTx2 := testssi.GetRegisterDidDocumentRPC(org_didDoc, []testcrypto.IKeyPair{wallet2_kp}) + _, err2 := msgServer.RegisterDID(goCtx, didDocTx2) + if err2 == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + + t.Log("3.2 PASS: Signature is provided by both VMs.") + t.Logf("Org DID Id: %s", org_didDoc.Id) + didDocTx2 = testssi.GetRegisterDidDocumentRPC(org_didDoc, []testcrypto.IKeyPair{wallet1_kp, wallet2_kp}) + _, err3 := msgServer.RegisterDID(goCtx, didDocTx2) + if err3 != nil { + t.Log(err3) + t.FailNow() + } +} + +func TestCreateDidTC4(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("4. Alice creates an Org DID where Alice is the controller, and she adds a verification method of her friend Eve.") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create Eve's DID") + eve_kp := testcrypto.GenerateEd25519KeyPair() + eve_didDoc := testssi.GenerateDidDoc(eve_kp) + eve_didDoc.Controller = append(eve_didDoc.Controller, eve_didDoc.Id) + t.Logf("eve's DID Id: %s", eve_didDoc.Id) + eve_kp.VerificationMethodId = eve_didDoc.VerificationMethod[0].Id + didDocTx2 := testssi.GetRegisterDidDocumentRPC(eve_didDoc, []testcrypto.IKeyPair{eve_kp}) + _, err2 := msgServer.RegisterDID(goCtx, didDocTx2) + if err2 != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create a random DID Document with Alice being the controller, and Eve's VM being the only Verification Method") + random_kp := testcrypto.GenerateEd25519KeyPair() + random_didDoc := testssi.GenerateDidDoc(random_kp) + random_didDoc.Controller = []string{alice_didDoc.Id} + random_didDoc.VerificationMethod = []*types.VerificationMethod{ + eve_didDoc.VerificationMethod[0], + } + t.Logf("Random DID Id: %s", random_didDoc.Id) + random_kp.VerificationMethodId = random_didDoc.VerificationMethod[0].Id + + t.Log("4.1 FAIL: Only Alice sends their singature") + didDocTx3 := testssi.GetRegisterDidDocumentRPC(random_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err3 := msgServer.RegisterDID(goCtx, didDocTx3) + if err3 == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + + t.Log("4.2 PASS: Both Alice and Eve send their singatures") + didDocTx3 = testssi.GetRegisterDidDocumentRPC(random_didDoc, []testcrypto.IKeyPair{alice_kp, eve_kp}) + _, err4 := msgServer.RegisterDID(goCtx, didDocTx3) + if err4 != nil { + t.Log(err4) + t.FailNow() + } +} + +func TestCreateDidTC5(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("5. FAIL: Alice tries to register a DID Document with duplicate publicKeyMultibase of type Ed25519VerificationKey2020.") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + alice_didDoc.VerificationMethod = append(alice_didDoc.VerificationMethod, alice_didDoc.VerificationMethod[0]) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} diff --git a/x/ssi/tests/tx_schema_test.go b/x/ssi/tests/tx_schema_test.go new file mode 100644 index 0000000..e0984d8 --- /dev/null +++ b/x/ssi/tests/tx_schema_test.go @@ -0,0 +1,199 @@ +package tests + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testssi "github.com/hypersign-protocol/hid-node/x/ssi/tests/ssi" +) + +func TestSchemaTC1(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Alice creates a DID, deactivates it and attempts to create a schema") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice attempts to deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Alice creates a schema with her deactivated DID Document") + credentialSchema := testssi.GenerateSchema(alice_kp, alice_didDoc.Id) + schemaRPCElements := testssi.GenerateSchemaRPCElements(alice_kp, credentialSchema, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} + +func TestSchemaTC2(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("PASS: Bob creates a DID and attempts to register a Schema") + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Bob creates a schema") + credentialSchema := testssi.GenerateSchema(bob_kp, bob_didDoc.Id) + schemaRPCElements := testssi.GenerateSchemaRPCElements(bob_kp, credentialSchema, bob_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestSchemaTC3(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Bob creates a Schema where the name field is not in Pascal Case") + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + credentialSchema := testssi.GenerateSchema(bob_kp, bob_didDoc.Id) + credentialSchema.Name = "Day Pass" + schemaRPCElements := testssi.GenerateSchemaRPCElements(bob_kp, credentialSchema, bob_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} + +func TestSchemaTC4(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Bob creates a Schema where the property field is some random string") + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + credentialSchema := testssi.GenerateSchema(bob_kp, bob_didDoc.Id) + credentialSchema.Schema.Properties = "someString" + schemaRPCElements := testssi.GenerateSchemaRPCElements(bob_kp, credentialSchema, bob_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} + +func TestSchemaTC5(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Bob creates a Schema where the property field is a valid JSON, but one of the attributes has an invalid sub-attribute") + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + credentialSchema := testssi.GenerateSchema(bob_kp, bob_didDoc.Id) + credentialSchema.Schema.Properties = "{\"fullName\":{\"type\":\"string\",\"sda\":\"string\"},\"companyName\":{\"type\":\"string\"},\"center\":{\"type\":\"string\"},\"invoiceNumber\":{\"type\":\"string\"}}" + schemaRPCElements := testssi.GenerateSchemaRPCElements(bob_kp, credentialSchema, bob_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} + +func TestSchemaTC6(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("FAIL: Bob creates a Schema where the property field is a valid JSON, but `type` sub-attribute is missing") + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + credentialSchema := testssi.GenerateSchema(bob_kp, bob_didDoc.Id) + credentialSchema.Schema.Properties = "{\"fullName\":{\"format\":\"string\"},\"companyName\":{\"type\":\"string\"},\"center\":{\"type\":\"string\"},\"invoiceNumber\":{\"type\":\"string\"}}" + schemaRPCElements := testssi.GenerateSchemaRPCElements(bob_kp, credentialSchema, bob_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} \ No newline at end of file diff --git a/x/ssi/tests/tx_update_did_test.go b/x/ssi/tests/tx_update_did_test.go new file mode 100644 index 0000000..58e68f9 --- /dev/null +++ b/x/ssi/tests/tx_update_did_test.go @@ -0,0 +1,138 @@ +package tests + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + "github.com/hypersign-protocol/hid-node/x/ssi/types" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testssi "github.com/hypersign-protocol/hid-node/x/ssi/tests/ssi" +) + +func TestUpdateDidTC(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + t.Log("1 FAIL: Alice creates an Org DID where alice is the controller, and Bob's VM is added to its VM List only. Bob attempts to update Org DID by sending his signature.") + + t.Log("Create Alice's DID") + alice_kp := testcrypto.GenerateEd25519KeyPair() + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + t.Logf("Alice's DID Id: %s", alice_didDoc.Id) + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create Bob's DID") + bob_kp := testcrypto.GenerateEd25519KeyPair() + bob_didDoc := testssi.GenerateDidDoc(bob_kp) + bob_didDoc.Controller = append(bob_didDoc.Controller, bob_didDoc.Id) + t.Logf("Bob's DID Id: %s", bob_didDoc.Id) + bob_kp.VerificationMethodId = bob_didDoc.VerificationMethod[0].Id + didDocTx = testssi.GetRegisterDidDocumentRPC(bob_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Create Organization DID") + org_kp := testcrypto.GenerateEd25519KeyPair() + org_didDoc := testssi.GenerateDidDoc(org_kp) + org_didDoc.Controller = []string{alice_didDoc.Id} + org_didDoc.VerificationMethod = []*types.VerificationMethod{bob_didDoc.VerificationMethod[0]} + didDocTx = testssi.GetRegisterDidDocumentRPC(org_didDoc, []testcrypto.IKeyPair{alice_kp, bob_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Bob not being controller, attempts to change Organization DID") + org_didDoc.CapabilityDelegation = []string{org_didDoc.VerificationMethod[0].Id} + updateDidDocTx := testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{bob_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + + t.Log("2 PASS: Alice being the controller, attempts to update Org DID by sending their signature.") + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("3 FAIL: George tries to add himself as a controller in Org DID by only passing his signature") + george_kp := testcrypto.GenerateEd25519KeyPair() + george_didDoc := testssi.GenerateDidDoc(george_kp) + george_didDoc.Controller = append(george_didDoc.Controller, george_didDoc.Id) + t.Logf("george's DID Id: %s", george_didDoc.Id) + george_kp.VerificationMethodId = george_didDoc.VerificationMethod[0].Id + didDocTx = testssi.GetRegisterDidDocumentRPC(george_didDoc, []testcrypto.IKeyPair{george_kp}) + _, err = msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + org_didDoc.Controller = append(org_didDoc.Controller, george_didDoc.Id) + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{george_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + + t.Log("4 FAIL: Alice attemps to add George as controller, by only sender her signature") + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } + + t.Log("5 PASS: Both Alice and George's signature are passed") + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{alice_kp, george_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("6 PASS: Alice attempts to remove George as a cotroller by passing only her signature") + org_didDoc.Controller = []string{alice_didDoc.Id} + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("7 PASS: Addition of George as a controller and simultaneous removal of Alice as a controller. Both alice's and george's signature are passed") + org_didDoc.Controller = []string{george_didDoc.Id} + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{alice_kp, george_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("8 FAIL: Alice attempts to perform UpdateDID by not changing any property of DID Document") + updateDidDocTx = testssi.GetUpdateDidDocumentRPC(k, ctx, org_didDoc, []testcrypto.IKeyPair{alice_kp, george_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err == nil { + t.Log(errExpectedToFail) + t.FailNow() + } +} diff --git a/x/ssi/tests/verification_method_test.go b/x/ssi/tests/verification_method_test.go new file mode 100644 index 0000000..a1cda72 --- /dev/null +++ b/x/ssi/tests/verification_method_test.go @@ -0,0 +1,242 @@ +package tests + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/hypersign-protocol/hid-node/x/ssi/keeper" + + testcrypto "github.com/hypersign-protocol/hid-node/x/ssi/tests/crypto" + testssi "github.com/hypersign-protocol/hid-node/x/ssi/tests/ssi" +) + +// Note: Ed25519VerificationKey2020 tests are skipped as it is being +// used in other tests. + +func TestEcdsaSecp256k1VerificationKey2019(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + alice_kp := testcrypto.GenerateSecp256k1KeyPair() + + t.Log("Register DID Document") + + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Update DID Document") + alice_didDoc.CapabilityDelegation = []string{alice_didDoc.VerificationMethod[0].Id} + updateDidDocTx := testssi.GetUpdateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Schema Document") + credentialSchema := testssi.GenerateSchema(alice_kp, alice_didDoc.Id) + schemaRPCElements := testssi.GenerateSchemaRPCElements(alice_kp, credentialSchema, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Status Document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestEcdsaSecp256k1RecoveryMethod2020(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + alice_kp := testcrypto.GenerateSecp256k1RecoveryKeyPair() + + t.Log("Register DID Document") + + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Update DID Document") + alice_didDoc.CapabilityDelegation = []string{alice_didDoc.VerificationMethod[0].Id} + updateDidDocTx := testssi.GetUpdateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Schema Document") + credentialSchema := testssi.GenerateSchema(alice_kp, alice_didDoc.Id) + schemaRPCElements := testssi.GenerateSchemaRPCElements(alice_kp, credentialSchema, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Status Document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestBabyJubJubKey2021(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + alice_kp := testcrypto.GenerateBabyJubJubKeyPair() + + t.Log("Register DID Document") + + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Update DID Document") + alice_didDoc.CapabilityDelegation = []string{alice_didDoc.VerificationMethod[0].Id} + updateDidDocTx := testssi.GetUpdateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Schema Document") + credentialSchema := testssi.GenerateSchema(alice_kp, alice_didDoc.Id) + schemaRPCElements := testssi.GenerateSchemaRPCElements(alice_kp, credentialSchema, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Status Document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } +} + +func TestBbsBls(t *testing.T) { + k, ctx := TestKeeper(t) + msgServer := keeper.NewMsgServerImpl(*k) + goCtx := sdk.WrapSDKContext(ctx) + + alice_kp := testcrypto.GenerateBbsBlsKeyPair() + + t.Log("Register DID Document") + + alice_didDoc := testssi.GenerateDidDoc(alice_kp) + alice_didDoc.Controller = append(alice_didDoc.Controller, alice_didDoc.Id) + + alice_kp.VerificationMethodId = alice_didDoc.VerificationMethod[0].Id + + didDocTx := testssi.GetRegisterDidDocumentRPC(alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err := msgServer.RegisterDID(goCtx, didDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Update DID Document") + alice_didDoc.CapabilityDelegation = []string{alice_didDoc.VerificationMethod[0].Id} + updateDidDocTx := testssi.GetUpdateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.UpdateDID(goCtx, updateDidDocTx) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Schema Document") + credentialSchema := testssi.GenerateSchema(alice_kp, alice_didDoc.Id) + schemaRPCElements := testssi.GenerateSchemaRPCElements(alice_kp, credentialSchema, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialSchema(goCtx, schemaRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Register Credential Status Document") + credentialStatus := testssi.GenerateCredentialStatus(alice_kp, alice_didDoc.Id) + credentialStatusRPCElements := testssi.GenerateRegisterCredStatusRPCElements(alice_kp, credentialStatus, alice_didDoc.VerificationMethod[0]) + _, err = msgServer.RegisterCredentialStatus(goCtx, credentialStatusRPCElements) + if err != nil { + t.Log(err) + t.FailNow() + } + + t.Log("Deactivate DID Document") + deactivateDidElements := testssi.GetDeactivateDidDocumentRPC(k, ctx, alice_didDoc, []testcrypto.IKeyPair{alice_kp}) + _, err = msgServer.DeactivateDID(goCtx, deactivateDidElements) + if err != nil { + t.Log(err) + t.FailNow() + } +}