Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates from getting started guide runthrough #66

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ jobs:
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.10.13
python-version: 3.12.2
- name: Clear databases
run: |
rm -Rf /usr/local/var/keri/*
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
13 changes: 6 additions & 7 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ E.g. using git, Github pages, FTP, SCP, etc.
## Example: serve from docker
You can run the docker example service to serve the did.json and keri.cesr files for the other docker containers:

First, lets copy our generated files to the directory we'll serve from. On your `LOCAL` machine (or within the container) you can copy `volume/dkr/examples/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe` to `volume/dkr/pages/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe`:
First, lets copy our generated files to the directory we'll serve from. On your
`LOCAL` machine (or within the container) you can copy
`volume/dkr/examples/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe` to
`volume/dkr/pages/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe`:

For this demo these files have been copied ahead of time for you.

```
cp -R volume/dkr/examples/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe volume/dkr/pages/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe
Expand All @@ -203,12 +208,6 @@ It will search for AID named directories and for the two files (`did.json` and `
"did.doc.dir": "/usr/local/var/webs/volume/dkr/pages/"
```

And when a file is found by the service, there will be logs like:
```
Looking for did.json file /usr/local/var/webs/volume/dkr/pages/ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe
registering /ENro7uf0ePmiK3jdTo2YCdXLqW7z7xoP6qhhBou6gBLe/did.json
```

It will serve it at a URL that you can CURL from any of our docker containers (for instance from the webs container) like:

`command:`
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"

networks:
websnet:
# networks:
# websnet:

services:
witnesshost:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
'http_sfv>=0.9.8',
'cryptography>=39.0.2',
'requests>=2.28',
'numpy>=1.26.0',
'pytest>=6.2.5',
'pytest-timeout>=2.3.1'
],
Expand Down
12 changes: 6 additions & 6 deletions src/dkr/app/cli/commands/did/keri/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@
dest="bran", default=None) # passcode => bran
parser.add_argument("--did", "-d", help="DID to resolve (did:keri method)", required=True)
parser.add_argument("--oobi", "-o", help="OOBI to use for resolving the DID", required=False)
parser.add_argument("--metadata", "-m", help="Whether to include metadata (True), or only return the DID document (False)", type=bool, required=False, default=None)
parser.add_argument("--meta", "-m", help="Whether to include metadata (True), or only return the DID document (False)", type=bool, required=False, default=None)


def handler(args):
hby = existing.setupHby(name=args.name, base=args.base, bran=args.bran)
hbyDoer = habbing.HaberyDoer(habery=hby) # setup doer
obl = oobiing.Oobiery(hby=hby)
res = KeriResolver(hby=hby, hbyDoer=hbyDoer, obl=obl, did=args.did, oobi=args.oobi, metadata=args.metadata)
res = KeriResolver(hby=hby, hbyDoer=hbyDoer, obl=obl, did=args.did, oobi=args.oobi, meta=args.meta)
return [res]


class KeriResolver(doing.DoDoer):

def __init__(self, hby, hbyDoer, obl, did, oobi, metadata):
def __init__(self, hby, hbyDoer, obl, did, oobi, meta):

self.hby = hby
self.did = did
self.oobi = oobi
self.metadata = metadata
self.meta = meta

self.toRemove = [hbyDoer] + obl.doers
doers = list(self.toRemove) + [doing.doify(self.resolve)]
Expand All @@ -68,9 +68,9 @@ def resolve(self, tymth, tock=0.0, **opts):
while self.hby.db.roobi.get(keys=(self.oobi,)) is None:
_ = yield tock

didresult = didding.generateDIDDoc(self.hby, did=self.did, aid=aid, oobi=self.oobi, metadata=True)
didresult = didding.generateDIDDoc(self.hby, did=self.did, aid=aid, oobi=self.oobi, meta=True)
dd = didresult[didding.DD_FIELD]
result = didresult if self.metadata else dd
result = didresult if self.meta else dd
data = json.dumps(result, indent=2)

print(data)
Expand Down
20 changes: 14 additions & 6 deletions src/dkr/app/cli/commands/did/webs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
required=False,
default=None,
help="Name of regery to find designated aliases attestation. Default is None.")
parser.add_argument("--meta", "-m", help="Whether to include metadata (True), or only return the DID document (False)", type=bool, required=False, default=False)

def handler(args):
gen = Generator(name=args.name, base=args.base, bran=args.bran, did=args.did, oobi=None, da_reg=args.da_reg)
gen = Generator(name=args.name, base=args.base, bran=args.bran, did=args.did, oobi=None, da_reg=args.da_reg, meta=args.meta)
return [gen]

class Generator(doing.DoDoer):

def __init__(self, name, base, bran, did, oobi, da_reg):
def __init__(self, name, base, bran, did, oobi, da_reg, meta=False):
self.name = name
self.base = base
self.bran = bran
Expand All @@ -55,6 +56,8 @@ def __init__(self, name, base, bran, did, oobi, da_reg):
self.did = did
# self.oobi = oobi
self.da_reg = da_reg
self.meta = meta
print("Generate DID document command", did, "using oobi", oobi, "and metadata", meta, "registry name for creds", da_reg)

self.toRemove = [hbyDoer] + obl.doers
doers = list(self.toRemove) + [doing.doify(self.generate)]
Expand Down Expand Up @@ -105,7 +108,12 @@ def generate(self, tymth, tock=0.0, **opts):
kcf.write(tmsg)

#generate did doc
diddoc = didding.generateDIDDoc(self.hby, did=self.did, aid=aid, oobi=None, reg_name=self.da_reg)
result = didding.generateDIDDoc(self.hby, did=self.did, aid=aid, oobi=None, reg_name=self.da_reg, meta=self.meta)

diddoc = result
if(self.meta):
diddoc = result["didDocument"]
print("Generated metadata for DID document", result["didDocumentMetadata"])

# Create the directory (and any intermediate directories in the given path) if it doesn't already exist
dd_dir_path = f"{aid}"
Expand Down Expand Up @@ -172,7 +180,7 @@ def genTelCesr(self, reger: viring.Reger, regk: str, msgs: bytearray):
msgs.extend(msg)

def genAcdcCesr(self, aid, creder, msgs: bytearray):
print(f"Generating {creder.crd['d']} ACDC CESR events, issued by {creder.crd['i']}")
# print(f"Generating {creder.crd['d']} ACDC CESR events, issued by {creder.crd['i']}")
cmsg = self.hby.habs[aid].endorse(creder)
msgs.extend(cmsg)

Expand All @@ -187,7 +195,7 @@ def genCredCesr(self, aid: str, schema: str, msgs: bytearray):

creder, *_ = rgy.reger.cloneCred(said=saider.qb64)

if creder.status is not None:
self.genTelCesr(rgy.reger, creder.status, msgs)
if creder.regi is not None:
self.genTelCesr(rgy.reger, creder.regi, msgs)
self.genTelCesr(rgy.reger, creder.said, msgs)
self.genAcdcCesr(aid, creder, msgs)
10 changes: 5 additions & 5 deletions src/dkr/app/cli/commands/did/webs/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
parser.add_argument('--passcode', help='22 character encryption passcode for keystore (is not saved)',
dest="bran", default=None) # passcode => bran
parser.add_argument("--did", "-d", help="DID to resolve", required=True)
parser.add_argument("--metadata", "-m", help="Whether to include metadata (True), or only return the DID document (False)", type=bool, required=False, default=None)
parser.add_argument("--meta", "-m", help="Whether to include metadata (True), or only return the DID document (False)", type=bool, required=False, default=None)


def handler(args):
hby = existing.setupHby(name=args.name, base=args.base, bran=args.bran)
hbyDoer = habbing.HaberyDoer(habery=hby) # setup doer
obl = oobiing.Oobiery(hby=hby)
res = WebsResolver(hby=hby, hbyDoer=hbyDoer, obl=obl, did=args.did, metadata=args.metadata)
res = WebsResolver(hby=hby, hbyDoer=hbyDoer, obl=obl, did=args.did, meta=args.meta)
return [res]


class WebsResolver(doing.DoDoer):

def __init__(self, hby, hbyDoer, obl, did, metadata):
def __init__(self, hby, hbyDoer, obl, did, meta):

self.hby = hby
self.did = did
self.metadata = metadata
self.meta = meta

self.toRemove = [hbyDoer] + obl.doers
doers = list(self.toRemove) + [doing.doify(self.resolve)]
Expand All @@ -51,6 +51,6 @@ def resolve(self, tymth, tock=0.125, **opts):
self.tock = tock
_ = (yield self.tock)

resolving.resolve(hby=self.hby, did=self.did, metadata=self.metadata)
resolving.resolve(hby=self.hby, did=self.did, meta=self.meta)

self.remove(self.toRemove)
16 changes: 8 additions & 8 deletions src/dkr/core/didding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

"""

from datetime import datetime
import datetime
import json
import math
import re
import numpy as np

from base64 import urlsafe_b64encode

Expand Down Expand Up @@ -60,10 +60,10 @@ def parseDIDWebs(did):
return domain, port, path, aid


def generateDIDDoc(hby: habbing.Habery, did, aid, oobi=None, metadata=None, reg_name=None):
def generateDIDDoc(hby: habbing.Habery, did, aid, oobi=None, meta=False, reg_name=None):
if (did and aid) and not did.endswith(aid):
raise ValueError(f"{did} does not end with {aid}")
print("Generating DID document for", did, "with aid", aid, "using oobi", oobi, "and metadata", metadata, "registry name for creds", reg_name)
print("Generating DID document for", did, "with aid", aid, "using oobi", oobi, "and metadata", meta, "registry name for creds", reg_name)

hab = None
if aid in hby.habs:
Expand Down Expand Up @@ -112,7 +112,7 @@ def generateDIDDoc(hby: habbing.Habery, did, aid, oobi=None, metadata=None, reg_
conditionThreshold=conditions
))
elif isinstance(kever.tholder.thold, list):
lcd = int(np.lcm.reduce([fr.denominator for fr in kever.tholder.thold[0]]))
lcd = int(math.lcm(*[fr.denominator for fr in kever.tholder.thold[0]]))
threshold = float(lcd/2)
numerators = [int(fr.numerator * lcd / fr.denominator) for fr in kever.tholder.thold[0]]
conditions = []
Expand Down Expand Up @@ -164,7 +164,7 @@ def generateDIDDoc(hby: habbing.Habery, did, aid, oobi=None, metadata=None, reg_

didResolutionMetadata = dict(
contentType="application/did+json",
retrieved=datetime.utcnow().strftime(DID_TIME_FORMAT)
retrieved=datetime.datetime.now(datetime.UTC).strftime(DID_TIME_FORMAT)
)
didDocumentMetadata = dict(
witnesses=witnesses,
Expand All @@ -178,7 +178,7 @@ def generateDIDDoc(hby: habbing.Habery, did, aid, oobi=None, metadata=None, reg_
alsoKnownAs=aka_ids
)

if metadata is True:
if meta is True:
resolutionResult = dict(
didDocument=diddoc,
didResolutionMetadata=didResolutionMetadata,
Expand Down Expand Up @@ -265,4 +265,4 @@ def addEnds(ends):
)
if v not in sEnds:
sEnds.append(v)
return sEnds
return sEnds
18 changes: 8 additions & 10 deletions src/dkr/core/resolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def saveCesr(hby: habbing.Habery, kc_res: requests.Response, aid: str = None):
assert aid in hby.kevers, f"KERI CESR parsing failed, KERI AID {aid} not found in habery"

def getComp(hby: habbing.Habery, did: str, aid: str, dd_res: requests.Response, kc_res: requests.Response):
dd = didding.generateDIDDoc(hby, did=did, aid=aid, oobi=None, metadata=True)
dd = didding.generateDIDDoc(hby, did=did, aid=aid, oobi=None, meta=True)
dd[didding.DD_META_FIELD]['didDocUrl'] = dd_res.url
dd[didding.DD_META_FIELD]['keriCesrUrl'] = kc_res.url

Expand All @@ -62,7 +62,7 @@ def getComp(hby: habbing.Habery, did: str, aid: str, dd_res: requests.Response,

return dd, dd_actual

def verify(dd, dd_actual, metadata: bool = False):
def verify(dd, dd_actual, meta: bool = False):
dd_exp = dd
if didding.DD_FIELD in dd_exp:
dd_exp = dd[didding.DD_FIELD]
Expand All @@ -71,7 +71,7 @@ def verify(dd, dd_actual, metadata: bool = False):

result = None
if verified:
result = dd if metadata else dd[didding.DD_FIELD]
result = dd if meta else dd[didding.DD_FIELD]
print(f"DID verified")
else:
didresult = dict()
Expand Down Expand Up @@ -145,11 +145,11 @@ def _compare_dicts(expected, actual, path=""):
if expected != actual:
print(f"Different values for key {path}: {expected} (expected) vs. {actual} (actual)", file=sys.stderr)

def resolve(hby, did, metadata=False, resq: queue.Queue = None):
def resolve(hby, did, meta=False, resq: queue.Queue = None):
aid, dd_res, kc_res = getSrcs(did=did, resq=resq)
saveCesr(hby=hby,kc_res=kc_res, aid=aid)
dd, dd_actual = getComp(hby=hby, did=did, aid=aid, dd_res=dd_res, kc_res=kc_res)
vresult = verify(dd, dd_actual, metadata=metadata)
vresult = verify(dd, dd_actual, meta=meta)
print("Resolution result: ", vresult)
return vresult

Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(self, hby, hbyDoer, obl):
super(ResolveResource, self).__init__(doers=[])
print(f"Init resolver endpoint")

def on_get(self, req, rep, did):
def on_get(self, req, rep, did, meta=False):
print(f"Request to resolve did: {did}")

if did is None:
Expand All @@ -239,20 +239,18 @@ def on_get(self, req, rep, did):
else:
oobi = None

metadata = False

if did.startswith('did:webs:'):
#res = WebsResolver(hby=self.hby, hbyDoer=self.hbyDoer, obl=self.obl, did=did)
#tymth = None # ???
#data = res.resolve(tymth)
cmd = f"dkr did webs resolve --name dkr --did {did} --metadata {metadata}"
cmd = f"dkr did webs resolve --name dkr --did {did} --meta {meta}"
stream = os.popen(cmd)
data = stream.read()
elif did.startswith('did:keri'):
#res = KeriResolver(hby=self.hby, hbyDoer=self.hbyDoer, obl=self.obl, did=did, oobi=oobi, metadata=False)
#tymth = None # ???
#data = res.resolve(tymth)
cmd = f"dkr did keri resolve --name dkr --did {did} --oobi {oobi} --metadata {metadata}"
cmd = f"dkr did keri resolve --name dkr --did {did} --oobi {oobi} --meta {meta}"
stream = os.popen(cmd)
data = stream.read()
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/dkr/app/cli/commands/did/webs/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,18 @@ def on_get(self, req, resp):
# assert dd[didding.DD_FIELD][didding.VMETH_FIELD] == dd_actual[didding.VMETH_FIELD]

# # no metadata
# vresult = resolving.verify(dd, dd_actual, metadata=False)
# vresult = resolving.verify(dd, dd_actual, meta=False)
# assert vresult[didding.VMETH_FIELD] == dd[didding.DD_FIELD][didding.VMETH_FIELD]

# # metadata
# vresult = resolving.verify(dd, dd_actual, metadata=True)
# vresult = resolving.verify(dd, dd_actual, meta=True)
# assert vresult[didding.DD_FIELD][didding.VMETH_FIELD] == dd[didding.DD_FIELD][didding.VMETH_FIELD]

# # should not verify
# dd_actual_bad = dd_actual
# # remove the last character of the id
# dd_actual_bad[didding.VMETH_FIELD][0]["id"] = dd_actual_bad[didding.VMETH_FIELD][0]["id"][:-1]
# vresult = resolving.verify(dd, dd_actual_bad, metadata=True)
# vresult = resolving.verify(dd, dd_actual_bad, meta=True)
# assert vresult[didding.DID_RES_META_FIELD]['error'] == 'notVerified'

# # TODO test services, alsoKnownAs, etc.
Expand Down
Loading