Git Product home page Git Product logo

didcomm-messaging-python's Introduction

didcomm-messaging-python

This is a minimal but flexible implementation of DIDComm Messaging. To learn more about DIDComm Messaging, check out the spec or visit didcomm.org to learn about DIDComm Messaging protocols defined by the community.

Usage

"""Example of using DIDComm Messaging."""
from aries_askar import Key, KeyAlg
from didcomm_messaging.crypto.askar import AskarCryptoService, AskarSecretKey
from didcomm_messaging.crypto.basic import InMemorySecretsManager
from didcomm_messaging.didcomm import PackagingService
from didcomm_messaging.multiformats import multibase
from didcomm_messaging.multiformats import multicodec
from didcomm_messaging.resolver.peer import Peer2, Peer4
from didcomm_messaging.resolver import PrefixResolver
from did_peer_2 import KeySpec, generate, json
async def main():
"""An example of using DIDComm Messaging."""
secrets = InMemorySecretsManager()
crypto = AskarCryptoService()
packer = PackagingService(
PrefixResolver({"did:peer:2": Peer2(), "did:peer:4": Peer4()}), crypto, secrets
)
verkey = Key.generate(KeyAlg.ED25519)
xkey = Key.generate(KeyAlg.X25519)
did = generate(
[
KeySpec.verification(
multibase.encode(
multicodec.wrap("ed25519-pub", verkey.get_public_bytes()),
"base58btc",
)
),
KeySpec.key_agreement(
multibase.encode(
multicodec.wrap("x25519-pub", xkey.get_public_bytes()), "base58btc"
)
),
],
[],
)
await secrets.add_secret(AskarSecretKey(verkey, f"{did}#key-1"))
await secrets.add_secret(AskarSecretKey(xkey, f"{did}#key-2"))
print(did)
packed = await packer.pack(b"hello world", [did], did)
print(json.dumps(json.loads(packed), indent=2))
unpacked = await packer.unpack(packed)
print(unpacked)
if __name__ == "__main__":
import asyncio
asyncio.run(main())

Overview

didcomm-messaging-python layer cake

This library has the following core components (as outlined in the layer cake architecture diagram above):

CryptoService

The CryptoService provides the core cryptographic capabilities needed to encrypt and decrypt DIDComm Messages. This service is designed to be implemented by users of this library; however, an implementation using Aries Askar is available as an extra (install the askar extra to use it). Additional implementations may be added as extras in the future (i.e. an implementation using Authlib's JWE implementation or perhaps an implementation backed by an HSM). The service is seprate from but closely coupled with the SecretsManager. Both must use the same public and private key representations.

Warning

TODO:

  • More details on implementing your own CryptoService
  • More details on using the included Askar CryptoService

SecretsManager

The SecretsManager is responsible for retrieving secrets for use by the CryptoService. It is notable that the secret value need not literally contain the value of a private key. For example, in the included Askar implementation, an Askar Key value is retrieved. This object in python does permit you to retrieve the bytes of the secret key from Askar if you choose; however, this is not necessary for the operation of the library. This enables Askar to keep the private key value down in the Rust layer where it can better ensure security of the key (zeroizing memory, etc.). This is not so distant from interacting with an HSM; as long as the SecretKey value retrieved by the SecretsManager can be used by the CryptoService to perform the required cryptographic operations, exactly what is stored inside of the SecretKey object is irrelevant.

Warning

TODO:

  • More details on implementing your own SecretsManager
  • More details on the included AskarSecretsManager

DIDResolver

This component provides a fairly generic DID Resolution interface. Users of this library will provide a resolver implementation for the DID Methods they care about. Implementations of did:peer:2 and did:peer:4 are included as part of the did_peer extra.

Warning

TODO:

  • More details on PrefixResolver
  • More details on implementing your own DIDResolver

PackagingService

The PackagingService is responsible for the core functions of packing and unpacking messages. It depends on the CryptoService, the SecretsManager, and the DIDResolver to accomplish this.

Warning

TODO:

  • More details on PackagingService

RoutingService

The RoutingService is responsible for preparing messages for forwarding to a mediator. It depends on the PackagingService and the DIDResolver to accomplish this.

Warning

TODO:

  • More details on RoutingService

DIDCommMessaging

The DIDCommMessaging interface is the main entrypoint for interacting with this library. It utilizes all the layers below to prepare messages for other parties.

Warning

TODO:

  • More details on DIDCommMessaging

didcomm-messaging-python's People

Contributors

dbluhm avatar thetechmage avatar mepeltier avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

Kim Ebert avatar Mike Ebert avatar Sam Curren avatar  avatar

Forkers

telegramsam

didcomm-messaging-python's Issues

Optional Message Model

We should provide a Message class that can be used by users of this library. However, we should not require that the included Message is the only way to interact with the library.

This essentially means that we should operate on messages as dictionaries.

Validation. I think we should keep validation to a practical minimum at the interface layer. According to the DIDComm v2 spec, only the following attributes are required:

  • id
  • type
  • body

The Message class MAY provide additional validation; the interface itself, however, MUST NOT validate any deeper than this.

DIDCommMessaging

There's not actually going to be that much code here. Most of the task is determining what we want the interface to look like.

Resolver: did:web

Add a did:web resolver using a common web client framework. The dependency should be optional, following the same pattern as the did_peer extra. Probably should use aiohttp.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.