Skip to main content

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


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.2.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

samp_core-1.2.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file samp_core-1.2.0.tar.gz.

File metadata

  • Download URL: samp_core-1.2.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for samp_core-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4663fc0d36948a56b979bb5b204e4abf96e44a28168ae649016c57da4ea9b473
MD5 47378f97b6e44fd73d76398f3f8606b6
BLAKE2b-256 c45b32e8de73f6872c5546cf028b9a3a59595c13a7d35852f8a4fe58f6e966ac

See more details on using hashes here.

File details

Details for the file samp_core-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: samp_core-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for samp_core-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e7d47b2f8debbe6ec58dd75a056caffde6c9cc232796eac3563258df5adb22
MD5 fda27da8ba19bbd42b1928fe83e530a9
BLAKE2b-256 8cbb21fc6103edeb4476b1b53bb873fe64119b9fab30034061f6970249de3fb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page