Substrate Account Messaging Protocol -- Python SDK
Project description
samp-core
Python implementation of SAMP (Substrate Account Messaging Protocol). Crypto operations use a native Rust extension via PyO3.
Install
pip install samp-core
Usage
import os
from samp import (
EncryptedRemark, Seed, decode_remark,
nonce_from_bytes, plaintext_from_bytes, pubkey_from_bytes, sr25519_signing_scalar,
)
from samp.encryption import compute_view_tag, decrypt, encrypt
from samp.wire import ContentType, encode_encrypted, encode_public
sender_seed = Seed.from_bytes(bytes.fromhex("e5be9a5092b81bca" + "00" * 24))
recipient_pub = pubkey_from_bytes(bytes.fromhex("8eaf04151687736" + "0" + "00" * 24))
# Public message
remark = encode_public(recipient_pub, "Hello from Python")
# Encrypted message
nonce = nonce_from_bytes(os.urandom(12))
plaintext = plaintext_from_bytes(b"Private message")
ciphertext = encrypt(plaintext, recipient_pub, nonce, sender_seed)
tag = compute_view_tag(sender_seed, recipient_pub, nonce)
enc_remark = encode_encrypted(ContentType.ENCRYPTED, tag, nonce, ciphertext)
# Decrypt
recipient_seed = Seed.from_bytes(bytes(32))
scalar = sr25519_signing_scalar(recipient_seed)
parsed = decode_remark(enc_remark)
assert isinstance(parsed, EncryptedRemark)
clear = decrypt(parsed.ciphertext, parsed.nonce, scalar)
API
Wire
| Function | Description |
|---|---|
encode_public |
Public message (0x10) |
encode_encrypted |
Encrypted or thread message (0x11/0x12) |
encode_channel_create |
Channel creation (0x13) |
encode_channel_msg |
Channel message (0x14) |
encode_group |
Group message (0x15) |
decode_remark |
Parse any SAMP remark → Remark dataclass |
encode_thread_content / decode_thread_content |
Thread plaintext (refs + body) |
encode_channel_content / decode_channel_content |
Channel plaintext (refs + body) |
decode_group_content |
Group plaintext (refs + body) |
encode_group_members / decode_group_members |
Group member list |
channel_ref_from_recipient |
Extract channel ref from recipient field |
Crypto
| Function | Description |
|---|---|
encrypt / decrypt |
1:1 ECDH + ChaCha20-Poly1305 |
decrypt_as_sender |
Sender self-decryption via sealed_to |
encrypt_for_group / decrypt_from_group |
Multi-recipient encryption |
sr25519_signing_scalar |
Derive signing scalar from sr25519 seed |
public_from_seed |
Derive public key from seed |
compute_view_tag / check_view_tag |
1-byte recipient filter |
unseal_recipient |
Recover recipient from sealed_to field |
build_capsules / scan_capsules |
Group capsule construction and scanning |
Types
Remark (dataclass), SampError (exception)
Test
pytest tests/ -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
samp_core-1.1.1.tar.gz
(25.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
samp_core-1.1.1-py3-none-any.whl
(16.8 kB
view details)
File details
Details for the file samp_core-1.1.1.tar.gz.
File metadata
- Download URL: samp_core-1.1.1.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91a8413bb3b11af0511dcee772c57c7cdc6914b43539e3ac74da7ce5f428758c
|
|
| MD5 |
d17cbee3da4b3107a805101b77b12664
|
|
| BLAKE2b-256 |
e35fcdab2f743441e9f18bca0b38ae3deabd303501079f9f7496eee683c54055
|
File details
Details for the file samp_core-1.1.1-py3-none-any.whl.
File metadata
- Download URL: samp_core-1.1.1-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
971154c3a4f01ff20a62de05e1e84f5b81399f37012b41877460a223a69d582f
|
|
| MD5 |
70995774a3e9d2b77fc34243db9047b5
|
|
| BLAKE2b-256 |
cb49930b21ebd9ae0f9e85c6ba6441026c3b2e21f1c9755a81dadb3549936dcc
|