Skip to main content

pamoja-session

X25519 key agreement, HKDF, and ChaCha20-Poly1305 with an anti-replay window, with no TLS stack. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.

read the guide documentation API reference

Install

pip install pamoja-session
from pamoja import session

This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.

Example

The script the test suite runs, spliced here as it ran.

From bindings/python/guides/session.py:

import os

from pamoja.core import PamojaError
from pamoja.session import AgreementKey, Role, Session

# Each device is provisioned with a 32-byte seed and publishes the key it derives. A real
# seed comes from the factory or a secure element; any 32 bytes stand in here.
node = AgreementKey(bytes([7]) * 32)
gateway = AgreementKey(bytes([9]) * 32)

# Neither side sends the session key. Both derive it from the shared secret, a salt that
# travels in the clear, and both public keys, with opposite roles.
#
# The salt must be fresh for every session: reusing one derives the same key from the same
# pair of devices twice. The initiator draws it and sends it in the clear, so the responder
# uses the salt it received rather than one of its own.
salt = os.urandom(16)
uplink = Session(node, gateway.public_key, salt, Role.INITIATOR)
downlink = Session(gateway, node.public_key, salt, Role.RESPONDER)
print("both sides derived a key without sending one")

# The pump id is authenticated but not encrypted, so a router still reads it while any
# change to it fails the tag.
sealed = uplink.seal(b"flow=41.2", b"pump-3")
print(f"sealed    the reading is no longer readable: {sealed.ciphertext != b'flow=41.2'}")
print(f"opened    {downlink.open(sealed, b'pump-3').decode()}")

# The anti-replay window refuses a counter it has already accepted, so a frame captured
# off the air and sent again is not delivered a second time.
try:
    downlink.open(sealed, b"pump-3")
    print("a replayed frame was accepted, which should never happen")
except PamojaError as error:
    print(f"replay    refused: {error}")

The same capability in every language

Language Package Reference
Rust pamoja-session reference, docs.rs, install
TypeScript @pamoja/session reference, install
Python pamoja-session reference, install
C# Pamoja.Session reference, install

Documentation

License

MIT

Release files for pamoja-session 0.1.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pamoja-session 0.1.18
File Size Uploaded
pamoja_session-0.1.18.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-session 0.1.18
File Interpreter ABI Platform
pamoja_session-0.1.18-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / pamoja_session-0.1.18.tar.gz

Download URL pamoja_session-0.1.18.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ce25eb8df1622dfa7bfec509652bbeac80d6ef7470db44c0ac39e2272c637835
BLAKE2b-256 checksum
How to use checksums
e653c7789ff9e31cacde86e10902b515d45dd6d230a324b91ce11dec65e34ae5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pamoja_session-0.1.18-py3-none-any.whl

Download URL pamoja_session-0.1.18-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00eff3fc48f921f0f530eb1369300ca1e438bde8449f6878980e06164129a0ea
BLAKE2b-256 checksum
How to use checksums
f6f2406c86f04b632e6e342a69fdb33db3c550316323c2f1fdc6a7f1ecef7487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.18 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page