Cryptography
This document explains the SDK’s cryptography layer in practical terms, grounded on the headers in include/Cryptography/* and the serialization helpers in include/Utils/*. It is written for engineers who need to generate keys, derive addresses, sign/verify payloads, and serialize/deserialize cryptographic types.
What’s inside
PrivateKey — secure 32‑byte secret key (guarded reads/writes)
PhantasmaKeys — convenience holder: private key, public key, and derived address; also provides signing
Address — canonical on‑chain address with parsing/formatting and validation
Signature — variant container for signatures (Ed25519 provided by default)
Hash — 32‑byte hash value with I/O helpers
(Utils)
BinaryReader,BinaryWriter,Serializable,Entropy— used across the types
Include & namespaces
#include "Cryptography/PrivateKey.h"
#include "Cryptography/KeyPair.h"
#include "Cryptography/Address.h"
#include "Cryptography/Signature.h"
#include "Cryptography/Hash.h"
#include "Utils/BinaryReader.h"
#include "Utils/BinaryWriter.h"
using namespace phantasma;PrivateKey
PrivateKey stores a 32‑byte secret key. The bytes are kept in a secure buffer and can only be accessed via short‑lived reader/writer proxies. Typical flows:
Generate a random key (recommended: use
PhantasmaKeys::Generate())Import/export into the secure buffer via
Write()/Read()Key members & methods (selection)PHANTASMA_EXCEPTION("privateKey should have length 32")→ ``
Example — create and access
PhantasmaKeys
PhantasmaKeys bundles a private key, the corresponding public key bytes, and the derived Address. It also provides message signing helpers. Public API (selection)
Example — generate, inspect, sign
Address
Address represents an on‑chain account address. It supports deriving from a public key, parsing from text, validating, and converting to string. Public API (selection)
Example — parse and derive
Signature (Ed25519)
Signature is a serializable container that can hold an Ed25519 signature. Verification checks the signature against one or more allowed addresses (derived from public keys). Public API (selection)
Example — verify
Hash
Hash encapsulates a 32‑byte hash with helpers to construct from bytes and to print/compare/serialize. Public API (selection)
Example
Recipes
Sign & verify an arbitrary message
Sign a transaction (end-to-end)
Serialize / deserialize a signature
Last updated