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#.
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
pamoja.securityreference, every class and function in this module.- The Device identity guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Release files for pamoja-security 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pamoja_security-0.2.0.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_security-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / pamoja_security-0.2.0.tar.gz
| Download URL | pamoja_security-0.2.0.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76804d59e663582d9d22be367945181a0fe9f5348fe62e75e25a46ee51eec0d3
|
|
BLAKE2b-256 checksum How to use checksums |
b8e0fbf125ce377dcfbaf2c9e43ff4086bca41348f333e5b512491fd7d60acc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / pamoja_security-0.2.0-py3-none-any.whl
| Download URL | pamoja_security-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06bdc77af28e63f70ad7677d1ea8a0f705f0e5ca9a9c8ce6438ee850ac16f12a
|
|
BLAKE2b-256 checksum How to use checksums |
5c18730455c0e7d5a1ee43d9436018398f3caf115880f8ccb10b09389d4f97ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|