Skip to main content

pamoja-security

ed25519 device identity: sign a reading and verify it, so a gateway can prove it is authentic. 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-security
from pamoja import security

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/security.py:

from pamoja.security import DeviceIdentity, fingerprint, verify, verify_message

# The seed is provisioned into the device once and never leaves it. A real one comes from
# the factory or a secure element; any 32 bytes stand in here.
device = DeviceIdentity.from_seed(bytes([7]) * 32)

# Only the 32-byte public key travels to the gateway. Its fingerprint is the short form an
# operator reads off a screen to tell one device from another.
gateway_key = device.public_key
print(f"device     {fingerprint(gateway_key)}")

# Signing is deterministic, so the same reading always produces the same 64 bytes and there
# is no randomness to get wrong on a microcontroller.
reading = "meter-4 1182.750 kWh"
signature = device.sign(reading)
if verify(gateway_key, reading, signature):
    print(f"accepted   {reading}")
else:
    print("rejected   a reading the device really did sign, which should never happen")

# A digit changed in transit no longer matches what was signed.
edited = "meter-4 1082.750 kWh"
if verify(gateway_key, edited, signature):
    print("accepted   an edited reading, which should never happen")
else:
    print(f"rejected   {edited}")

# Nor does the same reading offered under another device's key.
impostor = DeviceIdentity.from_seed(bytes([90]) * 32)
if verify(impostor.public_key, reading, signature):
    print("accepted   an impostor, which should never happen")
else:
    print("rejected   a signature offered under another device's key")

# On a link the signature and the reading usually travel as one message, signature first,
# and the gateway gets the reading back only once it has checked it.
message = device.sign_message(reading)
print(f"message    {len(message)} bytes on the wire, the signature and the reading together")
carried = verify_message(gateway_key, message)
if carried is not None:
    print(f"accepted   {carried.decode()}, read out of the message")
else:
    print("rejected   a message the device really did sign, which should never happen")

# A message that lost its last byte on the way is refused whole.
if verify_message(gateway_key, message[:-1]) is not None:
    print("accepted   a message cut short, which should never happen")
else:
    print("rejected   a message that lost its last byte on the way")

The same capability in every language

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

Documentation

License

MIT

Metadata

Release files for pamoja-security 0.2.1

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-security 0.2.1
File Size Uploaded Provenance Actions
pamoja_security-0.2.1.tar.gz 5.0 kB Without provenance Details for pamoja_security-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-security 0.2.1
File Interpreter ABI Platform Actions
pamoja_security-0.2.1-py3-none-any.whl Python 3 none any Details for pamoja_security-0.2.1-py3-none-any.whl

Total release size: 10.7 kB

Release files / pamoja_security-0.2.1.tar.gz

Download URL pamoja_security-0.2.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
453b27429e1de5cf7226d2bbd4c020a42bbf750825684d59be0439221299907f
BLAKE2b-256 checksum
How to use checksums
370924023057a34eb155aed76a3a1d93b818ee3904a6e6f7178e875aa582dbc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / pamoja_security-0.2.1-py3-none-any.whl

Download URL pamoja_security-0.2.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cf516a10c1cadf9b848574232e6e5ab9eca4159b1c9140de00d41da933b8c00
BLAKE2b-256 checksum
How to use checksums
e96638df558893df3efc7444184ca23c37cc6f7bf9f1f1f7bb08556aa401c1f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for pamoja-security 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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