Skip to content

Commit

Permalink
docs: add usage example
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Oct 19, 2023
1 parent b7f238e commit 5516584
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# did-peer-2

[![pypi release](https://img.shields.io/pypi/v/did-peer-2)](https://pypi.org/project/did-peer-2/)

A minimal did:peer:2 (and 3) library.

did:peer:2 has (or will soon be) superseded by [did:peer:4](https://github.com/dbluhm/did-peer-4). Even so, we anticipate did:peer:2 being around for at least a while longer. This library is built against the most recent version of the did:peer:2 spec.

## Install

```sh
pip install did-peer-2
```

## Usage

```python
>>> from did_peer_2 import generate, KeySpec, resolve, peer2to3
>>> keys = [
... KeySpec.verification("z6Mkj3PUd1WjvaDhNZhhhXQdz5UnZXmS7ehtx8bsPpD47kKc"),
... KeySpec.encryption("z6LSg8zQom395jKLrGiBNruB9MM6V8PWuf2FpEy4uRFiqQBR")
... ]
>>> services = [
... {
... "type": "DIDCommMessaging",
... "serviceEndpoint": {
... "uri": "http://example.com/didcomm",
... "accept": ["didcomm/v2"],
... "routingKeys": ["did:example:123456789abcdefghi#key-1"],
... },
... },
... ]
>>> did = generate(keys, services)
>>> print(did)
did:peer:2.Vz6Mkj3PUd1WjvaDhNZhhhXQdz5UnZXmS7ehtx8bsPpD47kKc.Ez6LSg8zQom395jKLrGiBNruB9MM6V8PWuf2FpEy4uRFiqQBR.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6Imh0dHA6Ly9leGFtcGxlLmNvbS9kaWRjb21tIiwiYSI6WyJkaWRjb21tL3YyIl0sInIiOlsiZGlkOmV4YW1wbGU6MTIzNDU2Nzg5YWJjZGVmZ2hpI2tleS0xIl19fQ
>>> resolved = resolve(did)
>>> assert isinstance(resolved, dict)
>>> did3 = peer2to3(did)
>>> print(did3)
did:peer:3zQmbRvRJgKBuubq8T9VBjrDPTmjb2Ed91f89ekW4gr6aZxa

```

## DID Peer 2 Specification

If `numalgo` == `2`, the generation mode is similar to Method 0 (and therefore also did:key) with the ability to specify additional keys in the generated DID Document. This method is necessary when both an encryption key and a signing key are required. This method also enables including services in the generated DID Document.
Expand Down
15 changes: 14 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = [
]
dependencies = [
"base58>=2.1.1",
"pytest-ruff>=0.1.1",
]
requires-python = ">=3.9"
readme = "README.md"
Expand All @@ -23,3 +24,21 @@ dev = [
"ruff>=0.1.0",
"pre-commit>=3.5.0",
]

[tool.pytest.ini_options]
addopts = "--doctest-glob README.md --ruff"

[tool.ruff]
select = ["E", "F", "C", "D"]

ignore = [
# Google Python Doc Style
"D203", "D204", "D213", "D215", "D400", "D401", "D404", "D406", "D407",
"D408", "D409", "D413",
"D202", # Allow blank line after docstring
]

line-length = 90

[tool.ruff.per-file-ignores]
"**/{tests}/*" = ["F841", "D", "E501"]

0 comments on commit 5516584

Please sign in to comment.