diff --git a/integration/__init__.py b/integration/__init__.py deleted file mode 100644 index 6305a07..0000000 --- a/integration/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -integration test package - - -""" diff --git a/integration/app/__init__.py b/integration/app/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/integration/app/integration.sh b/integration/app/integration.sh deleted file mode 100755 index e2de866..0000000 --- a/integration/app/integration.sh +++ /dev/null @@ -1,382 +0,0 @@ -#!/bin/bash - -# -# Run this script from the base SignifyPy directory, like -# signifypy% ./integration/app/delegate.sh -# - -#print commands -#set -x - -#save this current directory, this is where the integration_clienting file also is -ORIG_CUR_DIR=$( pwd ) - -KERI_PRIMARY_STORAGE="/usr/local/var/keri" -KERI_FALLBACK_STORAGE="${HOME}/.keri" - -KERI_DEV_BRANCH="development" -KERI_DEV_TAG="c3a6fc455b5fac194aa9c264e48ea2c52328d4c5" -VLEI_DEV_BRANCH="dev" -VLEI_DEV_TAG="ed982313dab86bfada3825857601a10d71ce9631" -KERIA_DEV_BRANCH="main" -KERIA_DEV_TAG="65bebb4912557067ca290f4765e85aafa657c46f" -SIGNIFY_DEV_BRANCH="main" - -prompt="y" -function intro() { - echo "Welcome to the integration test setup/run/teardown script" - read -p "Enable prompts?, [y]: " enablePrompts - prompt=${enablePrompts:-"y"} - if [ "${prompt}" != "n" ]; then - echo "Prompts enabled" - else - echo "Skipping prompts, using defaults" - fi -} - -function getKeripyDir() { - # Check if the environment variable is set - if [ -z "$KERIPY_DIR" ]; then - default_value="../keripy" - # Prompt the user for input with a default value - if [ "${prompt}" == "y" ]; then - read -p "Set keripy dir [${default_value}]: " keriDirInput - fi - # Set the value to the user input or the default value - KERIPY_DIR=${keriDirInput:-$default_value} - fi - # Use the value of the environment variable - echo "$KERIPY_DIR" -} - -function getVleiDir() { - # Check if the environment variable is set - if [ -z "$VLEI_DIR" ]; then - default_value="../vLEI" - # Prompt the user for input with a default value - if [ "${prompt}" == "y" ]; then - read -p "Set vlei dir [${default_value}]: " vleiDirInput - fi - # Set the value to the user input or the default value - VLEI_DIR=${vleiDirInput:-$default_value} - fi - # Use the value of the environment variable - echo "$VLEI_DIR" -} - -function getKeriaDir() { - # Check if the environment variable is set - if [ -z "$KERIA_DIR" ]; then - default_value="../keria" - # Prompt the user for input with a default value - if [ "${prompt}" == "y" ]; then - read -p "Set keria dir [${default_value}]: " keriaDirInput - fi - # Set the value to the user input or the default value - KERIA_DIR=${keriaDirInput:-$default_value} - fi - # Use the value of the environment variable - echo "$KERIA_DIR" -} - -function runDelegator() { - #create the delegator from keripy - keriDir=$1 - echo "Creating delegator" - KERIPY_SCRIPTS_DIR="${keriDir}/scripts" - delPid=-1 - if [ -d "${KERIPY_SCRIPTS_DIR}" ]; then - kli init --name delegator --nopasscode --config-dir "${KERIPY_SCRIPTS_DIR}" --config-file demo-witness-oobis --salt 0ACDEyMzQ1Njc4OWdoaWpsaw - KERIPY_DELEGATOR_CONF="${KERIPY_SCRIPTS_DIR}/demo/data/delegator.json" - if [ -f "${KERIPY_DELEGATOR_CONF}" ]; then - kli incept --name delegator --alias delegator --file "${KERIPY_DELEGATOR_CONF}" - # kli incept --name delegator --alias delegator --file /Users/meenyleeny/VSCode/keripy/scripts/demo/data/delegator.json - echo "Delegator created" - # delgator auto-accepts the delegation request - kli delegate confirm --name delegator --alias delegator -Y & - delPid=$! - echo "Delegator waiting to auto-accept delegation request" - else - echo "Delegator configuration missing ${KERIPY_DELEGATOR_CONF}" - fi - else - echo "KERIPY directory ${KERIPY_SCRIPTS_DIR} does not exist." - fi -} - -function runMultisig() { - #create the delegator from keripy - keriDir=$1 - echo "Creating multisig" - KERIPY_SCRIPTS_DIR="${keriDir}/scripts" - delPid=-1 - if [ -d "${KERIPY_SCRIPTS_DIR}" ]; then - - # Follow commands run in parallel - kli multisig incept --name multisig1 --alias multisig1 --group multisig --file ${KERI_DEMO_SCRIPT_DIR}/data/multisig-triple-sample.json & - pid=$! - PID_LIST+=" $pid" - kli multisig incept --name multisig2 --alias multisig2 --group multisig --file ${KERI_SCRIPTS_DIR}/data/multisig-triple-sample.json & - pid=$! - PID_LIST+=" $pid" - - - kli init --name multisig1 --salt 0ACDEyMzQ1Njc4OWxtbm9aBc --nopasscode --config-dir "${KERIPY_SCRIPTS_DIR}" --config-file demo-witness-oobis - kli init --name multisig2 --salt 0ACDEyMzQ1Njc4OWdoaWpsaw --nopasscode --config-dir "${KERIPY_SCRIPTS_DIR}" --config-file demo-witness-oobis - KERIPY_MULTISIG_CONF_1="${KERIPY_SCRIPTS_DIR}/demo/data/multisig-1-sample.json" - KERIPY_MULTISIG_CONF_2="${KERIPY_SCRIPTS_DIR}/demo/data/multisig-2-sample.json" - if [ -f "${KERIPY_MULTISIG_CONF_2}" ]; then - kli incept --name multisig1 --alias multisig1 --file "${KERIPY_MULTISIG_CONF_1}" - kli incept --name multisig2 --alias multisig2 --file "${KERIPY_MULTISIG_CONF_2}" - - echo "Multisig 1 and 2 created" - kli oobi resolve --name multisig1 --oobi-alias multisig2 --oobi http://127.0.0.1:5642/oobi/EJccSRTfXYF6wrUVuenAIHzwcx3hJugeiJsEKmndi5q1/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha & - kli oobi resolve --name multisig1 --oobi-alias multisig3 --oobi http://127.0.0.1:5642/oobi/EKzS2BGQ7qkmEfsjGdx2w5KwmpWKf7lEXAMfB4AKqvUe/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha & - kli oobi resolve --name multisig2 --oobi-alias multisig1 --oobi http://127.0.0.1:5642/oobi/EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha & - kli oobi resolve --name multisig2 --oobi-alias multisig3 --oobi http://127.0.0.1:5642/oobi/EKzS2BGQ7qkmEfsjGdx2w5KwmpWKf7lEXAMfB4AKqvUe/witness/BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha & - echo "All participants of multisig looking for each other" - else - echo "Multisig configuration missing ${KERIPY_MULTISIG_CONF_2}" - fi - else - echo "KERIPY directory ${KERIPY_SCRIPTS_DIR} does not exist." - fi -} - -function runIssueEcr() { - cd "${ORIG_CUR_DIR}" || exit - if [ "${prompt}" == "y" ]; then - read -p "Run vLEI issue ECR script (n to skip)?, [n]: " runEcr - fi - runIssueEcr=${runEcr:-"n"} - if [ "${runIssueEcr}" == "n" ]; then - echo "Skipping Issue ECR script" - else - echo "Running issue ECR script" - scriptsDir="scripts" - if [ -d "${scriptsDir}" ]; then - echo "Launching Issue ECR script" - cd ${scriptsDir} || exit - source env.sh - source issue-ecr.sh - echo "Completed issue ECR script" - python list_person_credentials.py - echo "Listed person credentials" - fi - fi - cd "${ORIG_CUR_DIR}" || exit -} - -function runKeri() { - cd ${ORIG_CUR_DIR} || exit - witPid=-1 - keriDir=$(getKeripyDir) - echo "Keripy dir set to: ${keriDir}" - if [ "${prompt}" == "y" ]; then - read -p "Run witness network (y/n)? [y]: " runWitNet - fi - runWit=${runWitNet:-"y"} - if [ "${runWit}" == "y" ]; then - if [ -d "${keriDir}" ]; then - #run a clean witness network - echo "Launching a clean witness network" - cd "${keriDir}" || exit - updateFromGit ${KERI_DEV_BRANCH} - installPythonUpdates "keri" - rm -rf ${KERI_PRIMARY_STORAGE}/*;rm -Rf ${KERI_FALLBACK_STORAGE}/*;kli witness demo & - witPid=$! - sleep 5 - echo "Clean witness network launched" - else - echo "KERIPY dir missing ${keriDir}" - exit 1 - fi - else - echo "Skipping witness network" - fi - echo "" -} - -function runKeria() { - # run keria cloud agent - keriaPid=-1 - - if [ "${prompt}" == "y" ]; then - read -p "Run Keria (y/n)? [y]: " runKeriaInput - fi - runKeria=${runKeriaInput:-"y"} - if [ "${runKeria}" == "y" ]; then - echo "Running keria cloud agent" - keriaDir=$(getKeriaDir) - if [ -d "${keriaDir}" ]; then - cd "${keriaDir}" || exit - updateFromGit ${KERIA_DEV_BRANCH} - installPythonUpdates "keria" - export KERI_AGENT_CORS=true - keria start --config-file demo-witness-oobis.json --config-dir "${keriaDir}/scripts" & - keriaPid=$! - sleep 5 - echo "Keria cloud agent running" - else - echo "Keria dir missing ${keriaDir}" - fi - fi - echo "" -} - -function runSignifyIntegrationTests() { - # Assumes you are running from the base signify dir (see hints at the top) - cd "${ORIG_CUR_DIR}" || exit - integrationTestModule="integration.app.integration_clienting" - echo "Available functions in ${integrationTestModule}" - testList=$(python -c "import ${integrationTestModule}; print('\n'.join(x for x in dir(${integrationTestModule}) if x.startswith('test_')))") - echo "${testList}" - # echo "all" - - read -p "What signify test to run (n to skip integration tests)?, [${runSignify}]: " runSigInput - runSignify=${runSigInput:-"n"} - if [ "${runSignify}" == "n" ]; then - echo "Skipping signify test" - else - runIntegrationTest "${runSignify}" - fi -} - -function runIntegrationTest() { - testName=$1 - echo "Launching Signifypy integration test ${testName}" - signifyPid=-1 - updateFromGit ${SIGNIFY_DEV_BRANCH} - installPythonUpdates "signify" - iClient="./integration/app/integration_clienting.py" - if [ -f "${iClient}" ]; then - if [ "${testName}" == "test_delegation" ]; then - runDelegator "${keriDir}" - fi - if [ "${testName}" == "test_multisig" ]; then - runMultisig "${keriDir}" - fi - python -c "from ${integrationTestModule} import ${testName}; ${testName}()" & - signifyPid=$! - sleep 10 - echo "Completed signify ${testName}" - else - echo "${iClient} module missing" - exit 1 - fi -} - -function runVlei() { - # run vLEI cloud agent - cd ${ORIG_CUR_DIR} || exit - vleiPid=-1 - if [ "${prompt}" == "y" ]; then - read -p "Run vLEI (y/n)? [y]: " runVleiInput - fi - runVlei=${runVleiInput:-"y"} - if [ "${runVlei}" == "y" ]; then - echo "Running vLEI server" - vleiDir=$(getVleiDir) - if [ -d "${vleiDir}" ]; then - cd "${vleiDir}" || exit - updateFromGit ${VLEI_DEV_BRANCH} - installPythonUpdates "vlei" - vLEI-server -s ./schema/acdc -c ./samples/acdc/ -o ./samples/oobis/ & - vleiPid=$! - sleep 5 - echo "vLEI server is running" - else - echo "vLEI dir missing ${vleiDir}" - fi - fi - echo "" -} - -function installPythonUpdates() { - name=$1 - if [ "${prompt}" == "y" ]; then - read -p "Install $name?, [n]: " installInput - fi - install=${installInput:-"n"} - if [ "${install}" == "n" ]; then - echo "Skipping install of $name" - else - echo "Installing python module updates..." - python -m pip install -e . - fi -} - -function updateFromGit() { - branch=$1 - commit=$2 - - if [ "${prompt}" == "y" ]; then - read -p "Update git repo ${branch} ${commit}?, [n]: " upGitInput - fi - update=${upGitInput:-"n"} - if [ "${update}" == "y" ]; then - echo "Updating git branch ${branch} ${commit}" - fetch=$(git fetch) - echo "git fetch status ${fetch}" - if [ -z "${commit}" ]; then - switch=$(git switch "${branch}") - echo "git switch status ${switch}" - pull=$(git pull) - echo "git pull status ${pull}" - else - switch=$(git checkout "${commit}") - echo "git checkout commit status ${switch}" - fi - else - echo "Skipping git update ${branch}" - fi -} - -runInt="test_salty" -while [ "${runInt}" != "n" ] -do - intro - - echo "Setting up..." - - runKeri - - sleep 3 - - runVlei - - sleep 3 - - runKeria - - sleep 3 - - runSignifyIntegrationTests - - sleep 3 - - runIssueEcr - - echo "" - - if [ "${prompt}" == "y" ]; then - read -p "Your servers still running, hit enter to tear down: " teardown - fi - - echo "Tearing down any leftover processes" - #tear down the signify client - kill "$signifyPid" >/dev/null 2>&1 - # tear down the keria cloud agent - kill $keriaPid >/dev/null 2>&1 - # tear down the delegator - kill "$delPid" >/dev/null 2>&1 - # tear down the vLEI server - kill $vleiPid >/dev/null 2>&1 - # tear down the witness network - kill $witPid >/dev/null 2>&1 - - read -p "Run another test [n]?: " runAgain - runInt=${runAgain:-"n"} -done - -echo "Done" \ No newline at end of file diff --git a/integration/app/integration_clienting.py b/integration/app/integration_clienting.py deleted file mode 100644 index 4bed4ab..0000000 --- a/integration/app/integration_clienting.py +++ /dev/null @@ -1,792 +0,0 @@ -# -*- encoding: utf-8 -*- -""" -SIGNIFY -signify.app.clienting module - -Testing clienting with integration tests that require a running KERIA Cloud Agent -""" -import json -import random -from time import sleep - -import requests -from keri.app.keeping import Algos -from keri.core import coring - -import pytest -from keri import kering -from keri.core.coring import Tiers, Serder, MtrDex - -from signify.app.clienting import SignifyClient - -TESTS_APP_DIR = "tests/app/" -WITNESS_FILE_PATH = "{}{}".format(TESTS_APP_DIR,"witness.toml") -DELEGATION_FILE_PATH = "{}{}".format(TESTS_APP_DIR,"delegation.toml") -CONNECT_FILE_PATH = "{}{}".format(TESTS_APP_DIR,"connect.toml") - -wit1 = "BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha" -wit2 = "BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM" -wit3 = "BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX" - -def test_init(): - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = None - - # Try with bran that is too short - with pytest.raises(kering.ConfigurationError): - SignifyClient(passcode=bran[:16], tier=tier) - - # Try with an invalid URL - with pytest.raises(kering.ConfigurationError): - client = SignifyClient(passcode=bran, tier=tier) - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url="ftp://www.example.com") - - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - serder = client.icp - assert serder.raw == (b'{"v":"KERI10JSON00012b_","t":"icp","d":"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJ' - b'XJHtJose","i":"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose","s":"0","kt":"1' - b'","k":["DAbWjobbaLqRB94KiAutAHb_qzPpOHm3LURA_ksxetVc"],"nt":"1","n":["EIFG_u' - b'qfr1yN560LoHYHfvPAhxQ5sN6xZZT_E3h7d2tL"],"bt":"0","b":[],"c":[],"a":[]}') - - # changing tier with has no effect - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - tier = Tiers.med - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "EOgQvKz8ziRn7FdR_ebwK9BkaVOnGeXQOJ87N6hMLrK0" - - tier = Tiers.high - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "EB8wN2c_tv1WlsJ5c3949-TFWPMB2IflFbdMlZfC_Hgo" - - -def test_extern(): - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = None - - client = SignifyClient(passcode=bran, tier=tier, - extern_modules=[ - dict( - type="gcp", - name="gcp_ksm_shim", - params=dict( - projectId="advance-copilot-319717", - locationId="us-west1", - keyRingId="signify-key-ring" - ) - )]) - - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - assert client.ctrl.ridx == 0 - - # Create AID using external HSM module - stem = "ABO4qF9g9L-e1QzvMXgY-58elMh8L-63ZBnNXhxScO81" - identifiers = client.identifiers() - aid = identifiers.create("aid1", algo=Algos.extern, extern_type="gcp", extern=dict(stem=stem)) - icp = Serder(ked=aid) - print(icp.pretty()) - - -@_recorder.record(file_path=CONNECT_FILE_PATH) -def test_salty(): - """ - This test assumes a running KERIA agent. - See integration.sh to run this test automatically with a locally running KERIA and witness network. - """ - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.med - - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "EOgQvKz8ziRn7FdR_ebwK9BkaVOnGeXQOJ87N6hMLrK0" - - # Raises configuration error because the started agent has a different controller AID - with pytest.raises(kering.ConfigurationError): - client.connect(url=url) - - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - - print(evt.pretty()) - print(siger.qb64) - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - identifiers = client.identifiers() - aids = identifiers.list() - assert aids == [] - - op = identifiers.create("aid1", bran="0123456789abcdefghijk") - aid = op["response"] - icp = Serder(ked=aid) - assert icp.pre == "ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK" - assert len(icp.verfers) == 1 - assert icp.verfers[0].qb64 == "DPmhSfdhCPxr3EqjxzEtF8TVy0YX7ATo0Uc8oo2cnmY9" - assert len(icp.digers) == 1 - assert icp.digers[0].qb64 == "EAORnRtObOgNiOlMolji-KijC_isa3lRDpHCsol79cOc" - assert icp.tholder.num == 1 - assert icp.ntholder.num == 1 - - rpy = identifiers.makeEndRole(pre=icp.pre, eid="EPGaq6inGxOx-VVVEcUb_KstzJZldHJvVsHqD4IPxTWf") - print(rpy.pretty()) - assert rpy.ked['a']['cid'] == "ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK" - assert rpy.ked['a']['eid'] == "EPGaq6inGxOx-VVVEcUb_KstzJZldHJvVsHqD4IPxTWf" - - aids = identifiers.list() - assert len(aids) == 1 - aid = aids.pop() - - salt = aid[Algos.salty] - assert aid['name'] == "aid1" - assert salt["pidx"] == 0 - assert aid["prefix"] == icp.pre - assert salt["stem"] == "signify:aid" - - op2 = identifiers.create("aid2", count=3, ncount=3, isith="2", nsith="2", bran="0123456789lmnopqrstuv") - aid2 = op2["response"] - icp2 = Serder(ked=aid2) - print(icp2.pre) - assert icp2.pre == "EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX" - assert len(icp2.verfers) == 3 - assert icp2.verfers[0].qb64 == "DGBw7C7AfC7jbD3jLLRS3SzIWFndM947TyNWKQ52iQx5" - assert icp2.verfers[1].qb64 == "DD_bHYFsgWXuCbz3SD0HjCIe_ITjRvEoCGuZ4PcNFFDz" - assert icp2.verfers[2].qb64 == "DEe9u8k0fm1wMFAuOIsCtCNrpduoaV5R21rAcJl0awze" - assert len(icp2.digers) == 3 - print([diger.qb64 for diger in icp2.digers]) - assert icp2.digers[0].qb64 == "EML5FrjCpz8SEl4dh0U15l8bMRhV_O5iDcR1opLJGBSH" - assert icp2.digers[1].qb64 == "EJpKquuibYTqpwMDqEFAFs0gwq0PASAHZ_iDmSF3I2Vg" - assert icp2.digers[2].qb64 == "ELplTAiEKdobFhlf-dh1vUb2iVDW0dYOSzs1dR7fQo60" - assert icp2.tholder.num == 2 - assert icp2.ntholder.num == 2 - - aids = identifiers.list() - assert len(aids) == 2 - aid = aids[1] - assert aid['name'] == "aid2" - assert aid["prefix"] == icp2.pre - salt = aid[Algos.salty] - assert salt["pidx"] == 1 - assert salt["stem"] == "signify:aid" - - op3 = identifiers.rotate("aid1") - ked = op3["response"] - rot = Serder(ked=ked) - - assert rot.said == "EBQABdRgaxJONrSLcgrdtbASflkvLxJkiDO0H-XmuhGg" - assert rot.sn == 1 - assert len(rot.digers) == 1 - assert rot.verfers[0].qb64 == "DHgomzINlGJHr-XP3sv2ZcR9QsIEYS3LJhs4KRaZYKly" - assert rot.digers[0].qb64 == "EJMovBlrBuD6BVeUsGSxLjczbLEbZU9YnTSud9K4nVzk" - - op4 = identifiers.interact("aid1", data=[icp.pre]) - ked = op4["response"] - ixn = Serder(ked=ked) - assert ixn.said == "ENsmRAg_oM7Hl1S-GTRMA7s4y760lQMjzl0aqOQ2iTce" - assert ixn.sn == 2 - assert ixn.ked["a"] == [icp.pre] - - aid = identifiers.get("aid1") - state = aid["state"] - assert state['s'] == '2' - assert state['f'] == '2' - assert state['et'] == 'ixn' - assert state['d'] == ixn.said - assert state['ee']['d'] == rot.said - - events = client.keyEvents() - log = events.get(pre=aid["prefix"]) - assert len(log) == 3 - serder = coring.Serder(ked=log[0]) - assert serder.pre == icp.pre - assert serder.said == icp.said - serder = coring.Serder(ked=log[1]) - assert serder.pre == rot.pre - assert serder.said == rot.said - serder = coring.Serder(ked=log[2]) - assert serder.pre == ixn.pre - assert serder.said == ixn.said - - print(identifiers.list()) - - -@_recorder.record(file_path=WITNESS_FILE_PATH) -def test_witnesses(): - """ This test assumes a running Demo Witnesses and KERIA agent with the following comands: - - `kli witness demo` - `keria start -c ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose \ - --config-file demo-witness-oobis --config-dir /scripts` - - """ - import os - dir_path = os.path.dirname(os.path.realpath(__file__)) - print("current path: ", dir_path) - print("should find witenss toml file here: ",os.listdir("{}/../../{}".format(dir_path,TESTS_APP_DIR))) - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == 'EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei' - - # assert client.ctrl.ridx == 0 - - identifiers = client.identifiers() - operations = client.operations() - - print("creating aid") - # Use witnesses - op = identifiers.create("aid1", bran="canIGetAWitnessSaltGreaterThan21", toad="2", wits=["BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha", - "BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM", - "BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"]) - - while not op["done"]: - op = operations.get(op["name"]) - sleep(1) - - icp1 = Serder(ked=op["response"]) - assert icp1.pre == 'EGTFIbnFoA7G-f4FHzzXUMp6VAgQfJ-2nXqzfb5hVwKa' - - - assert icp1.ked['b'] == ["BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha", - "BLskRTInXnMxWaGqcpSyMgo0nYbalW99cGZESrz3zapM", - "BIKKuvBwpmDVA4Ds-EpL5bt9OqPzWPja2LigFYZN2YfX"] - assert icp1.ked['bt'] == "2" - - aid1 = identifiers.get("aid1") - assert aid1["prefix"] == icp1.pre - assert len(aid1["windexes"]) == 3 - - aids = identifiers.list() - assert len(aids) == 1 - aid = aids.pop() - assert aid['prefix'] == icp1.pre - - -@_recorder.record(file_path=DELEGATION_FILE_PATH) -def test_delegation(): - """ This test assumes a running Demo Witnesses and KERIA agent with the following comands: - - `kli witness demo` - `keria start \ - --config-file demo-witness-oobis --config-dir /scripts` - - """ - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - - client = SignifyClient(passcode=bran, tier=tier) - print(client.controller) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - # Delegator OOBI: - # http://127.0.0.1:5642/oobi/EHpD0-CDWOdu5RJ8jHBSUkOqBZ3cXeDVHWNb_Ul89VI7/witness - - delpre = "EHpD0-CDWOdu5RJ8jHBSUkOqBZ3cXeDVHWNb_Ul89VI7" - identifiers = client.identifiers() - operations = client.operations() - oobis = client.oobis() - - op = oobis.resolve(f"http://127.0.0.1:5642/oobi/{delpre}/witness") - print("OOBI op is: ", op) - - count = 0 - while not op["done"] and not count > 25: - op = operations.get(op["name"]) - sleep(1) - - op = identifiers.create("aid1", toad="2", delpre=delpre, wits=[wit1, wit2, wit3]) - pre = op["metadata"]["pre"] - - while not op["done"]: - op = operations.get(op["name"]) - sleep(1) - - icp1 = Serder(ked=op["response"]) - - print(icp1.pretty()) - assert icp1.pre == pre - - -def test_randy(): - """ This test assumes a running KERIA agent with the following comand: - - `keria start -c ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose` - - """ - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - # assert client.ctrl.ridx == 0 - - identifiers = client.identifiers() - op = identifiers.create("aid1", algo=Algos.randy) - aid = op["response"] - icp = Serder(ked=aid) - assert len(icp.verfers) == 1 - assert len(icp.verfers) == 1 - assert len(icp.digers) == 1 - assert len(icp.digers) == 1 - assert icp.tholder.num == 1 - assert icp.ntholder.num == 1 - - aids = identifiers.list() - assert len(aids) == 1 - aid = aids[0] - assert aid["prefix"] == icp.pre - - op = identifiers.interact("aid1", data=[icp.pre]) - ked = op["response"] - ixn = Serder(ked=ked) - assert ixn.sn == 1 - assert ixn.ked["a"] == [icp.pre] - - aids = identifiers.list() - assert len(aids) == 1 - aid = aids[0] - events = client.keyEvents() - log = events.get(pre=aid["prefix"]) - assert len(log) == 2 - - op = identifiers.rotate("aid1") - ked = op["response"] - rot = Serder(ked=ked) - assert rot.pre == icp.pre - assert rot.sn == 2 - assert len(rot.digers) == 1 - assert rot.verfers[0].qb64 != icp.verfers[0].qb64 - assert rot.digers[0].qb64 != icp.digers[0].qb64 - dig = coring.Diger(ser=rot.verfers[0].qb64b, code=MtrDex.Blake3_256) - print(icp.digers[0].qb64, dig.qb64) - assert icp.digers[0].qb64 == dig.qb64 - log = events.get(pre=aid["prefix"]) - assert len(log) == 3 - - for event in log: - print(coring.Serder(ked=event).pretty()) - - -def test_query(): - """ This test assumes a running Demo Witnesses and KERIA agent with the following comands: - - `kli witness demo` - `keria start -c ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose \ - --config-file demo-witness-oobis --config-dir /scripts` - - """ - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - # assert client.ctrl.ridx == 0 - - operations = client.operations() - keyState = client.keyStates() - op = keyState.query(pre="EKYLUMmNPZeEs77Zvclf0bSN5IN-mLfLpx2ySb-HDlk4") - while not op["done"]: - op = operations.get(op["name"]) - sleep(1) - - multisig1 = op["response"] - - op = keyState.query(pre="EJccSRTfXYF6wrUVuenAIHzwcx3hJugeiJsEKmndi5q1") - while not op["done"]: - op = operations.get(op["name"]) - sleep(1) - - multisig2 = op["response"] - - -def test_multi_tenant(): - """ This test assumes a running KERIA agent with the following comand: - - `keria start -c ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose` - - """ - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - - identifiers = client.identifiers() - op = identifiers.create("aid1") - aid = op["response"] - icp = Serder(ked=aid) - - # assert icp.pre == "EKGpuLBMAncuGm2mk4F7tEtELqLEl60tT5eGX3sBdCHF" - print(icp.verfers[0].qb64, icp.digers[0].qb64) - assert len(icp.verfers) == 1 - # assert icp.verfers[0].qb64 == "DPmhSfdhCPxr3EqjxzEtF8TVy0YX7ATo0Uc8oo2cnmY9" - assert len(icp.digers) == 1 - # assert icp.digers[0].qb64 == "EAORnRtObOgNiOlMolji-KijC_isa3lRDpHCsol79cOc" - assert icp.tholder.num == 1 - assert icp.ntholder.num == 1 - - identifiers.addEndRole("aid1", eid=client.agent.pre) - - rbran = b'abcdefghijk0123456789' - rclient = SignifyClient(passcode=rbran, tier=tier) - assert rclient.controller == "EIIY2SgE_bqKLl2MlnREUawJ79jTuucvWwh-S6zsSUFo" - - evt, siger = rclient.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=rclient.ctrl.stem, - pidx=1, - tier=rclient.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - rclient.connect(url=url) - assert rclient.agent is not None - assert rclient.agent.delpre == "EIIY2SgE_bqKLl2MlnREUawJ79jTuucvWwh-S6zsSUFo" - assert rclient.agent.pre == "EFK_y173TSxvwgLHlsWAH9RwRq_6k8R_EVpbJ5rYujbo" - # assert rclient.ctrl.ridx == 0 - - ridentifiers = rclient.identifiers() - op = ridentifiers.create("randy1", algo=Algos.randy) - aid = op["response"] - icp = Serder(ked=aid) - assert len(icp.verfers) == 1 - assert len(icp.verfers) == 1 - assert len(icp.digers) == 1 - assert len(icp.digers) == 1 - assert icp.tholder.num == 1 - assert icp.ntholder.num == 1 - - ridentifiers.addEndRole("randy1", eid=rclient.agent.pre) - print(identifiers.list()) - print(ridentifiers.list()) - - -def test_passcode_rotation(): - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - - identifiers = client.identifiers() - op = identifiers.create("salty") - aid = op["response"] - sicp = Serder(ked=aid) - - aid = identifiers.get("salty") - assert aid["prefix"] == sicp.pre - - op = identifiers.create("randy", algo=Algos.randy) - aid = op["response"] - ricp = Serder(ked=aid) - - aid = identifiers.get("randy") - assert aid["prefix"] == ricp.pre - - identifiers = client.identifiers() - pres = identifiers.list() - aids = [] - for pre in pres: - aid = identifiers.get(name=pre["name"]) - aids.append(aid) - - client.rotate(nbran='0123456789abcdefghijk', aids=aids) - print(json.dumps(identifiers.list(), indent=1)) - - op = identifiers.rotate("salty") - ked = op["response"] - rot = Serder(ked=ked) - print("Salty Rotated:") - print(rot.pretty()) - - op = identifiers.rotate("randy") - ked = op["response"] - rot = Serder(ked=ked) - print("Randy Rotated:") - print(rot.pretty()) - - -def test_passcode_rotation_x1000(): - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - assert client.agent is not None - assert client.agent.delpre == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - assert client.agent.pre == "EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei" - - identifiers = client.identifiers() - - for idx in range(1000): - if idx % 10 == 0: - print(f"Created {idx}...") - - algo = random.choice(["salty", "randy"]) - match algo: - case "salty": - op = identifiers.create(f"salty-{idx}") - aid = op["response"] - sicp = Serder(ked=aid) - - op = identifiers.get(f"salty-{idx}") - aid = op["response"] - assert aid["prefix"] == sicp.pre - - case "randy": - op = identifiers.create(f"randy-{idx}", algo=Algos.randy) - aid = op["response"] - ricp = Serder(ked=aid) - - aid = identifiers.get(f"randy-{idx}") - assert aid["prefix"] == ricp.pre - - identifiers = client.identifiers() - pres = identifiers.list() - print(len(pres)) - # aids = [] - # for pre in pres: - # aid = identifiers.get(name=pre["name"]) - # aids.append(aid) - # - # client.rotate(nbran='0123456789abcdefghijk', aids=aids) - # print(json.dumps(identifiers.list(), indent=1)) - # - # ked = identifiers.rotate("salty") - # rot = Serder(ked=ked) - # print("Salty Rotated:") - # print(rot.pretty()) - # - # ked = identifiers.rotate("randy") - # rot = Serder(ked=ked) - # print("Randy Rotated:") - # print(rot.pretty()) - - -def test_recreate_client(): - url = "http://localhost:3901" - bran = b'0123456789abcdefghijk' - tier = Tiers.low - client = SignifyClient(passcode=bran, tier=tier) - assert client.controller == "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" - - evt, siger = client.ctrl.event() - res = requests.post(url="http://localhost:3903/boot", - json=dict( - icp=evt.ked, - sig=siger.qb64, - stem=client.ctrl.stem, - pidx=1, - tier=client.ctrl.tier)) - - if res.status_code != requests.codes.accepted: - raise kering.AuthNError(f"unable to initialize cloud agent connection, {res.status_code}, {res.text}") - - client.connect(url=url) - - identifiers = client.identifiers() - pres = identifiers.list(limit=1000) - - print(f"loaded {len(pres)} identifiers") - aids = [] - for pre in pres: - aid = identifiers.get(name=pre["name"]) - aids.append(aid) - - print("done getting all values, now to rotate") - - client.rotate(nbran='0123456789abcdefghijk', aids=aids) - - print("rotation done, now to list.") - print(json.dumps(identifiers.list(limit=1000), indent=1)) - - -if __name__ == "__main__": - - #SHOULD WORK - # test_delegation() - # test_witnesses() - # test_salty() - # test_randy() - # test_multisig() - test_query() - # test_recreate_client() - # test_multi_tenant() - - # KNOWN ISSUE with KERIA, will not work - # test_passcode_rotation() - # test_passcode_rotation_x1000() - - #REQUIRES external HSM - # test_extern() \ No newline at end of file diff --git a/integration/app/test_randy.ipynb b/integration/app/test_randy.ipynb deleted file mode 100644 index 8357125..0000000 --- a/integration/app/test_randy.ipynb +++ /dev/null @@ -1,441 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "5ccc5e88-2a8e-4934-a6f5-60500c936ec1", - "metadata": { - "tags": [] - }, - "source": [ - "# SignifyPy Randy Keys\n", - "This notebook should help a developer validate their env setup (Witnesses, KERIA, and SignifyPy client) and walk them step-by-step through the randy key creation. If you haven't setup and run KERI/Witnesses before [Kent Bull's KERI/ACDC guide](https://kentbull.com/2023/03/09/keri-tutorial-series-treasure-hunting-in-abydos-issuing-and-verifying-a-credential-acdc/) is a great starting point" - ] - }, - { - "cell_type": "markdown", - "id": "4f1c272f", - "metadata": {}, - "source": [ - "## Env Setup\n", - "\n", - "### Witness Network\n", - "Run a **clean** local witness network\n", - "* Clear out any of the local files from previous runs. Note keri wants to write to /user/local/var/keri, or ~/.keri\n", - "* And launch the local witness network\n", - "* You will know your witness network isn't clean if you see a KERIA error like:\n", - "``` ValueError: Already incepted pre=DCQE55HKUokSAKc4ntJw2b845r4DnddpPZs8iF_T-0c-. ERR: mdb_txn_renew: MDB_BAD_RSLOT: Invalid reuse of reader locktable slot```\n", - "\n", - "Start your clean demo witness network (usually from the keripy project) with a command like:\n", - "\n", - "```rm -rf /usr/local/var/keri/*;rm -Rf ~/.keri/*;nohup kli witness demo```" - ] - }, - { - "cell_type": "markdown", - "id": "21330ac6", - "metadata": {}, - "source": [ - "## KERIA\n", - "\n", - "Next, start the KERI Agent (KERIA)\n", - "\n", - "In the KERIA project you might want to change start.py to have:\n", - "```help.ogler.level = logging.DEBUG```\n", - "\n", - "When you execute keria start --config-file demo-witness-oobis.json --config-dir ./scripts you need to be in the keria folder where the config files are located (under scripts)\n", - "\n", - "```keria start --config-file demo-witness-oobis.json --config-dir ./scripts``` " - ] - }, - { - "cell_type": "markdown", - "id": "a6ce8ef6", - "metadata": {}, - "source": [ - "\n", - "## Signify\n", - "* If signifypy isn't on PiPy yet, then make sure your Jupyter Python version points to the same Python version where you install signifypy.\n", - "* One way to install signifypy is from git like: ```%python -m pip install \"signifypy @ git+https://github.com/WebOfTrust/signifypy.git\"```" - ] - }, - { - "cell_type": "markdown", - "id": "b52ede76", - "metadata": {}, - "source": [ - "## Install python dependencies from PiPy" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "id": "398aac8e", - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "UsageError: Line magic function `%python` not found (But cell magic `%%python` exists, did you mean that instead?).\n" - ] - } - ], - "source": [ - "%python -m pip install keri\n", - "%python -m pip install responses\n", - "%python -m pip install pytest" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "id": "c62e0ed2-19b2-4c82-923d-cf89a8e78c96", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from time import sleep\n", - "\n", - "import requests\n", - "from keri.app.keeping import Algos\n", - "from keri.core import coring\n", - "from responses import _recorder\n", - "\n", - "import pytest\n", - "from keri import kering\n", - "from keri.core.coring import Tiers, Serder, MtrDex\n", - "\n", - "from signify.app.clienting import SignifyClient" - ] - }, - { - "cell_type": "markdown", - "id": "d71ec345", - "metadata": {}, - "source": [ - "## Basic Signify client creation\n", - "* Create client using the admin url\n", - "* Hard-code the randomness for testing purposes\n", - "* Don't set the tier, to create the least expensive/secure public key" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "id": "921aa899", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Inception event is: b'{\"v\":\"KERI10JSON00012b_\",\"t\":\"icp\",\"d\":\"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\",\"i\":\"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\",\"s\":\"0\",\"kt\":\"1\",\"k\":[\"DAbWjobbaLqRB94KiAutAHb_qzPpOHm3LURA_ksxetVc\"],\"nt\":\"1\",\"n\":[\"EIFG_uqfr1yN560LoHYHfvPAhxQ5sN6xZZT_E3h7d2tL\"],\"bt\":\"0\",\"b\":[],\"c\":[],\"a\":[]}'\n" - ] - } - ], - "source": [ - "admin_url = \"http://localhost:3901\"\n", - "# bran = passcode for the db and keystore (habery)\n", - "bran = b'0123456789abcdefghijk'\n", - "# tier (str low|med|high): value from Tierage for security level of stretch\n", - "tier = None\n", - "\n", - "client = SignifyClient(url=admin_url, bran=bran, tier=tier)\n", - "# Your client public key\n", - "assert client.controller == \"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\"\n", - "# Get the inception event\n", - "serder = client.icp\n", - "# Review the inception event\n", - "assert serder.raw == (b'{\"v\":\"KERI10JSON00012b_\",\"t\":\"icp\",\"d\":\"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJ'\n", - " b'XJHtJose\",\"i\":\"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\",\"s\":\"0\",\"kt\":\"1'\n", - " b'\",\"k\":[\"DAbWjobbaLqRB94KiAutAHb_qzPpOHm3LURA_ksxetVc\"],\"nt\":\"1\",\"n\":[\"EIFG_u'\n", - " b'qfr1yN560LoHYHfvPAhxQ5sN6xZZT_E3h7d2tL\"],\"bt\":\"0\",\"b\":[],\"c\":[],\"a\":[]}')\n", - "print(\"Inception event is: \", serder.raw)" - ] - }, - { - "cell_type": "markdown", - "id": "3ae85294", - "metadata": {}, - "source": [ - "* For more information about keri fields, see [that section of the KERI whitepaper](https://weboftrust.github.io/ietf-keri/draft-ssmith-keri.html#section-5.1)" - ] - }, - { - "cell_type": "markdown", - "id": "c4e5908c", - "metadata": {}, - "source": [ - "## You can create tiers of clients\n", - "The higher tiers take longer to generate as the number of hash iterations increases" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "id": "a6cf222d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Low tier controller is: ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\n" - ] - } - ], - "source": [ - "tier = Tiers.low\n", - "client = SignifyClient(url=admin_url, bran=bran, tier=tier)\n", - "print(\"Low tier controller is: \", client.controller)\n", - "assert client.controller == \"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\"\n", - "\n", - "#tier = Tiers.med\n", - "#client = SignifyClient(url=admin_url, bran=bran, tier=tier)\n", - "#print(\"Medium tier controller is: \", client.controller)\n", - "#assert client.controller == \"EOgQvKz8ziRn7FdR_ebwK9BkaVOnGeXQOJ87N6hMLrK0\"\n", - "\n", - "#tier = Tiers.high\n", - "#client = SignifyClient(url=admin_url, bran=bran, tier=tier)\n", - "#print(\"High tier controller is: \", client.controller)\n", - "#assert client.controller == \"EB8wN2c_tv1WlsJ5c3949-TFWPMB2IflFbdMlZfC_Hgo\"" - ] - }, - { - "cell_type": "markdown", - "id": "f3b94d4b", - "metadata": {}, - "source": [ - "## Post inception event to KERIA (OOB) boot interface" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "id": "701d9d38", - "metadata": {}, - "outputs": [], - "source": [ - "evt, siger = client.ctrl.event()\n", - "res = requests.post(url=\"http://localhost:3903/boot\",\n", - " json=dict(\n", - " icp=evt.ked,\n", - " sig=siger.qb64,\n", - " stem=client.ctrl.stem,\n", - " pidx=1,\n", - " tier=client.ctrl.tier))\n", - "if res.status_code != requests.codes.accepted:\n", - " raise kering.AuthNError(f\"unable to initialize cloud agent connection, {res.status_code}, {res.text}\")" - ] - }, - { - "cell_type": "markdown", - "id": "fb09cf01", - "metadata": {}, - "source": [ - "## Create a KERIA agent session" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "id": "8d8b33e5", - "metadata": {}, - "outputs": [], - "source": [ - "client.connect()\n", - "assert client.agent is not None\n", - "assert client.agent.anchor == \"ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose\"\n", - "assert client.agent.pre == \"EJoqUMpQAfqsJhBqv02ehR-9BJYBTCrW8h5JlLdMTWBg\"\n", - "assert client.ctrl.ridx == 0" - ] - }, - { - "cell_type": "markdown", - "id": "32ba696d", - "metadata": {}, - "source": [ - "## Create a KERI Autonomic Identifier (AID)\n", - "* Note that identifiers.create will do the post to KERIA for you " - ] - }, - { - "cell_type": "code", - "execution_count": 59, - "id": "b1d37b67", - "metadata": {}, - "outputs": [], - "source": [ - "identifiers = client.identifiers()\n", - "aids = identifiers.list()\n", - "assert aids == []\n", - "\n", - "aid = identifiers.create(\"aid1\")\n", - "icp = Serder(ked=aid)\n", - "assert icp.pre == \"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK\"\n", - "assert len(icp.verfers) == 1\n", - "assert icp.verfers[0].qb64 == \"DPmhSfdhCPxr3EqjxzEtF8TVy0YX7ATo0Uc8oo2cnmY9\"\n", - "assert len(icp.digers) == 1\n", - "assert icp.digers[0].qb64 == \"EAORnRtObOgNiOlMolji-KijC_isa3lRDpHCsol79cOc\"\n", - "assert icp.tholder.num == 1\n", - "assert icp.ntholder.num == 1\n", - "\n", - "rpy = identifiers.makeEndRole(pre=icp.pre, eid=\"EPGaq6inGxOx-VVVEcUb_KstzJZldHJvVsHqD4IPxTWf\")\n", - "\n", - "aids = identifiers.list()\n", - "assert len(aids) == 1\n", - "aid = aids.pop()\n", - "\n", - "salt = aid[Algos.salty]\n", - "assert aid['name'] == \"aid1\"\n", - "assert salt[\"pidx\"] == 0\n", - "assert aid[\"prefix\"] == icp.pre\n", - "assert salt[\"stem\"] == \"signify:aid\"" - ] - }, - { - "cell_type": "markdown", - "id": "def47556", - "metadata": {}, - "source": [ - "## Create a second AID with more configuration" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "id": "26fb711d", - "metadata": {}, - "outputs": [], - "source": [ - "aid2 = identifiers.create(\"aid2\", count=3, ncount=3, isith=\"2\", nsith=\"2\")\n", - "icp2 = Serder(ked=aid2)\n", - "assert icp2.pre == \"EI5e4q43vsTsy-vJFcVGKfI3YKHbOT5ffuseaxtuYydL\"\n", - "assert len(icp2.verfers) == 3\n", - "assert icp2.verfers[0].qb64 == \"DPmhSfdhCPxr3EqjxzEtF8TVy0YX7ATo0Uc8oo2cnmY9\"\n", - "assert icp2.verfers[1].qb64 == \"DHgomzINlGJHr-XP3sv2ZcR9QsIEYS3LJhs4KRaZYKly\"\n", - "assert icp2.verfers[2].qb64 == \"DEfdjYZMI2hLaHBOpUubn5AUItgOvh2W1vckGE33SIPf\"\n", - "assert len(icp2.digers) == 3\n", - "assert icp2.digers[0].qb64 == \"EEvyqpRLktts-_aSfPHKKv1mTKTV4ngwKKkOaqm3ZuPX\"\n", - "assert icp2.digers[1].qb64 == \"EEkMimwsv_JMZh7k-Rfq5wvhvbEdjVr8NhGQpyssVmNJ\"\n", - "assert icp2.digers[2].qb64 == \"EJy_MjjMWLJkn_5cRaUtDr7asfLe70xbAPD2nablr0iv\"\n", - "assert icp2.tholder.num == 2\n", - "assert icp2.ntholder.num == 2\n", - "\n", - "aids = identifiers.list()\n", - "assert len(aids) == 2\n", - "aid = aids[1]\n", - "assert aid['name'] == \"aid2\"\n", - "assert aid[\"prefix\"] == icp2.pre\n", - "salt = aid[Algos.salty]\n", - "assert salt[\"pidx\"] == 1\n", - "assert salt[\"stem\"] == \"signify:aid\"\n", - "\n", - "ked = identifiers.rotate(\"aid1\")\n", - "rot = Serder(ked=ked)\n", - "\n", - "assert rot.said == \"EBQABdRgaxJONrSLcgrdtbASflkvLxJkiDO0H-XmuhGg\"\n", - "assert rot.sn == 1\n", - "assert len(rot.digers) == 1\n", - "assert rot.verfers[0].qb64 == \"DHgomzINlGJHr-XP3sv2ZcR9QsIEYS3LJhs4KRaZYKly\"\n", - "assert rot.digers[0].qb64 == \"EJMovBlrBuD6BVeUsGSxLjczbLEbZU9YnTSud9K4nVzk\"" - ] - }, - { - "cell_type": "markdown", - "id": "dfb84040", - "metadata": {}, - "source": [ - "## Create an interaction event" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "id": "f912e95d", - "metadata": {}, - "outputs": [], - "source": [ - "ked = identifiers.interact(\"aid1\", data=[icp.pre])\n", - "ixn = Serder(ked=ked)\n", - "assert ixn.said == \"ENsmRAg_oM7Hl1S-GTRMA7s4y760lQMjzl0aqOQ2iTce\"\n", - "assert ixn.sn == 2\n", - "assert ixn.ked[\"a\"] == [icp.pre]\n", - "\n", - "aid = identifiers.get(\"aid1\")\n", - "state = aid[\"state\"]\n", - "assert state['s'] == '2'\n", - "assert state['f'] == '2'\n", - "assert state['et'] == 'ixn'\n", - "assert state['d'] == ixn.said\n", - "assert state['ee']['d'] == rot.said" - ] - }, - { - "cell_type": "markdown", - "id": "5d69537e", - "metadata": {}, - "source": [ - "## Review the key events and list the identifiers" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "id": "2f817695", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'name': 'aid1', 'prefix': 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK', 'salty': {'pidx': 0, 'kidx': 1, 'stem': 'signify:aid', 'tier': 'low', 'dcode': 'E', 'icodes': ['A'], 'ncodes': ['A'], 'transferable': True}}, {'name': 'aid2', 'prefix': 'EI5e4q43vsTsy-vJFcVGKfI3YKHbOT5ffuseaxtuYydL', 'salty': {'pidx': 1, 'kidx': 0, 'stem': 'signify:aid', 'tier': 'low', 'dcode': 'E', 'icodes': ['A', 'A', 'A'], 'ncodes': ['A', 'A', 'A'], 'transferable': True}}]\n" - ] - } - ], - "source": [ - "events = client.keyEvents()\n", - "log = events.get(pre=aid[\"prefix\"])\n", - "assert len(log) == 3\n", - "serder = coring.Serder(ked=log[0])\n", - "assert serder.pre == icp.pre\n", - "assert serder.said == icp.said\n", - "serder = coring.Serder(ked=log[1])\n", - "assert serder.pre == rot.pre\n", - "assert serder.said == rot.said\n", - "serder = coring.Serder(ked=log[2])\n", - "assert serder.pre == ixn.pre\n", - "assert serder.said == ixn.said\n", - "\n", - "print(identifiers.list())" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.11.3 64-bit ('3.11.3')", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.3" - }, - "vscode": { - "interpreter": { - "hash": "ebe7f73a47762276d07c618e3a56dc3bc1e0329af7b3d7764336a2d1f3e9db09" - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/scripts/list_contacts.py b/scripts/list_contacts.py new file mode 100644 index 0000000..a3c451c --- /dev/null +++ b/scripts/list_contacts.py @@ -0,0 +1,32 @@ +# -*- encoding: utf-8 -*- +""" +SIGNIFY +signify.app.clienting module + +Testing clienting with integration tests that require a running KERIA Cloud Agent +""" + +from keri.core.coring import Tiers +from signify.app.clienting import SignifyClient + + +def list_contacts(): + url = "http://localhost:3901" + bran = b'0123456789abcdefghijk' + tier = Tiers.low + + client = SignifyClient(passcode=bran, tier=tier, url=url) + contacts = client.contacts() + + cons = contacts.list() + + print(cons) + + identifiers = client.identifiers() + res = identifiers.get(name="Email access - Phil") + + print(res) + + +if __name__ == "__main__": + list_contacts() diff --git a/src/signify/app/clienting.py b/src/signify/app/clienting.py index cd4cf0c..d51eea9 100644 --- a/src/signify/app/clienting.py +++ b/src/signify/app/clienting.py @@ -259,6 +259,10 @@ def challenges(self): from signify.app.challenging import Challenges return Challenges(client=self) + def contacts(self): + from signify.app.contacting import Contacts + return Contacts(client=self) + @staticmethod def raiseForStatus(res): try: diff --git a/src/signify/app/contacting.py b/src/signify/app/contacting.py new file mode 100644 index 0000000..2d3f735 --- /dev/null +++ b/src/signify/app/contacting.py @@ -0,0 +1,34 @@ +# -*- encoding: utf-8 -*- +""" +SIGNIFY +signify.app.contacting module + +""" +from signify.app.clienting import SignifyClient + + +class Contacts: + """ Domain class for accessing Endpoint Role Authorizations """ + + def __init__(self, client: SignifyClient): + self.client = client + + def list(self, start=0, end=24): + """ Returns list of notifications + + Parameters: + start (int): start index of list of notifications, defaults to 0 + end (int): end index of list of notifications, defaults to 24 + + Returns: + dict: data with start, end, total and notes of list result + + """ + headers = dict(Range=f"contacts={start}-{end}") + res = self.client.get(f"/contacts", headers=headers) + # cr = res.headers["content-range"] + # start, end, total = httping.parseRangeHeader(cr, "notes") + + contacts = res.json() + return dict(start=0, end=len(contacts), total=len(contacts), contacts=contacts) + diff --git a/tests/app/test_contacting.py b/tests/app/test_contacting.py new file mode 100644 index 0000000..b442ce0 --- /dev/null +++ b/tests/app/test_contacting.py @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +""" +SIGNIFY +signify.app.test_contacting module + +Testing contacting with unit tests +""" + +from mockito import mock, unstub, expect, verifyNoUnwantedInteractions + + +def test_contact_list(): + from signify.app.clienting import SignifyClient + mock_client = mock(spec=SignifyClient) + + from signify.app.contacting import Contacts + contacts = Contacts(client=mock_client) # type: ignore + + from requests import Response + mock_response = mock({'headers': {'content-range': 'contents 0-10/20'}}, spec=Response, strict=True) + expect(mock_client, times=1).get('/contacts', headers=dict(Range=f"contacts={0}-{24}")).thenReturn(mock_response) + expect(mock_response, times=1).json().thenReturn( + ['contact1', 'contact2'] + ) + + out = contacts.list() + assert out['start'] == 0 + assert out['end'] == 2 + assert out['total'] == 2 + assert out['contacts'] == ['contact1', 'contact2'] + + verifyNoUnwantedInteractions() + unstub()